Submission #74600027
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 pq = new PriorityQueue()
const res = []
for (let i = 0; i < q; i++) {
const [x, h] = nexts(2)
if (x === 1) {
pq.push(h, h)
} else if (x === 2) {
while (pq.size && pq.top[0] <= h) {
pq.pop()
}
}
res.push(pq.size)
}
return res.join('\n')
}
class PriorityQueue {
constructor() {
this.a = []
}
push(num, inc) {
const a = this.a
let i = a.length
for (let j; i; i = j) {
j = i - 1 >> 1
if (a[j][0] <= num) {
break
}
a[i] = a[j]
}
a[i] = [num, inc]
}
pop() {
const a = this.a
const r = a[0]
const x = a.pop()
const k = a.length >> 1
let i = 0
for (let j; i < k; i = j) {
j = (i << 1) + 1
if (a[j + 1] && a[j + 1][0] < a[j][0]) {
j++
}
if (x[0] <= a[j][0]) {
break
}
a[i] = a[j]
}
if (a.length) {
a[i] = x
}
return r
}
pushPop(num, inc) {
const a = this.a
const r = a[0]
const k = a.length >> 1
if (!a.length || r[0] >= num) {
return [num, inc]
}
let i = 0
for (let j; i < k; i = j) {
j = (i << 1) + 1
if (a[j + 1] && a[j + 1][0] < a[j][0]) {
j++
}
if (num <= a[j][0]) {
break
}
a[i] = a[j]
}
a[i] = [num, inc]
return r
}
popPush(num, inc) {
const a = this.a
const r = a[0]
const k = a.length >> 1
let i = 0
for (let j; i < k; i = j) {
j = (i << 1) + 1
if (a[j + 1] && a[j + 1][0] < a[j][0]) {
j++
}
if (num <= a[j][0]) {
break
}
a[i] = a[j]
}
a[i] = [num, inc]
return r
}
get size() {
return this.a.length
}
get top() {
return this.a[0]
}
}
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 - Understory |
| User |
xhksun |
| Language |
JavaScript (Node.js 22.19.0) |
| Score |
300 |
| Code Size |
3347 Byte |
| Status |
AC |
| Exec Time |
261 ms |
| Memory |
167572 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 |
| All |
00_sample_00.txt, 00_sample_01.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 00_sample_00.txt |
AC |
23 ms |
42352 KiB |
| 00_sample_01.txt |
AC |
21 ms |
42352 KiB |
| 01_random_00.txt |
AC |
127 ms |
126008 KiB |
| 01_random_01.txt |
AC |
146 ms |
130856 KiB |
| 01_random_02.txt |
AC |
172 ms |
135944 KiB |
| 01_random_03.txt |
AC |
181 ms |
139964 KiB |
| 01_random_04.txt |
AC |
198 ms |
167572 KiB |
| 01_random_05.txt |
AC |
213 ms |
147748 KiB |
| 01_random_06.txt |
AC |
213 ms |
150032 KiB |
| 01_random_07.txt |
AC |
261 ms |
155400 KiB |
| 01_random_08.txt |
AC |
182 ms |
146576 KiB |
| 01_random_09.txt |
AC |
224 ms |
157988 KiB |
| 01_random_10.txt |
AC |
159 ms |
133816 KiB |