#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000;
struct lazy_segment_tree{
int N;
vector<int> mn, mx, lazy;
lazy_segment_tree(int N2){
N = 1;
while (N < N2){
N *= 2;
}
mn = vector<int>(N * 2 - 1, INF);
mx = vector<int>(N * 2 - 1, -INF);
for (int i = 0; i < N2; i++){
mn[N - 1 + i] = 0;
mx[N - 1 + i] = 0;
}
for (int i = N - 2; i >= 0; i--){
mn[i] = min(mn[i * 2 + 1], mn[i * 2 + 2]);
mx[i] = max(mx[i * 2 + 1], mx[i * 2 + 2]);
}
lazy = vector<int>(N * 2 - 1, 0);
}
void eval(int i){
if (i < N - 1){
lazy[i * 2 + 1] += lazy[i];
lazy[i * 2 + 2] += lazy[i];
}
mn[i] += lazy[i];
mx[i] += lazy[i];
lazy[i] = 0;
}
void range_add(int L, int R, int x, int i, int l, int r){
eval(i);
if (r <= L || R <= l){
return;
} else if (L <= l && r <= R){
lazy[i] += x;
eval(i);
} else {
int m = (l + r) / 2;
range_add(L, R, x, i * 2 + 1, l, m);
range_add(L, R, x, i * 2 + 2, m, r);
mn[i] = min(mn[i * 2 + 1], mn[i * 2 + 2]);
mx[i] = max(mx[i * 2 + 1], mx[i * 2 + 2]);
}
}
void range_add(int L, int R, int x){
range_add(L, R, x, 0, 0, N);
}
int range_min(int L, int R, int i, int l, int r){
eval(i);
if (r <= L || R <= l){
return INF;
} else if (L <= l && r <= R){
return mn[i];
} else {
int m = (l + r) / 2;
return min(range_min(L, R, i * 2 + 1, l, m), range_min(L, R, i * 2 + 2, m, r));
}
}
int range_min(int L, int R){
return range_min(L, R, 0, 0, N);
}
int range_max(int L, int R, int i, int l, int r){
eval(i);
if (r <= L || R <= l){
return -INF;
} else if (L <= l && r <= r){
return mx[i];
} else {
int m = (l + r) / 2;
return max(range_max(L, R, i * 2 + 1, l, m), range_max(L, R, i * 2 + 2, m, r));
}
}
int range_max(int L, int R){
return range_max(L, R, 0, 0, N);
}
};
int main(){
int N;
cin >> N;
lazy_segment_tree ST(N);
for (int i = 0; i < N; i++){
int R, S;
cin >> R >> S;
if (S == 1){
ST.range_add(0, R, 1);
}
if (S == 2){
ST.range_add(0, R, -1);
}
if (ST.range_max(0, N) <= 0){
cout << '<' << endl;
} else if (ST.range_min(0, N) >= 0){
cout << '>' << endl;
} else {
cout << '?' << endl;
}
}
}
Compilation message
stones.cpp: In member function 'int lazy_segment_tree::range_max(int, int, int, int, int)':
stones.cpp:69:28: warning: self-comparison always evaluates to true [-Wtautological-compare]
69 | } else if (L <= l && r <= r){
| ~ ^~ ~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
2 ms |
212 KB |
Output is correct |
7 |
Correct |
2 ms |
212 KB |
Output is correct |
8 |
Correct |
3 ms |
340 KB |
Output is correct |
9 |
Correct |
3 ms |
340 KB |
Output is correct |
10 |
Correct |
18 ms |
724 KB |
Output is correct |
11 |
Correct |
125 ms |
2368 KB |
Output is correct |
12 |
Correct |
199 ms |
4176 KB |
Output is correct |
13 |
Correct |
204 ms |
4344 KB |
Output is correct |
14 |
Correct |
207 ms |
4352 KB |
Output is correct |
15 |
Correct |
214 ms |
4352 KB |
Output is correct |
16 |
Correct |
213 ms |
4416 KB |
Output is correct |
17 |
Correct |
221 ms |
4416 KB |
Output is correct |
18 |
Correct |
216 ms |
4352 KB |
Output is correct |
19 |
Correct |
206 ms |
4300 KB |
Output is correct |
20 |
Correct |
202 ms |
4340 KB |
Output is correct |
21 |
Correct |
223 ms |
4444 KB |
Output is correct |
22 |
Correct |
215 ms |
4272 KB |
Output is correct |
23 |
Correct |
223 ms |
4440 KB |
Output is correct |
24 |
Correct |
219 ms |
4412 KB |
Output is correct |
25 |
Correct |
217 ms |
4344 KB |
Output is correct |