Submission #67338793
Source Code Expand
function main(stdin) {
// eslint-disable-next-line unused-imports/no-unused-vars, no-unused-vars
const { next, nextstr, nextbig, nexts, nextssort, nextm, xArray } = makeInputReader(stdin)
const q = next()
// const prefix = xArray([1], () => 0)
const chunks = []
let head = 0
const res = []
for (let i = 0; i < q; i++) {
const t = next()
if (t === 1) {
const [c, x] = nexts(2)
chunks.push({ val: x, cnt: c })
// for (let j = 0; j < c; j++) {
// prefix.push(prefix.at(-1) + x)
// }
}
else if (t === 2) {
let k = next()
let sum = 0n
while (k > 0) {
const front = chunks[head]
const take = Math.min(k, front.cnt)
front.cnt -= take
k -= take
sum += BigInt(take) * BigInt(front.val)
if (front.cnt === 0) {
head++
}
}
res.push(sum.toString())
}
}
return res.join('\n')
}
function makeInputReader(input) {
const cin = input.trim().split(/ |\n/)
let cid = 0
function createNDArray(shape, fillFn) {
if (shape.length === 0)
return fillFn()
const [dim, ...rest] = shape
return Array.from({ length: dim }, () => createNDArray(rest, fillFn))
}
return {
next: () => Number(cin[cid++]),
nextstr: () => cin[cid++],
nextbig: () => BigInt(cin[cid++]),
nexts: (n, addNum = 0, parse = true) =>
parse ? cin.slice(cid, cid += n).map(s => Number(s) + addNum) : cin.slice(cid, cid += n),
nextssort: (n, parse = true, desc = false) =>
parse
? cin.slice(cid, cid += n).map(Number).sort((a, b) => desc ? b - a : a - b)
: cin.slice(cid, cid += n).sort((a, b) => desc ? b.localeCompare(a) : a.localeCompare(b)),
nextm: (h, w, parse = true) => {
const res = []
for (let i = 0; i < h; i++) {
const row = cin.slice(cid, cid += w)
res.push(parse ? row.map(Number) : row)
}
return res
},
xArray: createNDArray,
}
}
if (require.main === module) {
const fs = require('node:fs')
const input = fs.readFileSync('/dev/stdin', 'utf8')
console.log(main(input))
}
module.exports = { main }
Submission Info
| Submission Time |
|
| Task |
C - Large Queue |
| User |
xhksun |
| Language |
JavaScript (Node.js 18.16.1) |
| Score |
300 |
| Code Size |
2221 Byte |
| Status |
AC |
| Exec Time |
329 ms |
| Memory |
136268 KiB |
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
300 / 300 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
| All |
00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_test_00.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 01_test_19.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 00_sample_00.txt |
AC |
39 ms |
42740 KiB |
| 00_sample_01.txt |
AC |
38 ms |
42724 KiB |
| 00_sample_02.txt |
AC |
40 ms |
42804 KiB |
| 01_test_00.txt |
AC |
40 ms |
43460 KiB |
| 01_test_01.txt |
AC |
42 ms |
43556 KiB |
| 01_test_02.txt |
AC |
41 ms |
43780 KiB |
| 01_test_03.txt |
AC |
39 ms |
42772 KiB |
| 01_test_04.txt |
AC |
329 ms |
102064 KiB |
| 01_test_05.txt |
AC |
146 ms |
97252 KiB |
| 01_test_06.txt |
AC |
181 ms |
115080 KiB |
| 01_test_07.txt |
AC |
73 ms |
53048 KiB |
| 01_test_08.txt |
AC |
157 ms |
101412 KiB |
| 01_test_09.txt |
AC |
71 ms |
52436 KiB |
| 01_test_10.txt |
AC |
183 ms |
119452 KiB |
| 01_test_11.txt |
AC |
211 ms |
126048 KiB |
| 01_test_12.txt |
AC |
205 ms |
125608 KiB |
| 01_test_13.txt |
AC |
198 ms |
128320 KiB |
| 01_test_14.txt |
AC |
196 ms |
127940 KiB |
| 01_test_15.txt |
AC |
195 ms |
128188 KiB |
| 01_test_16.txt |
AC |
173 ms |
136176 KiB |
| 01_test_17.txt |
AC |
172 ms |
136268 KiB |
| 01_test_18.txt |
AC |
39 ms |
42668 KiB |
| 01_test_19.txt |
AC |
176 ms |
127608 KiB |