#include <bits/stdc++.h>
using namespace std;
struct segment_tree {
struct node {
int value, push;
};
node merge(node a, node b) {
return {min(a.value, b.value), 0};
}
int size;
vector<node> tree;
void apply(int x, int value) {
tree[x].value += value;
tree[x].push += value;
}
void propagate(int x) {
if (tree[x].push != 0) {
apply(x * 2, tree[x].push);
apply(x * 2 + 1, tree[x].push);
tree[x].push = 0;
}
}
segment_tree(int n) : size(2 << __lg(n)) {
tree.assign(size * 2, {0, 0});
}
void update(int l, int r, int value) {
update(l, r, value, 1, 0, size);
}
void update(int l, int r, int value, int x, int lx, int rx) {
if (lx >= r || rx <= l) {
return;
} else if (lx >= l && rx <= r) {
apply(x, value);
} else {
propagate(x);
int mid = (lx + rx) / 2;
update(l, r, value, x * 2, lx, mid);
update(l, r, value, x * 2 + 1, mid, rx);
tree[x] = merge(tree[x * 2], tree[x * 2 + 1]);
}
}
int query() {
return tree[1].value;
}
};
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int N;
cin >> N;
segment_tree T1(N), T2(N);
for (int i = 0; i < N; i++) {
int R, S;
cin >> R >> S;
if (S == 1) {
T1.update(0, R, 1);
T2.update(0, R, -1);
} else {
T1.update(0, R, -1);
T2.update(0, R, 1);
}
if (T1.query() >= 0) {
cout << ">\n";
} else if (T2.query() >= 0) {
cout << "<\n";
} else {
cout << "?\n";
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
456 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
6 ms |
1020 KB |
Output is correct |
11 |
Correct |
31 ms |
2904 KB |
Output is correct |
12 |
Correct |
58 ms |
5204 KB |
Output is correct |
13 |
Correct |
42 ms |
4648 KB |
Output is correct |
14 |
Correct |
39 ms |
5200 KB |
Output is correct |
15 |
Correct |
53 ms |
4692 KB |
Output is correct |
16 |
Correct |
42 ms |
5268 KB |
Output is correct |
17 |
Correct |
41 ms |
4944 KB |
Output is correct |
18 |
Correct |
67 ms |
5396 KB |
Output is correct |
19 |
Correct |
46 ms |
5200 KB |
Output is correct |
20 |
Correct |
43 ms |
4956 KB |
Output is correct |
21 |
Correct |
44 ms |
5140 KB |
Output is correct |
22 |
Correct |
45 ms |
5456 KB |
Output is correct |
23 |
Correct |
46 ms |
5116 KB |
Output is correct |
24 |
Correct |
49 ms |
5320 KB |
Output is correct |
25 |
Correct |
43 ms |
4700 KB |
Output is correct |