Submission #68641


ソースコード

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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include <iostream>
#include <vector>
using namespace std;
struct FastSet {
static constexpr uint32_t B = 64;
int n, lg;
vector<vector<uint64_t> > seg;
FastSet(int _n) : n(++_n) {
do {
seg.emplace_back(vector<uint64_t>((_n + B - 1) / B));
_n = (_n + B - 1) / B;
} while (_n > 1);
lg = (int) seg.size();
}
bool contain(int k) const {
return ((seg[0][k / B] >> (k % B) & 1) != 0);
}
void insert(int k) {
for (int h = 0; h < lg; ++h) {
seg[h][k / B] |= 1ULL << (k % B);
k /= B;
}
}
void erase(int k) {
for (int h = 0; h < lg; ++h) {
seg[h][k / B] &= ~(1ULL << (k % B));
if (seg[h][k / B]) break;
k /= B;
}
}
int next(int k) {
if (k < 0) k = 0;
if (k >= n) return (-1);
for (int h = 0; h < lg; ++h) {
if (k / B == seg[h].size()) break;
uint64_t d = seg[h][k / B] >> (k % B);
if (!d) {
k = k / B + 1;
continue;
}
k += __builtin_ctzll(d);
for (int g = h - 1; g >= 0; --g) {
k *= B;
k += __builtin_ctzll(seg[g][k / B]);
}
return (k);
}
return (-1);
}
int prev(int k) {
if (k > n) k = n;
for (int h = 0; h < lg; ++h) {
if (k < 0) break;
uint64_t d = seg[h][k / B] << (63 - k % 64);
if (!d) {
k = k / B - 1;
continue;
}
k += 63 - __builtin_clzll(d) - (B - 1);
for (int g = h - 1; g >= 0; --g) {
k *= B;
k += 63 - __builtin_clzll(seg[g][k / B]);
}
return (k);
}
return (-1);
}
};
int main(){
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
int n, q;
cin >> n >> q;
FastSet s(n);
vector<vector<int> > box(n);
vector<int> res;
int cur = 0;
for(int i = 0; i < q; ++i){
int com;
cin >> com;
if(com == 1){
int k, c;
cin >> k >> c;
--k;
if(box[k].empty()){
s.insert(k);
}
box[k].push_back(c);
}else{
int nxt = s.next(cur + 1);
if(nxt == -1){
nxt = s.next(0);
}
cur = nxt;
res.emplace_back(box[cur].back());
box[cur].pop_back();
if(box[cur].empty()){
s.erase(nxt);
}
}
}
for(auto e: res){
cout << e << '\n';
}
return (0);
}

ステータス

項目 データ
問題 1411 - Stacking Books
ユーザー名 ei1903
投稿日時 2021-10-05 07:29:32
言語 C++17
状態 Accepted
得点 4
ソースコード長 2859 Byte
最大実行時間 155 ms
最大メモリ使用量 95192 KB

セット

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

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
in01.txt AC 73 ms 5976 KB
1
in02.txt AC 45 ms 8572 KB
1
in03.txt AC 81 ms 7608 KB
1
in04.txt AC 40 ms 9972 KB
1
in05.txt AC 56 ms 13080 KB
1
in06.txt AC 69 ms 17752 KB
1
in07.txt AC 78 ms 20628 KB
1
in08.txt AC 74 ms 23620 KB
1
in09.txt AC 77 ms 26484 KB
1
in10.txt AC 75 ms 29476 KB
1
in11.txt AC 91 ms 32464 KB
1
in12.txt AC 155 ms 35336 KB
1
in13.txt AC 69 ms 38332 KB
1
in14.txt AC 65 ms 41460 KB
1
in15.txt AC 58 ms 44460 KB
1
in16.txt AC 84 ms 47316 KB
1
in17.txt AC 56 ms 47632 KB
1
in18.txt AC 58 ms 53600 KB
1
in19.txt AC 65 ms 56572 KB
1
in20.txt AC 55 ms 57628 KB
1
in21.txt AC 58 ms 59480 KB
1
in22.txt AC 89 ms 64156 KB
1
in23.txt AC 99 ms 64768 KB
1
in24.txt AC 54 ms 67788 KB
1
in25.txt AC 48 ms 65180 KB
1
in26.txt AC 47 ms 67544 KB
1
in27.txt AC 61 ms 70160 KB
1
in28.txt AC 51 ms 72780 KB
1
in29.txt AC 23 ms 72724 KB
1
in30.txt AC 23 ms 72152 KB
1
in31.txt AC 82 ms 82728 KB
1
in32.txt AC 46 ms 78556 KB
1
in33.txt AC 61 ms 86288 KB
1
in34.txt AC 71 ms 95192 KB
1
sample01.txt AC 22 ms 84180 KB
1
sample02.txt AC 22 ms 84264 KB
1