#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
template<typename It>
ostream& _out(ostream& out, It b, It e){
for(It i = b; i != e; i++)
out << (i==b?"":" ") << *i;
return out;
}
template<typename T1, typename T2>
ostream& operator<<(ostream& out, pair<T1, T2> a){
return out << '(' << a.ff << ", " << a.ss << ')';
}
template<typename T, size_t N>
ostream& operator<<(ostream& out, array<T, N> a){
return _out(out << '[', all(a)) << ']';
}
template<typename T>
ostream& operator<<(ostream& out, vector<T> a){
return _out(out << '[', all(a)) << ']';
}
struct node{
node *L, *R;
int lt = 1050000000, ans = -1, maxh = -1050000000,
l, r;
node(int ll, int rr){
l = ll, r = rr;
if(l != r)L = new node(l, l+r>>1), R = new node((l+r>>1)+1, r);
}
void update(int x){
if(lt <= x)return;
lt = x;
ans = max(ans, maxh-lt);
//cout << "upd" << l<<r<<lt << " " << ans << endl;
}
void down(){
//cout << lt << endl;
L->update(lt), R->update(lt);
lt = 1050000000;
//cout << (array<int, 5>){l, r, ans ,L->ans, R->ans} << endl;
assert(max(L->ans, R->ans) >= ans);
}
void up(){
maxh = max(L->maxh, R->maxh);
//assert(max(L->ans, R->ans) >= ans);
ans = max(L->ans, R->ans);
}
void modify(int x, int val){
if(l == r)return (void) (maxh = val, lt = 1050000000);
down();
(x <= (l+r>>1)?L:R)->modify(x, val);
up();
//cout << l << r << " " << maxh << endl;
}
int query(int ll, int rr){
if(ll <= l && r <= rr)return ans;
if(ll > r || rr < l)return -1;
down();
return max(L->query(ll, rr), R->query(ll, rr));
}
void modifyr(int ll, int rr, int x){
if(ll <= l && r <= rr)return (void) update(x);
if(ll > r || rr < l)return;
down();
L->modifyr(ll, rr, x);
R->modifyr(ll, rr, x);
up();
//cout << l << r << " " << ans << endl;
}
void clear(){
lt = 1050000000, ans = -1, maxh = -1050000000;
if(l != r)L->clear(), R->clear();
}
} *root;
vector<array<int, 5>> events; // pos, type, (pos, val) / (l, id)
vector<int> qans;
signed main(){
#ifdef LOCAL
freopen("jizz.in","r",stdin);
#endif
int n, q;
cin >> n;
for(int i = 1; i <= n; i++){
int w, a, b;
cin >> w >> a >> b;
events.pb({i+a, 0, i, w, 0});
events.pb({i+b, 3, i, 0, 0});
events.pb({i, 1, i-b, i-a, w});
}
cin >> q; qans.resize(q, -1);
for(int i = 0; i < q; i++){
int l, r;
cin >> l >> r;
events.pb({r, 2, l, i});
}
sort(all(events));
root = new node(1, n);
for(auto i: events){
//cout << i << endl;
switch(i[1]){
case 0:
root->modify(i[2], i[3]);
break;
case 1:
root->modifyr(i[2],i[3], i[4]);
break;
case 2:
qans[i[3]] = max(qans[i[3]], root->query(i[2],i[0]));
break;
case 3:
root->modify(i[2], -1050000000);
break;
}
}
root->clear();
for(auto i: events){
switch(i[1]){
case 0:
root->modify(i[2], -i[3]);
break;
case 1:
root->modifyr(i[2],i[3], -i[4]);
break;
case 2:
qans[i[3]] = max(qans[i[3]], root->query(i[2],i[0]));
break;
case 3:
root->modify(i[2], -1050000000);
break;
}
}
for(auto i: qans)cout << i << endl;
}
Compilation message
antennas.cpp: In constructor 'node::node(int, int)':
antennas.cpp:32:36: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
if(l != r)L = new node(l, l+r>>1), R = new node((l+r>>1)+1, r);
~^~
antennas.cpp:32:59: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
if(l != r)L = new node(l, l+r>>1), R = new node((l+r>>1)+1, r);
~^~
antennas.cpp: In member function 'void node::modify(int, int)':
antennas.cpp:55:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
(x <= (l+r>>1)?L:R)->modify(x, val);
~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
6 ms |
376 KB |
Output is correct |
3 |
Correct |
6 ms |
376 KB |
Output is correct |
4 |
Correct |
6 ms |
376 KB |
Output is correct |
5 |
Correct |
6 ms |
376 KB |
Output is correct |
6 |
Correct |
6 ms |
372 KB |
Output is correct |
7 |
Correct |
6 ms |
376 KB |
Output is correct |
8 |
Correct |
6 ms |
376 KB |
Output is correct |
9 |
Correct |
6 ms |
376 KB |
Output is correct |
10 |
Correct |
6 ms |
376 KB |
Output is correct |
11 |
Correct |
6 ms |
376 KB |
Output is correct |
12 |
Correct |
7 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
6 ms |
376 KB |
Output is correct |
15 |
Correct |
6 ms |
376 KB |
Output is correct |
16 |
Correct |
6 ms |
376 KB |
Output is correct |
17 |
Correct |
6 ms |
380 KB |
Output is correct |
18 |
Correct |
6 ms |
376 KB |
Output is correct |
19 |
Correct |
6 ms |
376 KB |
Output is correct |
20 |
Correct |
6 ms |
376 KB |
Output is correct |
21 |
Correct |
6 ms |
376 KB |
Output is correct |
22 |
Correct |
6 ms |
376 KB |
Output is correct |
23 |
Correct |
6 ms |
376 KB |
Output is correct |
24 |
Correct |
6 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
6 ms |
376 KB |
Output is correct |
3 |
Correct |
6 ms |
376 KB |
Output is correct |
4 |
Correct |
6 ms |
376 KB |
Output is correct |
5 |
Correct |
6 ms |
376 KB |
Output is correct |
6 |
Correct |
6 ms |
372 KB |
Output is correct |
7 |
Correct |
6 ms |
376 KB |
Output is correct |
8 |
Correct |
6 ms |
376 KB |
Output is correct |
9 |
Correct |
6 ms |
376 KB |
Output is correct |
10 |
Correct |
6 ms |
376 KB |
Output is correct |
11 |
Correct |
6 ms |
376 KB |
Output is correct |
12 |
Correct |
7 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
6 ms |
376 KB |
Output is correct |
15 |
Correct |
6 ms |
376 KB |
Output is correct |
16 |
Correct |
6 ms |
376 KB |
Output is correct |
17 |
Correct |
6 ms |
380 KB |
Output is correct |
18 |
Correct |
6 ms |
376 KB |
Output is correct |
19 |
Correct |
6 ms |
376 KB |
Output is correct |
20 |
Correct |
6 ms |
376 KB |
Output is correct |
21 |
Correct |
6 ms |
376 KB |
Output is correct |
22 |
Correct |
6 ms |
376 KB |
Output is correct |
23 |
Correct |
6 ms |
376 KB |
Output is correct |
24 |
Correct |
6 ms |
376 KB |
Output is correct |
25 |
Correct |
473 ms |
7268 KB |
Output is correct |
26 |
Correct |
58 ms |
1264 KB |
Output is correct |
27 |
Correct |
646 ms |
8800 KB |
Output is correct |
28 |
Correct |
626 ms |
8924 KB |
Output is correct |
29 |
Correct |
460 ms |
7268 KB |
Output is correct |
30 |
Correct |
435 ms |
7324 KB |
Output is correct |
31 |
Correct |
598 ms |
8156 KB |
Output is correct |
32 |
Correct |
653 ms |
8928 KB |
Output is correct |
33 |
Correct |
597 ms |
8360 KB |
Output is correct |
34 |
Correct |
302 ms |
4584 KB |
Output is correct |
35 |
Correct |
623 ms |
8800 KB |
Output is correct |
36 |
Correct |
640 ms |
8928 KB |
Output is correct |
37 |
Correct |
373 ms |
4840 KB |
Output is correct |
38 |
Correct |
645 ms |
8032 KB |
Output is correct |
39 |
Correct |
93 ms |
2028 KB |
Output is correct |
40 |
Correct |
637 ms |
8028 KB |
Output is correct |
41 |
Correct |
459 ms |
7528 KB |
Output is correct |
42 |
Correct |
626 ms |
8028 KB |
Output is correct |
43 |
Correct |
218 ms |
3948 KB |
Output is correct |
44 |
Correct |
622 ms |
8028 KB |
Output is correct |
45 |
Correct |
116 ms |
2160 KB |
Output is correct |
46 |
Correct |
628 ms |
7904 KB |
Output is correct |
47 |
Correct |
169 ms |
2540 KB |
Output is correct |
48 |
Correct |
631 ms |
7904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
844 ms |
31924 KB |
Output is correct |
2 |
Correct |
915 ms |
35380 KB |
Output is correct |
3 |
Correct |
593 ms |
24908 KB |
Output is correct |
4 |
Correct |
926 ms |
35380 KB |
Output is correct |
5 |
Correct |
360 ms |
16380 KB |
Output is correct |
6 |
Correct |
944 ms |
35508 KB |
Output is correct |
7 |
Correct |
797 ms |
30668 KB |
Output is correct |
8 |
Correct |
941 ms |
35380 KB |
Output is correct |
9 |
Correct |
113 ms |
5988 KB |
Output is correct |
10 |
Correct |
952 ms |
35380 KB |
Output is correct |
11 |
Correct |
528 ms |
22196 KB |
Output is correct |
12 |
Correct |
958 ms |
35432 KB |
Output is correct |
13 |
Correct |
585 ms |
35256 KB |
Output is correct |
14 |
Correct |
614 ms |
35252 KB |
Output is correct |
15 |
Correct |
602 ms |
35252 KB |
Output is correct |
16 |
Correct |
560 ms |
35244 KB |
Output is correct |
17 |
Correct |
590 ms |
35232 KB |
Output is correct |
18 |
Correct |
604 ms |
35252 KB |
Output is correct |
19 |
Correct |
577 ms |
35252 KB |
Output is correct |
20 |
Correct |
585 ms |
35252 KB |
Output is correct |
21 |
Correct |
596 ms |
35252 KB |
Output is correct |
22 |
Correct |
606 ms |
35252 KB |
Output is correct |
23 |
Correct |
579 ms |
35212 KB |
Output is correct |
24 |
Correct |
560 ms |
35204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
6 ms |
376 KB |
Output is correct |
3 |
Correct |
6 ms |
376 KB |
Output is correct |
4 |
Correct |
6 ms |
376 KB |
Output is correct |
5 |
Correct |
6 ms |
376 KB |
Output is correct |
6 |
Correct |
6 ms |
372 KB |
Output is correct |
7 |
Correct |
6 ms |
376 KB |
Output is correct |
8 |
Correct |
6 ms |
376 KB |
Output is correct |
9 |
Correct |
6 ms |
376 KB |
Output is correct |
10 |
Correct |
6 ms |
376 KB |
Output is correct |
11 |
Correct |
6 ms |
376 KB |
Output is correct |
12 |
Correct |
7 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
6 ms |
376 KB |
Output is correct |
15 |
Correct |
6 ms |
376 KB |
Output is correct |
16 |
Correct |
6 ms |
376 KB |
Output is correct |
17 |
Correct |
6 ms |
380 KB |
Output is correct |
18 |
Correct |
6 ms |
376 KB |
Output is correct |
19 |
Correct |
6 ms |
376 KB |
Output is correct |
20 |
Correct |
6 ms |
376 KB |
Output is correct |
21 |
Correct |
6 ms |
376 KB |
Output is correct |
22 |
Correct |
6 ms |
376 KB |
Output is correct |
23 |
Correct |
6 ms |
376 KB |
Output is correct |
24 |
Correct |
6 ms |
376 KB |
Output is correct |
25 |
Correct |
473 ms |
7268 KB |
Output is correct |
26 |
Correct |
58 ms |
1264 KB |
Output is correct |
27 |
Correct |
646 ms |
8800 KB |
Output is correct |
28 |
Correct |
626 ms |
8924 KB |
Output is correct |
29 |
Correct |
460 ms |
7268 KB |
Output is correct |
30 |
Correct |
435 ms |
7324 KB |
Output is correct |
31 |
Correct |
598 ms |
8156 KB |
Output is correct |
32 |
Correct |
653 ms |
8928 KB |
Output is correct |
33 |
Correct |
597 ms |
8360 KB |
Output is correct |
34 |
Correct |
302 ms |
4584 KB |
Output is correct |
35 |
Correct |
623 ms |
8800 KB |
Output is correct |
36 |
Correct |
640 ms |
8928 KB |
Output is correct |
37 |
Correct |
373 ms |
4840 KB |
Output is correct |
38 |
Correct |
645 ms |
8032 KB |
Output is correct |
39 |
Correct |
93 ms |
2028 KB |
Output is correct |
40 |
Correct |
637 ms |
8028 KB |
Output is correct |
41 |
Correct |
459 ms |
7528 KB |
Output is correct |
42 |
Correct |
626 ms |
8028 KB |
Output is correct |
43 |
Correct |
218 ms |
3948 KB |
Output is correct |
44 |
Correct |
622 ms |
8028 KB |
Output is correct |
45 |
Correct |
116 ms |
2160 KB |
Output is correct |
46 |
Correct |
628 ms |
7904 KB |
Output is correct |
47 |
Correct |
169 ms |
2540 KB |
Output is correct |
48 |
Correct |
631 ms |
7904 KB |
Output is correct |
49 |
Correct |
844 ms |
31924 KB |
Output is correct |
50 |
Correct |
915 ms |
35380 KB |
Output is correct |
51 |
Correct |
593 ms |
24908 KB |
Output is correct |
52 |
Correct |
926 ms |
35380 KB |
Output is correct |
53 |
Correct |
360 ms |
16380 KB |
Output is correct |
54 |
Correct |
944 ms |
35508 KB |
Output is correct |
55 |
Correct |
797 ms |
30668 KB |
Output is correct |
56 |
Correct |
941 ms |
35380 KB |
Output is correct |
57 |
Correct |
113 ms |
5988 KB |
Output is correct |
58 |
Correct |
952 ms |
35380 KB |
Output is correct |
59 |
Correct |
528 ms |
22196 KB |
Output is correct |
60 |
Correct |
958 ms |
35432 KB |
Output is correct |
61 |
Correct |
585 ms |
35256 KB |
Output is correct |
62 |
Correct |
614 ms |
35252 KB |
Output is correct |
63 |
Correct |
602 ms |
35252 KB |
Output is correct |
64 |
Correct |
560 ms |
35244 KB |
Output is correct |
65 |
Correct |
590 ms |
35232 KB |
Output is correct |
66 |
Correct |
604 ms |
35252 KB |
Output is correct |
67 |
Correct |
577 ms |
35252 KB |
Output is correct |
68 |
Correct |
585 ms |
35252 KB |
Output is correct |
69 |
Correct |
596 ms |
35252 KB |
Output is correct |
70 |
Correct |
606 ms |
35252 KB |
Output is correct |
71 |
Correct |
579 ms |
35212 KB |
Output is correct |
72 |
Correct |
560 ms |
35204 KB |
Output is correct |
73 |
Correct |
1518 ms |
38840 KB |
Output is correct |
74 |
Correct |
1022 ms |
36020 KB |
Output is correct |
75 |
Correct |
1537 ms |
34100 KB |
Output is correct |
76 |
Correct |
1915 ms |
44596 KB |
Output is correct |
77 |
Correct |
1000 ms |
22988 KB |
Output is correct |
78 |
Correct |
1547 ms |
41652 KB |
Output is correct |
79 |
Correct |
1718 ms |
39988 KB |
Output is correct |
80 |
Correct |
1863 ms |
44636 KB |
Output is correct |
81 |
Correct |
832 ms |
14416 KB |
Output is correct |
82 |
Correct |
1390 ms |
39860 KB |
Output is correct |
83 |
Correct |
1372 ms |
31408 KB |
Output is correct |
84 |
Correct |
1870 ms |
44596 KB |
Output is correct |
85 |
Correct |
1072 ms |
39860 KB |
Output is correct |
86 |
Correct |
1458 ms |
43396 KB |
Output is correct |
87 |
Correct |
701 ms |
36304 KB |
Output is correct |
88 |
Correct |
1422 ms |
43316 KB |
Output is correct |
89 |
Correct |
1236 ms |
41140 KB |
Output is correct |
90 |
Correct |
1449 ms |
43384 KB |
Output is correct |
91 |
Correct |
860 ms |
37940 KB |
Output is correct |
92 |
Correct |
1480 ms |
43316 KB |
Output is correct |
93 |
Correct |
729 ms |
36532 KB |
Output is correct |
94 |
Correct |
1455 ms |
43316 KB |
Output is correct |
95 |
Correct |
813 ms |
37300 KB |
Output is correct |
96 |
Correct |
1421 ms |
43420 KB |
Output is correct |