#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define s second
#define f first
#define pll pair <ll,ll>
#define pii pair <int,int>
#define left h*2,l,(l + r)/2
#define right h*2+1,(l + r)/2 + 1,r
using namespace std;
const int N = 1e6 + 5,inf = 1e9;
int a[N],le[N],ri[N],ans[N],k[N];
int t[4*N];
vector <int> v[N];
void upd(int h,int l,int r,int idx,int val){
if (l == r){
t[h] = max(t[h],val);
return;
}
int mid = (l + r)/2;
if (idx > mid) upd(right,idx,val);
else upd(left,idx,val);
t[h] = max(t[h*2],t[h*2 + 1]);
}
int get(int h,int l,int r,int L,int R){
if (r < L || R < l) return 0;
if (L <= l && r <= R) return t[h];
return max(get(left,L,R),get(right,L,R));
}
signed main() {
ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
int n,Q;
cin>>n>>Q;
for (int i = 1; i <= n; i++){
cin>>a[i];
}
for (int i = 1; i <= Q; i++){
cin>>le[i]>>ri[i]>>k[i];
v[ri[i]].pb(i);
}
deque <int> dq;
for (int i = 1; i <= n; i++){
while (dq.size() && a[dq.back()] <= a[i]){
dq.pop_back();
}
if (dq.size()){
upd(1,1,n,dq.back(),a[i] + a[dq.back()]);
}
dq.pb(i);
for (int id: v[i]){
if (get(1,1,n,le[id],i) <= k[id]) ans[id] = 1;
}
}
for (int i = 1; i <= Q; i++)
cout<<ans[i]<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
23820 KB |
Output is correct |
2 |
Correct |
11 ms |
23816 KB |
Output is correct |
3 |
Correct |
15 ms |
23880 KB |
Output is correct |
4 |
Correct |
11 ms |
23856 KB |
Output is correct |
5 |
Correct |
11 ms |
23812 KB |
Output is correct |
6 |
Correct |
12 ms |
23852 KB |
Output is correct |
7 |
Correct |
11 ms |
23796 KB |
Output is correct |
8 |
Correct |
15 ms |
23764 KB |
Output is correct |
9 |
Correct |
11 ms |
23764 KB |
Output is correct |
10 |
Correct |
12 ms |
23820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
23820 KB |
Output is correct |
2 |
Correct |
11 ms |
23816 KB |
Output is correct |
3 |
Correct |
15 ms |
23880 KB |
Output is correct |
4 |
Correct |
11 ms |
23856 KB |
Output is correct |
5 |
Correct |
11 ms |
23812 KB |
Output is correct |
6 |
Correct |
12 ms |
23852 KB |
Output is correct |
7 |
Correct |
11 ms |
23796 KB |
Output is correct |
8 |
Correct |
15 ms |
23764 KB |
Output is correct |
9 |
Correct |
11 ms |
23764 KB |
Output is correct |
10 |
Correct |
12 ms |
23820 KB |
Output is correct |
11 |
Correct |
20 ms |
23912 KB |
Output is correct |
12 |
Correct |
19 ms |
24080 KB |
Output is correct |
13 |
Correct |
17 ms |
24064 KB |
Output is correct |
14 |
Correct |
27 ms |
24212 KB |
Output is correct |
15 |
Correct |
21 ms |
24148 KB |
Output is correct |
16 |
Correct |
22 ms |
24080 KB |
Output is correct |
17 |
Correct |
18 ms |
24088 KB |
Output is correct |
18 |
Correct |
21 ms |
24136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2391 ms |
67544 KB |
Output is correct |
2 |
Correct |
2493 ms |
67736 KB |
Output is correct |
3 |
Correct |
2669 ms |
67636 KB |
Output is correct |
4 |
Correct |
2383 ms |
67576 KB |
Output is correct |
5 |
Correct |
2159 ms |
63320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
240 ms |
29648 KB |
Output is correct |
2 |
Correct |
212 ms |
28392 KB |
Output is correct |
3 |
Correct |
204 ms |
27824 KB |
Output is correct |
4 |
Correct |
210 ms |
27980 KB |
Output is correct |
5 |
Correct |
184 ms |
28068 KB |
Output is correct |
6 |
Correct |
187 ms |
26720 KB |
Output is correct |
7 |
Correct |
208 ms |
26648 KB |
Output is correct |
8 |
Correct |
189 ms |
28132 KB |
Output is correct |
9 |
Correct |
191 ms |
26636 KB |
Output is correct |
10 |
Correct |
171 ms |
28304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
23820 KB |
Output is correct |
2 |
Correct |
11 ms |
23816 KB |
Output is correct |
3 |
Correct |
15 ms |
23880 KB |
Output is correct |
4 |
Correct |
11 ms |
23856 KB |
Output is correct |
5 |
Correct |
11 ms |
23812 KB |
Output is correct |
6 |
Correct |
12 ms |
23852 KB |
Output is correct |
7 |
Correct |
11 ms |
23796 KB |
Output is correct |
8 |
Correct |
15 ms |
23764 KB |
Output is correct |
9 |
Correct |
11 ms |
23764 KB |
Output is correct |
10 |
Correct |
12 ms |
23820 KB |
Output is correct |
11 |
Correct |
20 ms |
23912 KB |
Output is correct |
12 |
Correct |
19 ms |
24080 KB |
Output is correct |
13 |
Correct |
17 ms |
24064 KB |
Output is correct |
14 |
Correct |
27 ms |
24212 KB |
Output is correct |
15 |
Correct |
21 ms |
24148 KB |
Output is correct |
16 |
Correct |
22 ms |
24080 KB |
Output is correct |
17 |
Correct |
18 ms |
24088 KB |
Output is correct |
18 |
Correct |
21 ms |
24136 KB |
Output is correct |
19 |
Correct |
373 ms |
35000 KB |
Output is correct |
20 |
Correct |
439 ms |
35132 KB |
Output is correct |
21 |
Correct |
442 ms |
33824 KB |
Output is correct |
22 |
Correct |
450 ms |
33664 KB |
Output is correct |
23 |
Correct |
371 ms |
33696 KB |
Output is correct |
24 |
Correct |
325 ms |
31544 KB |
Output is correct |
25 |
Correct |
407 ms |
31320 KB |
Output is correct |
26 |
Correct |
402 ms |
31972 KB |
Output is correct |
27 |
Correct |
402 ms |
31948 KB |
Output is correct |
28 |
Correct |
353 ms |
32232 KB |
Output is correct |
29 |
Correct |
345 ms |
32972 KB |
Output is correct |
30 |
Correct |
417 ms |
33124 KB |
Output is correct |
31 |
Correct |
406 ms |
32844 KB |
Output is correct |
32 |
Correct |
393 ms |
32700 KB |
Output is correct |
33 |
Correct |
347 ms |
32556 KB |
Output is correct |
34 |
Correct |
348 ms |
30560 KB |
Output is correct |
35 |
Correct |
305 ms |
30596 KB |
Output is correct |
36 |
Correct |
397 ms |
30600 KB |
Output is correct |
37 |
Correct |
402 ms |
30268 KB |
Output is correct |
38 |
Correct |
351 ms |
30364 KB |
Output is correct |
39 |
Correct |
397 ms |
32676 KB |
Output is correct |
40 |
Correct |
333 ms |
31912 KB |
Output is correct |
41 |
Correct |
403 ms |
32552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
23820 KB |
Output is correct |
2 |
Correct |
11 ms |
23816 KB |
Output is correct |
3 |
Correct |
15 ms |
23880 KB |
Output is correct |
4 |
Correct |
11 ms |
23856 KB |
Output is correct |
5 |
Correct |
11 ms |
23812 KB |
Output is correct |
6 |
Correct |
12 ms |
23852 KB |
Output is correct |
7 |
Correct |
11 ms |
23796 KB |
Output is correct |
8 |
Correct |
15 ms |
23764 KB |
Output is correct |
9 |
Correct |
11 ms |
23764 KB |
Output is correct |
10 |
Correct |
12 ms |
23820 KB |
Output is correct |
11 |
Correct |
20 ms |
23912 KB |
Output is correct |
12 |
Correct |
19 ms |
24080 KB |
Output is correct |
13 |
Correct |
17 ms |
24064 KB |
Output is correct |
14 |
Correct |
27 ms |
24212 KB |
Output is correct |
15 |
Correct |
21 ms |
24148 KB |
Output is correct |
16 |
Correct |
22 ms |
24080 KB |
Output is correct |
17 |
Correct |
18 ms |
24088 KB |
Output is correct |
18 |
Correct |
21 ms |
24136 KB |
Output is correct |
19 |
Correct |
2391 ms |
67544 KB |
Output is correct |
20 |
Correct |
2493 ms |
67736 KB |
Output is correct |
21 |
Correct |
2669 ms |
67636 KB |
Output is correct |
22 |
Correct |
2383 ms |
67576 KB |
Output is correct |
23 |
Correct |
2159 ms |
63320 KB |
Output is correct |
24 |
Correct |
240 ms |
29648 KB |
Output is correct |
25 |
Correct |
212 ms |
28392 KB |
Output is correct |
26 |
Correct |
204 ms |
27824 KB |
Output is correct |
27 |
Correct |
210 ms |
27980 KB |
Output is correct |
28 |
Correct |
184 ms |
28068 KB |
Output is correct |
29 |
Correct |
187 ms |
26720 KB |
Output is correct |
30 |
Correct |
208 ms |
26648 KB |
Output is correct |
31 |
Correct |
189 ms |
28132 KB |
Output is correct |
32 |
Correct |
191 ms |
26636 KB |
Output is correct |
33 |
Correct |
171 ms |
28304 KB |
Output is correct |
34 |
Correct |
373 ms |
35000 KB |
Output is correct |
35 |
Correct |
439 ms |
35132 KB |
Output is correct |
36 |
Correct |
442 ms |
33824 KB |
Output is correct |
37 |
Correct |
450 ms |
33664 KB |
Output is correct |
38 |
Correct |
371 ms |
33696 KB |
Output is correct |
39 |
Correct |
325 ms |
31544 KB |
Output is correct |
40 |
Correct |
407 ms |
31320 KB |
Output is correct |
41 |
Correct |
402 ms |
31972 KB |
Output is correct |
42 |
Correct |
402 ms |
31948 KB |
Output is correct |
43 |
Correct |
353 ms |
32232 KB |
Output is correct |
44 |
Correct |
345 ms |
32972 KB |
Output is correct |
45 |
Correct |
417 ms |
33124 KB |
Output is correct |
46 |
Correct |
406 ms |
32844 KB |
Output is correct |
47 |
Correct |
393 ms |
32700 KB |
Output is correct |
48 |
Correct |
347 ms |
32556 KB |
Output is correct |
49 |
Correct |
348 ms |
30560 KB |
Output is correct |
50 |
Correct |
305 ms |
30596 KB |
Output is correct |
51 |
Correct |
397 ms |
30600 KB |
Output is correct |
52 |
Correct |
402 ms |
30268 KB |
Output is correct |
53 |
Correct |
351 ms |
30364 KB |
Output is correct |
54 |
Correct |
397 ms |
32676 KB |
Output is correct |
55 |
Correct |
333 ms |
31912 KB |
Output is correct |
56 |
Correct |
403 ms |
32552 KB |
Output is correct |
57 |
Correct |
2580 ms |
70148 KB |
Output is correct |
58 |
Correct |
2340 ms |
70008 KB |
Output is correct |
59 |
Correct |
2322 ms |
65940 KB |
Output is correct |
60 |
Correct |
2263 ms |
65956 KB |
Output is correct |
61 |
Correct |
2273 ms |
65888 KB |
Output is correct |
62 |
Correct |
2117 ms |
65828 KB |
Output is correct |
63 |
Correct |
1639 ms |
51644 KB |
Output is correct |
64 |
Correct |
2000 ms |
51680 KB |
Output is correct |
65 |
Correct |
2176 ms |
57168 KB |
Output is correct |
66 |
Correct |
2105 ms |
57212 KB |
Output is correct |
67 |
Correct |
2025 ms |
57612 KB |
Output is correct |
68 |
Correct |
2332 ms |
61840 KB |
Output is correct |
69 |
Correct |
2005 ms |
62272 KB |
Output is correct |
70 |
Correct |
2194 ms |
61148 KB |
Output is correct |
71 |
Correct |
2189 ms |
60864 KB |
Output is correct |
72 |
Correct |
2110 ms |
60844 KB |
Output is correct |
73 |
Correct |
1790 ms |
51272 KB |
Output is correct |
74 |
Correct |
1660 ms |
51260 KB |
Output is correct |
75 |
Correct |
1699 ms |
51144 KB |
Output is correct |
76 |
Correct |
1655 ms |
51268 KB |
Output is correct |
77 |
Correct |
1564 ms |
51248 KB |
Output is correct |
78 |
Correct |
1870 ms |
62512 KB |
Output is correct |
79 |
Correct |
1532 ms |
55788 KB |
Output is correct |
80 |
Correct |
1835 ms |
60368 KB |
Output is correct |