#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
const int N = 1e6 + 5, oo = 1e9;
multiset < int > ms[N];
int tree[4 * N];
void update(int l, int r, int x, int val, int p) {
if(l > x || r < x) return;
if(l == r) {
tree[p] = val;
} else {
int m = l + r >> 1;
update(l, m, x, val, p << 1);
update(m + 1, r, x, val, p << 1 | 1);
tree[p] = min(tree[p << 1], tree[p << 1 | 1]);
}
}
int query(int l, int r, int L, int R, int p) {
if(L > r || l > R) return oo;
if(L <= l && R >= r) return tree[p];
int m = l + r >> 1;
return min(query(l, m, L, R, p << 1), query(m + 1, r, L, R, p << 1 | 1));
}
int main() {
for(int i = 0; i < 4 * N; ++i) tree[i] = oo;
int q;
cin >> q;
multiset < pair < int, int > > m;
for(int i = 1; i <= q; ++i) {
int l, r;
char t;
cin >> t >> l >> r;
if(t == 'R') {
m.erase(m.find({l, r}));
ms[l].erase(ms[l].find(r));
int val = oo;
if(!ms[l].empty()) {
val = *ms[l].begin();
}
update(1, N - 1, l, val, 1);
} else {
m.insert({l, r});
ms[l].insert(r);
update(1, N - 1, l, *ms[l].begin(), 1);
}
int maxL = -1, minR = 1e9;
for(auto [l, r] : m) {
maxL = max(maxL, l);
minR = min(minR, r);
}
if(minR <= maxL) {
int best = 1e9;
for(auto [l, r] : m) {
best = min(best, query(1, N - 1, r, N - 1, 1) - l);
}
cout << best << '\n';
} else {
int ansL = -1, ansR = 1e9;
for(auto [l, r] : m) {
if(l == maxL) {
ansR = min(ansR, r);
}
if(r == minR) {
ansL = max(ansL, l);
}
}
cout << ansR - ansL << '\n';
}
}
}
Compilation message
Main.cpp: In function 'void update(int, int, int, int, int)':
Main.cpp:13:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
13 | int m = l + r >> 1;
| ~~^~~
Main.cpp: In function 'int query(int, int, int, int, int)':
Main.cpp:22:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
22 | int m = l + r >> 1;
| ~~^~~
Main.cpp: In function 'int main()':
Main.cpp:48:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
48 | for(auto [l, r] : m) {
| ^
Main.cpp:54:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
54 | for(auto [l, r] : m) {
| ^
Main.cpp:60:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
60 | for(auto [l, r] : m) {
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
70 ms |
63096 KB |
Output is correct |
2 |
Correct |
50 ms |
62968 KB |
Output is correct |
3 |
Correct |
46 ms |
63096 KB |
Output is correct |
4 |
Correct |
44 ms |
62968 KB |
Output is correct |
5 |
Correct |
71 ms |
62976 KB |
Output is correct |
6 |
Correct |
51 ms |
62968 KB |
Output is correct |
7 |
Correct |
45 ms |
62968 KB |
Output is correct |
8 |
Correct |
49 ms |
62968 KB |
Output is correct |
9 |
Correct |
79 ms |
63096 KB |
Output is correct |
10 |
Correct |
69 ms |
62968 KB |
Output is correct |
11 |
Correct |
65 ms |
62968 KB |
Output is correct |
12 |
Correct |
68 ms |
62976 KB |
Output is correct |
13 |
Correct |
80 ms |
62968 KB |
Output is correct |
14 |
Correct |
86 ms |
62968 KB |
Output is correct |
15 |
Correct |
81 ms |
62976 KB |
Output is correct |
16 |
Correct |
81 ms |
62976 KB |
Output is correct |
17 |
Correct |
70 ms |
62976 KB |
Output is correct |
18 |
Correct |
53 ms |
62956 KB |
Output is correct |
19 |
Correct |
45 ms |
62968 KB |
Output is correct |
20 |
Correct |
43 ms |
62972 KB |
Output is correct |
21 |
Correct |
72 ms |
62972 KB |
Output is correct |
22 |
Correct |
51 ms |
62968 KB |
Output is correct |
23 |
Correct |
45 ms |
62976 KB |
Output is correct |
24 |
Correct |
47 ms |
62968 KB |
Output is correct |
25 |
Correct |
75 ms |
63096 KB |
Output is correct |
26 |
Correct |
66 ms |
62968 KB |
Output is correct |
27 |
Correct |
64 ms |
62972 KB |
Output is correct |
28 |
Correct |
65 ms |
62976 KB |
Output is correct |
29 |
Correct |
80 ms |
63224 KB |
Output is correct |
30 |
Correct |
82 ms |
62968 KB |
Output is correct |
31 |
Correct |
82 ms |
62968 KB |
Output is correct |
32 |
Correct |
81 ms |
62972 KB |
Output is correct |
33 |
Correct |
43 ms |
62968 KB |
Output is correct |
34 |
Correct |
45 ms |
62968 KB |
Output is correct |
35 |
Correct |
44 ms |
62968 KB |
Output is correct |
36 |
Correct |
44 ms |
62968 KB |
Output is correct |
37 |
Correct |
46 ms |
62976 KB |
Output is correct |
38 |
Correct |
45 ms |
62968 KB |
Output is correct |
39 |
Correct |
44 ms |
62968 KB |
Output is correct |
40 |
Correct |
45 ms |
62976 KB |
Output is correct |
41 |
Correct |
63 ms |
63000 KB |
Output is correct |
42 |
Correct |
48 ms |
62968 KB |
Output is correct |
43 |
Correct |
45 ms |
62912 KB |
Output is correct |
44 |
Correct |
49 ms |
62972 KB |
Output is correct |
45 |
Correct |
62 ms |
62976 KB |
Output is correct |
46 |
Correct |
48 ms |
62972 KB |
Output is correct |
47 |
Correct |
44 ms |
62968 KB |
Output is correct |
48 |
Correct |
44 ms |
62968 KB |
Output is correct |
49 |
Correct |
69 ms |
62968 KB |
Output is correct |
50 |
Correct |
66 ms |
62968 KB |
Output is correct |
51 |
Correct |
64 ms |
62968 KB |
Output is correct |
52 |
Correct |
66 ms |
62968 KB |
Output is correct |
53 |
Correct |
64 ms |
62968 KB |
Output is correct |
54 |
Correct |
64 ms |
62968 KB |
Output is correct |
55 |
Correct |
65 ms |
63096 KB |
Output is correct |
56 |
Correct |
65 ms |
62968 KB |
Output is correct |
57 |
Correct |
63 ms |
62968 KB |
Output is correct |
58 |
Correct |
65 ms |
62976 KB |
Output is correct |
59 |
Correct |
77 ms |
62976 KB |
Output is correct |
60 |
Correct |
80 ms |
63096 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
70 ms |
63096 KB |
Output is correct |
2 |
Correct |
50 ms |
62968 KB |
Output is correct |
3 |
Correct |
46 ms |
63096 KB |
Output is correct |
4 |
Correct |
44 ms |
62968 KB |
Output is correct |
5 |
Correct |
71 ms |
62976 KB |
Output is correct |
6 |
Correct |
51 ms |
62968 KB |
Output is correct |
7 |
Correct |
45 ms |
62968 KB |
Output is correct |
8 |
Correct |
49 ms |
62968 KB |
Output is correct |
9 |
Correct |
79 ms |
63096 KB |
Output is correct |
10 |
Correct |
69 ms |
62968 KB |
Output is correct |
11 |
Correct |
65 ms |
62968 KB |
Output is correct |
12 |
Correct |
68 ms |
62976 KB |
Output is correct |
13 |
Correct |
80 ms |
62968 KB |
Output is correct |
14 |
Correct |
86 ms |
62968 KB |
Output is correct |
15 |
Correct |
81 ms |
62976 KB |
Output is correct |
16 |
Correct |
81 ms |
62976 KB |
Output is correct |
17 |
Correct |
70 ms |
62976 KB |
Output is correct |
18 |
Correct |
53 ms |
62956 KB |
Output is correct |
19 |
Correct |
45 ms |
62968 KB |
Output is correct |
20 |
Correct |
43 ms |
62972 KB |
Output is correct |
21 |
Correct |
72 ms |
62972 KB |
Output is correct |
22 |
Correct |
51 ms |
62968 KB |
Output is correct |
23 |
Correct |
45 ms |
62976 KB |
Output is correct |
24 |
Correct |
47 ms |
62968 KB |
Output is correct |
25 |
Correct |
75 ms |
63096 KB |
Output is correct |
26 |
Correct |
66 ms |
62968 KB |
Output is correct |
27 |
Correct |
64 ms |
62972 KB |
Output is correct |
28 |
Correct |
65 ms |
62976 KB |
Output is correct |
29 |
Correct |
80 ms |
63224 KB |
Output is correct |
30 |
Correct |
82 ms |
62968 KB |
Output is correct |
31 |
Correct |
82 ms |
62968 KB |
Output is correct |
32 |
Correct |
81 ms |
62972 KB |
Output is correct |
33 |
Correct |
43 ms |
62968 KB |
Output is correct |
34 |
Correct |
45 ms |
62968 KB |
Output is correct |
35 |
Correct |
44 ms |
62968 KB |
Output is correct |
36 |
Correct |
44 ms |
62968 KB |
Output is correct |
37 |
Correct |
46 ms |
62976 KB |
Output is correct |
38 |
Correct |
45 ms |
62968 KB |
Output is correct |
39 |
Correct |
44 ms |
62968 KB |
Output is correct |
40 |
Correct |
45 ms |
62976 KB |
Output is correct |
41 |
Correct |
63 ms |
63000 KB |
Output is correct |
42 |
Correct |
48 ms |
62968 KB |
Output is correct |
43 |
Correct |
45 ms |
62912 KB |
Output is correct |
44 |
Correct |
49 ms |
62972 KB |
Output is correct |
45 |
Correct |
62 ms |
62976 KB |
Output is correct |
46 |
Correct |
48 ms |
62972 KB |
Output is correct |
47 |
Correct |
44 ms |
62968 KB |
Output is correct |
48 |
Correct |
44 ms |
62968 KB |
Output is correct |
49 |
Correct |
69 ms |
62968 KB |
Output is correct |
50 |
Correct |
66 ms |
62968 KB |
Output is correct |
51 |
Correct |
64 ms |
62968 KB |
Output is correct |
52 |
Correct |
66 ms |
62968 KB |
Output is correct |
53 |
Correct |
64 ms |
62968 KB |
Output is correct |
54 |
Correct |
64 ms |
62968 KB |
Output is correct |
55 |
Correct |
65 ms |
63096 KB |
Output is correct |
56 |
Correct |
65 ms |
62968 KB |
Output is correct |
57 |
Correct |
63 ms |
62968 KB |
Output is correct |
58 |
Correct |
65 ms |
62976 KB |
Output is correct |
59 |
Correct |
77 ms |
62976 KB |
Output is correct |
60 |
Correct |
80 ms |
63096 KB |
Output is correct |
61 |
Correct |
42 ms |
62968 KB |
Output is correct |
62 |
Correct |
42 ms |
62968 KB |
Output is correct |
63 |
Correct |
42 ms |
62900 KB |
Output is correct |
64 |
Execution timed out |
7066 ms |
63996 KB |
Time limit exceeded |
65 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
70 ms |
63096 KB |
Output is correct |
2 |
Correct |
50 ms |
62968 KB |
Output is correct |
3 |
Correct |
46 ms |
63096 KB |
Output is correct |
4 |
Correct |
44 ms |
62968 KB |
Output is correct |
5 |
Correct |
71 ms |
62976 KB |
Output is correct |
6 |
Correct |
51 ms |
62968 KB |
Output is correct |
7 |
Correct |
45 ms |
62968 KB |
Output is correct |
8 |
Correct |
49 ms |
62968 KB |
Output is correct |
9 |
Correct |
79 ms |
63096 KB |
Output is correct |
10 |
Correct |
69 ms |
62968 KB |
Output is correct |
11 |
Correct |
65 ms |
62968 KB |
Output is correct |
12 |
Correct |
68 ms |
62976 KB |
Output is correct |
13 |
Correct |
80 ms |
62968 KB |
Output is correct |
14 |
Correct |
86 ms |
62968 KB |
Output is correct |
15 |
Correct |
81 ms |
62976 KB |
Output is correct |
16 |
Correct |
81 ms |
62976 KB |
Output is correct |
17 |
Correct |
70 ms |
62976 KB |
Output is correct |
18 |
Correct |
53 ms |
62956 KB |
Output is correct |
19 |
Correct |
45 ms |
62968 KB |
Output is correct |
20 |
Correct |
43 ms |
62972 KB |
Output is correct |
21 |
Correct |
72 ms |
62972 KB |
Output is correct |
22 |
Correct |
51 ms |
62968 KB |
Output is correct |
23 |
Correct |
45 ms |
62976 KB |
Output is correct |
24 |
Correct |
47 ms |
62968 KB |
Output is correct |
25 |
Correct |
75 ms |
63096 KB |
Output is correct |
26 |
Correct |
66 ms |
62968 KB |
Output is correct |
27 |
Correct |
64 ms |
62972 KB |
Output is correct |
28 |
Correct |
65 ms |
62976 KB |
Output is correct |
29 |
Correct |
80 ms |
63224 KB |
Output is correct |
30 |
Correct |
82 ms |
62968 KB |
Output is correct |
31 |
Correct |
82 ms |
62968 KB |
Output is correct |
32 |
Correct |
81 ms |
62972 KB |
Output is correct |
33 |
Correct |
43 ms |
62968 KB |
Output is correct |
34 |
Correct |
45 ms |
62968 KB |
Output is correct |
35 |
Correct |
44 ms |
62968 KB |
Output is correct |
36 |
Correct |
44 ms |
62968 KB |
Output is correct |
37 |
Correct |
46 ms |
62976 KB |
Output is correct |
38 |
Correct |
45 ms |
62968 KB |
Output is correct |
39 |
Correct |
44 ms |
62968 KB |
Output is correct |
40 |
Correct |
45 ms |
62976 KB |
Output is correct |
41 |
Correct |
63 ms |
63000 KB |
Output is correct |
42 |
Correct |
48 ms |
62968 KB |
Output is correct |
43 |
Correct |
45 ms |
62912 KB |
Output is correct |
44 |
Correct |
49 ms |
62972 KB |
Output is correct |
45 |
Correct |
62 ms |
62976 KB |
Output is correct |
46 |
Correct |
48 ms |
62972 KB |
Output is correct |
47 |
Correct |
44 ms |
62968 KB |
Output is correct |
48 |
Correct |
44 ms |
62968 KB |
Output is correct |
49 |
Correct |
69 ms |
62968 KB |
Output is correct |
50 |
Correct |
66 ms |
62968 KB |
Output is correct |
51 |
Correct |
64 ms |
62968 KB |
Output is correct |
52 |
Correct |
66 ms |
62968 KB |
Output is correct |
53 |
Correct |
64 ms |
62968 KB |
Output is correct |
54 |
Correct |
64 ms |
62968 KB |
Output is correct |
55 |
Correct |
65 ms |
63096 KB |
Output is correct |
56 |
Correct |
65 ms |
62968 KB |
Output is correct |
57 |
Correct |
63 ms |
62968 KB |
Output is correct |
58 |
Correct |
65 ms |
62976 KB |
Output is correct |
59 |
Correct |
77 ms |
62976 KB |
Output is correct |
60 |
Correct |
80 ms |
63096 KB |
Output is correct |
61 |
Correct |
42 ms |
62968 KB |
Output is correct |
62 |
Correct |
42 ms |
62968 KB |
Output is correct |
63 |
Correct |
42 ms |
62900 KB |
Output is correct |
64 |
Execution timed out |
7066 ms |
63996 KB |
Time limit exceeded |
65 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
7063 ms |
63912 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
70 ms |
63096 KB |
Output is correct |
2 |
Correct |
50 ms |
62968 KB |
Output is correct |
3 |
Correct |
46 ms |
63096 KB |
Output is correct |
4 |
Correct |
44 ms |
62968 KB |
Output is correct |
5 |
Correct |
71 ms |
62976 KB |
Output is correct |
6 |
Correct |
51 ms |
62968 KB |
Output is correct |
7 |
Correct |
45 ms |
62968 KB |
Output is correct |
8 |
Correct |
49 ms |
62968 KB |
Output is correct |
9 |
Correct |
79 ms |
63096 KB |
Output is correct |
10 |
Correct |
69 ms |
62968 KB |
Output is correct |
11 |
Correct |
65 ms |
62968 KB |
Output is correct |
12 |
Correct |
68 ms |
62976 KB |
Output is correct |
13 |
Correct |
80 ms |
62968 KB |
Output is correct |
14 |
Correct |
86 ms |
62968 KB |
Output is correct |
15 |
Correct |
81 ms |
62976 KB |
Output is correct |
16 |
Correct |
81 ms |
62976 KB |
Output is correct |
17 |
Correct |
70 ms |
62976 KB |
Output is correct |
18 |
Correct |
53 ms |
62956 KB |
Output is correct |
19 |
Correct |
45 ms |
62968 KB |
Output is correct |
20 |
Correct |
43 ms |
62972 KB |
Output is correct |
21 |
Correct |
72 ms |
62972 KB |
Output is correct |
22 |
Correct |
51 ms |
62968 KB |
Output is correct |
23 |
Correct |
45 ms |
62976 KB |
Output is correct |
24 |
Correct |
47 ms |
62968 KB |
Output is correct |
25 |
Correct |
75 ms |
63096 KB |
Output is correct |
26 |
Correct |
66 ms |
62968 KB |
Output is correct |
27 |
Correct |
64 ms |
62972 KB |
Output is correct |
28 |
Correct |
65 ms |
62976 KB |
Output is correct |
29 |
Correct |
80 ms |
63224 KB |
Output is correct |
30 |
Correct |
82 ms |
62968 KB |
Output is correct |
31 |
Correct |
82 ms |
62968 KB |
Output is correct |
32 |
Correct |
81 ms |
62972 KB |
Output is correct |
33 |
Correct |
43 ms |
62968 KB |
Output is correct |
34 |
Correct |
45 ms |
62968 KB |
Output is correct |
35 |
Correct |
44 ms |
62968 KB |
Output is correct |
36 |
Correct |
44 ms |
62968 KB |
Output is correct |
37 |
Correct |
46 ms |
62976 KB |
Output is correct |
38 |
Correct |
45 ms |
62968 KB |
Output is correct |
39 |
Correct |
44 ms |
62968 KB |
Output is correct |
40 |
Correct |
45 ms |
62976 KB |
Output is correct |
41 |
Correct |
63 ms |
63000 KB |
Output is correct |
42 |
Correct |
48 ms |
62968 KB |
Output is correct |
43 |
Correct |
45 ms |
62912 KB |
Output is correct |
44 |
Correct |
49 ms |
62972 KB |
Output is correct |
45 |
Correct |
62 ms |
62976 KB |
Output is correct |
46 |
Correct |
48 ms |
62972 KB |
Output is correct |
47 |
Correct |
44 ms |
62968 KB |
Output is correct |
48 |
Correct |
44 ms |
62968 KB |
Output is correct |
49 |
Correct |
69 ms |
62968 KB |
Output is correct |
50 |
Correct |
66 ms |
62968 KB |
Output is correct |
51 |
Correct |
64 ms |
62968 KB |
Output is correct |
52 |
Correct |
66 ms |
62968 KB |
Output is correct |
53 |
Correct |
64 ms |
62968 KB |
Output is correct |
54 |
Correct |
64 ms |
62968 KB |
Output is correct |
55 |
Correct |
65 ms |
63096 KB |
Output is correct |
56 |
Correct |
65 ms |
62968 KB |
Output is correct |
57 |
Correct |
63 ms |
62968 KB |
Output is correct |
58 |
Correct |
65 ms |
62976 KB |
Output is correct |
59 |
Correct |
77 ms |
62976 KB |
Output is correct |
60 |
Correct |
80 ms |
63096 KB |
Output is correct |
61 |
Correct |
42 ms |
62968 KB |
Output is correct |
62 |
Correct |
42 ms |
62968 KB |
Output is correct |
63 |
Correct |
42 ms |
62900 KB |
Output is correct |
64 |
Execution timed out |
7066 ms |
63996 KB |
Time limit exceeded |
65 |
Halted |
0 ms |
0 KB |
- |