#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;}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
96604 KB |
Output is correct |
2 |
Correct |
13 ms |
96800 KB |
Output is correct |
3 |
Correct |
15 ms |
96604 KB |
Output is correct |
4 |
Correct |
13 ms |
96600 KB |
Output is correct |
5 |
Correct |
14 ms |
96784 KB |
Output is correct |
6 |
Correct |
15 ms |
96604 KB |
Output is correct |
7 |
Correct |
16 ms |
96604 KB |
Output is correct |
8 |
Correct |
13 ms |
96604 KB |
Output is correct |
9 |
Correct |
13 ms |
96604 KB |
Output is correct |
10 |
Correct |
13 ms |
96604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
96604 KB |
Output is correct |
2 |
Correct |
13 ms |
96800 KB |
Output is correct |
3 |
Correct |
15 ms |
96604 KB |
Output is correct |
4 |
Correct |
13 ms |
96600 KB |
Output is correct |
5 |
Correct |
14 ms |
96784 KB |
Output is correct |
6 |
Correct |
15 ms |
96604 KB |
Output is correct |
7 |
Correct |
16 ms |
96604 KB |
Output is correct |
8 |
Correct |
13 ms |
96604 KB |
Output is correct |
9 |
Correct |
13 ms |
96604 KB |
Output is correct |
10 |
Correct |
13 ms |
96604 KB |
Output is correct |
11 |
Correct |
15 ms |
96860 KB |
Output is correct |
12 |
Correct |
16 ms |
97656 KB |
Output is correct |
13 |
Correct |
16 ms |
97628 KB |
Output is correct |
14 |
Correct |
18 ms |
97680 KB |
Output is correct |
15 |
Correct |
17 ms |
97688 KB |
Output is correct |
16 |
Correct |
17 ms |
97628 KB |
Output is correct |
17 |
Correct |
15 ms |
97240 KB |
Output is correct |
18 |
Correct |
16 ms |
97596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2140 ms |
262144 KB |
Output is correct |
2 |
Correct |
2168 ms |
262144 KB |
Output is correct |
3 |
Correct |
2143 ms |
262144 KB |
Output is correct |
4 |
Correct |
2189 ms |
262144 KB |
Output is correct |
5 |
Correct |
1675 ms |
262144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
133 ms |
114808 KB |
Output is correct |
2 |
Correct |
124 ms |
114808 KB |
Output is correct |
3 |
Correct |
108 ms |
114676 KB |
Output is correct |
4 |
Correct |
108 ms |
114636 KB |
Output is correct |
5 |
Correct |
109 ms |
114692 KB |
Output is correct |
6 |
Correct |
96 ms |
114768 KB |
Output is correct |
7 |
Correct |
103 ms |
114972 KB |
Output is correct |
8 |
Correct |
95 ms |
114636 KB |
Output is correct |
9 |
Correct |
33 ms |
96860 KB |
Output is correct |
10 |
Correct |
118 ms |
114640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
96604 KB |
Output is correct |
2 |
Correct |
13 ms |
96800 KB |
Output is correct |
3 |
Correct |
15 ms |
96604 KB |
Output is correct |
4 |
Correct |
13 ms |
96600 KB |
Output is correct |
5 |
Correct |
14 ms |
96784 KB |
Output is correct |
6 |
Correct |
15 ms |
96604 KB |
Output is correct |
7 |
Correct |
16 ms |
96604 KB |
Output is correct |
8 |
Correct |
13 ms |
96604 KB |
Output is correct |
9 |
Correct |
13 ms |
96604 KB |
Output is correct |
10 |
Correct |
13 ms |
96604 KB |
Output is correct |
11 |
Correct |
15 ms |
96860 KB |
Output is correct |
12 |
Correct |
16 ms |
97656 KB |
Output is correct |
13 |
Correct |
16 ms |
97628 KB |
Output is correct |
14 |
Correct |
18 ms |
97680 KB |
Output is correct |
15 |
Correct |
17 ms |
97688 KB |
Output is correct |
16 |
Correct |
17 ms |
97628 KB |
Output is correct |
17 |
Correct |
15 ms |
97240 KB |
Output is correct |
18 |
Correct |
16 ms |
97596 KB |
Output is correct |
19 |
Correct |
314 ms |
131784 KB |
Output is correct |
20 |
Correct |
317 ms |
131640 KB |
Output is correct |
21 |
Correct |
281 ms |
131780 KB |
Output is correct |
22 |
Correct |
282 ms |
131844 KB |
Output is correct |
23 |
Correct |
294 ms |
131740 KB |
Output is correct |
24 |
Correct |
209 ms |
131784 KB |
Output is correct |
25 |
Correct |
218 ms |
131704 KB |
Output is correct |
26 |
Correct |
235 ms |
131756 KB |
Output is correct |
27 |
Correct |
263 ms |
131624 KB |
Output is correct |
28 |
Correct |
252 ms |
131784 KB |
Output is correct |
29 |
Correct |
239 ms |
131836 KB |
Output is correct |
30 |
Correct |
243 ms |
131780 KB |
Output is correct |
31 |
Correct |
239 ms |
131660 KB |
Output is correct |
32 |
Correct |
264 ms |
131784 KB |
Output is correct |
33 |
Correct |
253 ms |
131780 KB |
Output is correct |
34 |
Correct |
198 ms |
131780 KB |
Output is correct |
35 |
Correct |
193 ms |
131636 KB |
Output is correct |
36 |
Correct |
196 ms |
131784 KB |
Output is correct |
37 |
Correct |
191 ms |
131780 KB |
Output is correct |
38 |
Correct |
239 ms |
131784 KB |
Output is correct |
39 |
Correct |
235 ms |
131644 KB |
Output is correct |
40 |
Correct |
144 ms |
114888 KB |
Output is correct |
41 |
Correct |
208 ms |
131784 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
96604 KB |
Output is correct |
2 |
Correct |
13 ms |
96800 KB |
Output is correct |
3 |
Correct |
15 ms |
96604 KB |
Output is correct |
4 |
Correct |
13 ms |
96600 KB |
Output is correct |
5 |
Correct |
14 ms |
96784 KB |
Output is correct |
6 |
Correct |
15 ms |
96604 KB |
Output is correct |
7 |
Correct |
16 ms |
96604 KB |
Output is correct |
8 |
Correct |
13 ms |
96604 KB |
Output is correct |
9 |
Correct |
13 ms |
96604 KB |
Output is correct |
10 |
Correct |
13 ms |
96604 KB |
Output is correct |
11 |
Correct |
15 ms |
96860 KB |
Output is correct |
12 |
Correct |
16 ms |
97656 KB |
Output is correct |
13 |
Correct |
16 ms |
97628 KB |
Output is correct |
14 |
Correct |
18 ms |
97680 KB |
Output is correct |
15 |
Correct |
17 ms |
97688 KB |
Output is correct |
16 |
Correct |
17 ms |
97628 KB |
Output is correct |
17 |
Correct |
15 ms |
97240 KB |
Output is correct |
18 |
Correct |
16 ms |
97596 KB |
Output is correct |
19 |
Correct |
2140 ms |
262144 KB |
Output is correct |
20 |
Correct |
2168 ms |
262144 KB |
Output is correct |
21 |
Correct |
2143 ms |
262144 KB |
Output is correct |
22 |
Correct |
2189 ms |
262144 KB |
Output is correct |
23 |
Correct |
1675 ms |
262144 KB |
Output is correct |
24 |
Correct |
133 ms |
114808 KB |
Output is correct |
25 |
Correct |
124 ms |
114808 KB |
Output is correct |
26 |
Correct |
108 ms |
114676 KB |
Output is correct |
27 |
Correct |
108 ms |
114636 KB |
Output is correct |
28 |
Correct |
109 ms |
114692 KB |
Output is correct |
29 |
Correct |
96 ms |
114768 KB |
Output is correct |
30 |
Correct |
103 ms |
114972 KB |
Output is correct |
31 |
Correct |
95 ms |
114636 KB |
Output is correct |
32 |
Correct |
33 ms |
96860 KB |
Output is correct |
33 |
Correct |
118 ms |
114640 KB |
Output is correct |
34 |
Correct |
314 ms |
131784 KB |
Output is correct |
35 |
Correct |
317 ms |
131640 KB |
Output is correct |
36 |
Correct |
281 ms |
131780 KB |
Output is correct |
37 |
Correct |
282 ms |
131844 KB |
Output is correct |
38 |
Correct |
294 ms |
131740 KB |
Output is correct |
39 |
Correct |
209 ms |
131784 KB |
Output is correct |
40 |
Correct |
218 ms |
131704 KB |
Output is correct |
41 |
Correct |
235 ms |
131756 KB |
Output is correct |
42 |
Correct |
263 ms |
131624 KB |
Output is correct |
43 |
Correct |
252 ms |
131784 KB |
Output is correct |
44 |
Correct |
239 ms |
131836 KB |
Output is correct |
45 |
Correct |
243 ms |
131780 KB |
Output is correct |
46 |
Correct |
239 ms |
131660 KB |
Output is correct |
47 |
Correct |
264 ms |
131784 KB |
Output is correct |
48 |
Correct |
253 ms |
131780 KB |
Output is correct |
49 |
Correct |
198 ms |
131780 KB |
Output is correct |
50 |
Correct |
193 ms |
131636 KB |
Output is correct |
51 |
Correct |
196 ms |
131784 KB |
Output is correct |
52 |
Correct |
191 ms |
131780 KB |
Output is correct |
53 |
Correct |
239 ms |
131784 KB |
Output is correct |
54 |
Correct |
235 ms |
131644 KB |
Output is correct |
55 |
Correct |
144 ms |
114888 KB |
Output is correct |
56 |
Correct |
208 ms |
131784 KB |
Output is correct |
57 |
Correct |
2108 ms |
262144 KB |
Output is correct |
58 |
Correct |
2136 ms |
262144 KB |
Output is correct |
59 |
Correct |
2102 ms |
262144 KB |
Output is correct |
60 |
Correct |
2090 ms |
262144 KB |
Output is correct |
61 |
Correct |
2231 ms |
262144 KB |
Output is correct |
62 |
Correct |
2103 ms |
262144 KB |
Output is correct |
63 |
Correct |
1084 ms |
262144 KB |
Output is correct |
64 |
Correct |
1130 ms |
262144 KB |
Output is correct |
65 |
Correct |
1602 ms |
262144 KB |
Output is correct |
66 |
Correct |
1598 ms |
262144 KB |
Output is correct |
67 |
Correct |
1594 ms |
262144 KB |
Output is correct |
68 |
Correct |
1674 ms |
262144 KB |
Output is correct |
69 |
Correct |
1614 ms |
262144 KB |
Output is correct |
70 |
Correct |
1656 ms |
262144 KB |
Output is correct |
71 |
Correct |
1634 ms |
262144 KB |
Output is correct |
72 |
Correct |
1683 ms |
262144 KB |
Output is correct |
73 |
Correct |
1032 ms |
262144 KB |
Output is correct |
74 |
Correct |
1067 ms |
262144 KB |
Output is correct |
75 |
Correct |
1094 ms |
262144 KB |
Output is correct |
76 |
Correct |
1215 ms |
262144 KB |
Output is correct |
77 |
Correct |
1169 ms |
262144 KB |
Output is correct |
78 |
Correct |
1717 ms |
262144 KB |
Output is correct |
79 |
Correct |
923 ms |
192324 KB |
Output is correct |
80 |
Runtime error |
1516 ms |
262148 KB |
Memory limit exceeded |
81 |
Halted |
0 ms |
0 KB |
- |