#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 |
1 ms |
348 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 |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
4 ms |
860 KB |
Output is correct |
11 |
Correct |
31 ms |
2648 KB |
Output is correct |
12 |
Correct |
59 ms |
4768 KB |
Output is correct |
13 |
Correct |
40 ms |
5460 KB |
Output is correct |
14 |
Correct |
40 ms |
4948 KB |
Output is correct |
15 |
Correct |
42 ms |
5460 KB |
Output is correct |
16 |
Correct |
42 ms |
4988 KB |
Output is correct |
17 |
Correct |
40 ms |
5200 KB |
Output is correct |
18 |
Correct |
68 ms |
5020 KB |
Output is correct |
19 |
Correct |
46 ms |
4696 KB |
Output is correct |
20 |
Correct |
43 ms |
5196 KB |
Output is correct |
21 |
Correct |
43 ms |
4948 KB |
Output is correct |
22 |
Correct |
45 ms |
4672 KB |
Output is correct |
23 |
Correct |
52 ms |
4860 KB |
Output is correct |
24 |
Correct |
62 ms |
4700 KB |
Output is correct |
25 |
Correct |
43 ms |
5464 KB |
Output is correct |