#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("Ofast")
int const mxN = 1e6+5;
int n, pw;
vector<int> seg [4*mxN];
int ans[4*mxN], a[4*mxN];
void build ( int node, int l, int r) {
if(l==r-1) { seg[node].push_back(a[l]); return; }
int m = (l+r)/2;
build(node*2+1, l, m) , build(node*2+2, m, r);
seg[node] = seg[node*2+1];
int maxi = seg[node].back();
for(auto it:seg[node*2+2]) seg[node].push_back(it);
sort(seg[node].begin(),seg[node].end());
int ind = lower_bound(seg[node*2+2].begin(), seg[node*2+2].end(), maxi) - seg[node*2+2].begin(); ind--;
if(ind<0) ans[node] = 0;
else { ans[node] = seg[node*2+2][ind] + maxi; }
ans[node] = max ({ans[node], ans[node*2+1], ans[node*2+2]});
}
int fin = 0, maxi = 0;
void get ( int node, int l_n, int r_n, int l, int r) {
if(l_n>=r || r_n<=l) return;
if(l<=l_n && r>=r_n) {
fin = max (fin, ans[node]);
int ind = lower_bound(seg[node].begin(), seg[node].end(), maxi) - seg[node].begin(); ind--;
if(ind>=0) {
fin = max ( fin, maxi+seg[node][ind]);
}
maxi = max ( maxi, seg[node].back());
return;
}
int m = (l_n+r_n) / 2;
get(node*2+1, l_n, m, l, r), get(node*2+2, m ,r_n, l, r);
}
signed main() {
ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
cin>>n; int q; cin>>q;
for(int i=0; i<n; i++) cin>>a[i];
pw = (1<<(__lg(n-1)+1));
build(0,0,pw);
while(q--) {
int x,y; cin>>x>>y; int k; cin >> k;
x--;
fin = 0, maxi = 0;
get(0,0,pw,x,y);
cout<<(fin <= k)<<'\n';
}
return 0;}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
96604 KB |
Output is correct |
2 |
Correct |
13 ms |
96772 KB |
Output is correct |
3 |
Correct |
15 ms |
96600 KB |
Output is correct |
4 |
Correct |
14 ms |
96796 KB |
Output is correct |
5 |
Correct |
15 ms |
96600 KB |
Output is correct |
6 |
Correct |
13 ms |
96604 KB |
Output is correct |
7 |
Correct |
14 ms |
96600 KB |
Output is correct |
8 |
Correct |
17 ms |
96604 KB |
Output is correct |
9 |
Correct |
13 ms |
96604 KB |
Output is correct |
10 |
Correct |
13 ms |
96844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
96604 KB |
Output is correct |
2 |
Correct |
13 ms |
96772 KB |
Output is correct |
3 |
Correct |
15 ms |
96600 KB |
Output is correct |
4 |
Correct |
14 ms |
96796 KB |
Output is correct |
5 |
Correct |
15 ms |
96600 KB |
Output is correct |
6 |
Correct |
13 ms |
96604 KB |
Output is correct |
7 |
Correct |
14 ms |
96600 KB |
Output is correct |
8 |
Correct |
17 ms |
96604 KB |
Output is correct |
9 |
Correct |
13 ms |
96604 KB |
Output is correct |
10 |
Correct |
13 ms |
96844 KB |
Output is correct |
11 |
Correct |
18 ms |
96996 KB |
Output is correct |
12 |
Correct |
17 ms |
97692 KB |
Output is correct |
13 |
Correct |
21 ms |
97628 KB |
Output is correct |
14 |
Correct |
18 ms |
97628 KB |
Output is correct |
15 |
Correct |
18 ms |
97496 KB |
Output is correct |
16 |
Correct |
17 ms |
97512 KB |
Output is correct |
17 |
Correct |
15 ms |
97116 KB |
Output is correct |
18 |
Correct |
18 ms |
97616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2152 ms |
262144 KB |
Output is correct |
2 |
Correct |
2246 ms |
262144 KB |
Output is correct |
3 |
Correct |
2108 ms |
262144 KB |
Output is correct |
4 |
Correct |
2144 ms |
262144 KB |
Output is correct |
5 |
Correct |
1693 ms |
262144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
130 ms |
114636 KB |
Output is correct |
2 |
Correct |
126 ms |
114912 KB |
Output is correct |
3 |
Correct |
140 ms |
114640 KB |
Output is correct |
4 |
Correct |
107 ms |
114788 KB |
Output is correct |
5 |
Correct |
104 ms |
114640 KB |
Output is correct |
6 |
Correct |
111 ms |
114720 KB |
Output is correct |
7 |
Correct |
91 ms |
114700 KB |
Output is correct |
8 |
Correct |
94 ms |
114640 KB |
Output is correct |
9 |
Correct |
35 ms |
96860 KB |
Output is correct |
10 |
Correct |
105 ms |
114648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
96604 KB |
Output is correct |
2 |
Correct |
13 ms |
96772 KB |
Output is correct |
3 |
Correct |
15 ms |
96600 KB |
Output is correct |
4 |
Correct |
14 ms |
96796 KB |
Output is correct |
5 |
Correct |
15 ms |
96600 KB |
Output is correct |
6 |
Correct |
13 ms |
96604 KB |
Output is correct |
7 |
Correct |
14 ms |
96600 KB |
Output is correct |
8 |
Correct |
17 ms |
96604 KB |
Output is correct |
9 |
Correct |
13 ms |
96604 KB |
Output is correct |
10 |
Correct |
13 ms |
96844 KB |
Output is correct |
11 |
Correct |
18 ms |
96996 KB |
Output is correct |
12 |
Correct |
17 ms |
97692 KB |
Output is correct |
13 |
Correct |
21 ms |
97628 KB |
Output is correct |
14 |
Correct |
18 ms |
97628 KB |
Output is correct |
15 |
Correct |
18 ms |
97496 KB |
Output is correct |
16 |
Correct |
17 ms |
97512 KB |
Output is correct |
17 |
Correct |
15 ms |
97116 KB |
Output is correct |
18 |
Correct |
18 ms |
97616 KB |
Output is correct |
19 |
Correct |
343 ms |
131788 KB |
Output is correct |
20 |
Correct |
303 ms |
131632 KB |
Output is correct |
21 |
Correct |
302 ms |
131764 KB |
Output is correct |
22 |
Correct |
279 ms |
131812 KB |
Output is correct |
23 |
Correct |
284 ms |
131784 KB |
Output is correct |
24 |
Correct |
215 ms |
131780 KB |
Output is correct |
25 |
Correct |
204 ms |
131780 KB |
Output is correct |
26 |
Correct |
291 ms |
131804 KB |
Output is correct |
27 |
Correct |
229 ms |
131784 KB |
Output is correct |
28 |
Correct |
248 ms |
131764 KB |
Output is correct |
29 |
Correct |
254 ms |
131780 KB |
Output is correct |
30 |
Correct |
269 ms |
131780 KB |
Output is correct |
31 |
Correct |
271 ms |
131628 KB |
Output is correct |
32 |
Correct |
233 ms |
131736 KB |
Output is correct |
33 |
Correct |
247 ms |
131644 KB |
Output is correct |
34 |
Correct |
193 ms |
131780 KB |
Output is correct |
35 |
Correct |
191 ms |
131748 KB |
Output is correct |
36 |
Correct |
199 ms |
131784 KB |
Output is correct |
37 |
Correct |
192 ms |
131780 KB |
Output is correct |
38 |
Correct |
209 ms |
131628 KB |
Output is correct |
39 |
Correct |
246 ms |
131816 KB |
Output is correct |
40 |
Correct |
135 ms |
114896 KB |
Output is correct |
41 |
Correct |
203 ms |
131784 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
96604 KB |
Output is correct |
2 |
Correct |
13 ms |
96772 KB |
Output is correct |
3 |
Correct |
15 ms |
96600 KB |
Output is correct |
4 |
Correct |
14 ms |
96796 KB |
Output is correct |
5 |
Correct |
15 ms |
96600 KB |
Output is correct |
6 |
Correct |
13 ms |
96604 KB |
Output is correct |
7 |
Correct |
14 ms |
96600 KB |
Output is correct |
8 |
Correct |
17 ms |
96604 KB |
Output is correct |
9 |
Correct |
13 ms |
96604 KB |
Output is correct |
10 |
Correct |
13 ms |
96844 KB |
Output is correct |
11 |
Correct |
18 ms |
96996 KB |
Output is correct |
12 |
Correct |
17 ms |
97692 KB |
Output is correct |
13 |
Correct |
21 ms |
97628 KB |
Output is correct |
14 |
Correct |
18 ms |
97628 KB |
Output is correct |
15 |
Correct |
18 ms |
97496 KB |
Output is correct |
16 |
Correct |
17 ms |
97512 KB |
Output is correct |
17 |
Correct |
15 ms |
97116 KB |
Output is correct |
18 |
Correct |
18 ms |
97616 KB |
Output is correct |
19 |
Correct |
2152 ms |
262144 KB |
Output is correct |
20 |
Correct |
2246 ms |
262144 KB |
Output is correct |
21 |
Correct |
2108 ms |
262144 KB |
Output is correct |
22 |
Correct |
2144 ms |
262144 KB |
Output is correct |
23 |
Correct |
1693 ms |
262144 KB |
Output is correct |
24 |
Correct |
130 ms |
114636 KB |
Output is correct |
25 |
Correct |
126 ms |
114912 KB |
Output is correct |
26 |
Correct |
140 ms |
114640 KB |
Output is correct |
27 |
Correct |
107 ms |
114788 KB |
Output is correct |
28 |
Correct |
104 ms |
114640 KB |
Output is correct |
29 |
Correct |
111 ms |
114720 KB |
Output is correct |
30 |
Correct |
91 ms |
114700 KB |
Output is correct |
31 |
Correct |
94 ms |
114640 KB |
Output is correct |
32 |
Correct |
35 ms |
96860 KB |
Output is correct |
33 |
Correct |
105 ms |
114648 KB |
Output is correct |
34 |
Correct |
343 ms |
131788 KB |
Output is correct |
35 |
Correct |
303 ms |
131632 KB |
Output is correct |
36 |
Correct |
302 ms |
131764 KB |
Output is correct |
37 |
Correct |
279 ms |
131812 KB |
Output is correct |
38 |
Correct |
284 ms |
131784 KB |
Output is correct |
39 |
Correct |
215 ms |
131780 KB |
Output is correct |
40 |
Correct |
204 ms |
131780 KB |
Output is correct |
41 |
Correct |
291 ms |
131804 KB |
Output is correct |
42 |
Correct |
229 ms |
131784 KB |
Output is correct |
43 |
Correct |
248 ms |
131764 KB |
Output is correct |
44 |
Correct |
254 ms |
131780 KB |
Output is correct |
45 |
Correct |
269 ms |
131780 KB |
Output is correct |
46 |
Correct |
271 ms |
131628 KB |
Output is correct |
47 |
Correct |
233 ms |
131736 KB |
Output is correct |
48 |
Correct |
247 ms |
131644 KB |
Output is correct |
49 |
Correct |
193 ms |
131780 KB |
Output is correct |
50 |
Correct |
191 ms |
131748 KB |
Output is correct |
51 |
Correct |
199 ms |
131784 KB |
Output is correct |
52 |
Correct |
192 ms |
131780 KB |
Output is correct |
53 |
Correct |
209 ms |
131628 KB |
Output is correct |
54 |
Correct |
246 ms |
131816 KB |
Output is correct |
55 |
Correct |
135 ms |
114896 KB |
Output is correct |
56 |
Correct |
203 ms |
131784 KB |
Output is correct |
57 |
Correct |
2099 ms |
262144 KB |
Output is correct |
58 |
Correct |
2098 ms |
262144 KB |
Output is correct |
59 |
Correct |
2124 ms |
262144 KB |
Output is correct |
60 |
Correct |
2059 ms |
262144 KB |
Output is correct |
61 |
Correct |
2064 ms |
262144 KB |
Output is correct |
62 |
Correct |
2123 ms |
262144 KB |
Output is correct |
63 |
Correct |
1112 ms |
262144 KB |
Output is correct |
64 |
Correct |
1167 ms |
262144 KB |
Output is correct |
65 |
Correct |
1581 ms |
262144 KB |
Output is correct |
66 |
Correct |
1589 ms |
262144 KB |
Output is correct |
67 |
Correct |
1558 ms |
262144 KB |
Output is correct |
68 |
Correct |
1639 ms |
262144 KB |
Output is correct |
69 |
Correct |
1669 ms |
262144 KB |
Output is correct |
70 |
Correct |
1692 ms |
262144 KB |
Output is correct |
71 |
Correct |
1667 ms |
262144 KB |
Output is correct |
72 |
Correct |
1673 ms |
262144 KB |
Output is correct |
73 |
Correct |
1029 ms |
262144 KB |
Output is correct |
74 |
Correct |
1020 ms |
262144 KB |
Output is correct |
75 |
Correct |
1055 ms |
262144 KB |
Output is correct |
76 |
Correct |
1046 ms |
262144 KB |
Output is correct |
77 |
Correct |
1047 ms |
262144 KB |
Output is correct |
78 |
Correct |
1547 ms |
262144 KB |
Output is correct |
79 |
Correct |
820 ms |
192320 KB |
Output is correct |
80 |
Correct |
1294 ms |
262144 KB |
Output is correct |