Submission #66077


ソースコード

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <bits/stdc++.h>
using namespace std;
struct SegmentTree
{
vector< int > seg;
int sz;
SegmentTree(int n)
{
sz = 1;
while(sz < n) sz <<= 1;
seg.assign(2 * sz - 1, INT_MAX);
}
int rmq(int a, int b, int k, int l, int r)
{
if(a >= r || b <= l) return(INT_MAX);
if(a <= l && r <= b) return(seg[k]);
return(min(rmq(a, b, 2 * k + 1, l, (l + r) >> 1),
rmq(a, b, 2 * k + 2, (l + r) >> 1, r)));
}
int rmq(int a, int b)
{
return(rmq(a, b, 0, 0, sz));
}
void update(int k, int x)
{
k += sz - 1;
seg[k] = x;
while(k > 0) {
k = (k - 1) >> 1;
seg[k] = min(seg[2 * k + 1], seg[2 * k + 2]);
}
return;
}
};
int n, q, op, k, c, pos;
stack<int> st[200000];
int main() {
cin >> n >> q;
pos = 0;
SegmentTree tr = SegmentTree(n+1);
for (int i=0; i<q; i++ ) {
cin >> op;
if (op == 1) {
cin >> k >> c;
k--;
st[k].push(c);
tr.update(k, k);
} else {
pos = tr.rmq(pos+1, n);
if (pos == INT_MAX) {
pos = tr.rmq(0, pos);
}
cout << st[pos].top() << endl;
st[pos].pop();
if (st[pos].empty()) {
tr.update(pos, INT_MAX);
}
}
}
return (0);
}

ステータス

項目 データ
問題 1411 - Stacking Books
ユーザー名 ei1929
投稿日時 2021-04-07 15:11:28
言語 C++17
状態 Accepted
得点 4
ソースコード長 1306 Byte
最大実行時間 411 ms
最大メモリ使用量 160544 KB

セット

セット 得点 Cases
1 ALL 4 / 4 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
in01.txt AC 252 ms 136540 KB
1
in02.txt AC 243 ms 137808 KB
1
in03.txt AC 225 ms 137156 KB
1
in04.txt AC 233 ms 138688 KB
1
in05.txt AC 223 ms 139196 KB
1
in06.txt AC 387 ms 140080 KB
1
in07.txt AC 397 ms 141100 KB
1
in08.txt AC 380 ms 142112 KB
1
in09.txt AC 411 ms 143004 KB
1
in10.txt AC 380 ms 144020 KB
1
in11.txt AC 391 ms 145036 KB
1
in12.txt AC 386 ms 145788 KB
1
in13.txt AC 390 ms 146804 KB
1
in14.txt AC 392 ms 147816 KB
1
in15.txt AC 394 ms 148708 KB
1
in16.txt AC 409 ms 149852 KB
1
in17.txt AC 359 ms 150744 KB
1
in18.txt AC 373 ms 151760 KB
1
in19.txt AC 375 ms 152652 KB
1
in20.txt AC 371 ms 153028 KB
1
in21.txt AC 360 ms 153532 KB
1
in22.txt AC 229 ms 153528 KB
1
in23.txt AC 209 ms 154152 KB
1
in24.txt AC 201 ms 154212 KB
1
in25.txt AC 323 ms 152352 KB
1
in26.txt AC 353 ms 153368 KB
1
in27.txt AC 335 ms 154388 KB
1
in28.txt AC 337 ms 155276 KB
1
in29.txt AC 100 ms 155524 KB
1
in30.txt AC 91 ms 155384 KB
1
in31.txt AC 380 ms 158200 KB
1
in32.txt AC 340 ms 157376 KB
1
in33.txt AC 369 ms 160544 KB
1
in34.txt AC 219 ms 160040 KB
1
sample01.txt AC 91 ms 158112 KB
1
sample02.txt AC 90 ms 158232 KB
1