#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
#define int ll
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 |
23764 KB |
Output is correct |
2 |
Correct |
11 ms |
23764 KB |
Output is correct |
3 |
Correct |
12 ms |
23816 KB |
Output is correct |
4 |
Correct |
12 ms |
23764 KB |
Output is correct |
5 |
Correct |
12 ms |
23840 KB |
Output is correct |
6 |
Correct |
12 ms |
23828 KB |
Output is correct |
7 |
Correct |
17 ms |
23892 KB |
Output is correct |
8 |
Correct |
17 ms |
23884 KB |
Output is correct |
9 |
Correct |
17 ms |
23828 KB |
Output is correct |
10 |
Correct |
15 ms |
23784 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
23764 KB |
Output is correct |
2 |
Correct |
11 ms |
23764 KB |
Output is correct |
3 |
Correct |
12 ms |
23816 KB |
Output is correct |
4 |
Correct |
12 ms |
23764 KB |
Output is correct |
5 |
Correct |
12 ms |
23840 KB |
Output is correct |
6 |
Correct |
12 ms |
23828 KB |
Output is correct |
7 |
Correct |
17 ms |
23892 KB |
Output is correct |
8 |
Correct |
17 ms |
23884 KB |
Output is correct |
9 |
Correct |
17 ms |
23828 KB |
Output is correct |
10 |
Correct |
15 ms |
23784 KB |
Output is correct |
11 |
Correct |
14 ms |
24020 KB |
Output is correct |
12 |
Correct |
22 ms |
24208 KB |
Output is correct |
13 |
Correct |
20 ms |
24240 KB |
Output is correct |
14 |
Correct |
26 ms |
24324 KB |
Output is correct |
15 |
Correct |
26 ms |
24408 KB |
Output is correct |
16 |
Correct |
17 ms |
24260 KB |
Output is correct |
17 |
Correct |
17 ms |
24148 KB |
Output is correct |
18 |
Correct |
23 ms |
24148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2285 ms |
93396 KB |
Output is correct |
2 |
Correct |
2208 ms |
93412 KB |
Output is correct |
3 |
Correct |
2167 ms |
93356 KB |
Output is correct |
4 |
Correct |
2155 ms |
93364 KB |
Output is correct |
5 |
Correct |
2099 ms |
84712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
238 ms |
32372 KB |
Output is correct |
2 |
Correct |
226 ms |
33332 KB |
Output is correct |
3 |
Correct |
203 ms |
31620 KB |
Output is correct |
4 |
Correct |
194 ms |
31744 KB |
Output is correct |
5 |
Correct |
171 ms |
31756 KB |
Output is correct |
6 |
Correct |
208 ms |
30104 KB |
Output is correct |
7 |
Correct |
196 ms |
30156 KB |
Output is correct |
8 |
Correct |
202 ms |
31360 KB |
Output is correct |
9 |
Correct |
187 ms |
29400 KB |
Output is correct |
10 |
Correct |
205 ms |
31328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
23764 KB |
Output is correct |
2 |
Correct |
11 ms |
23764 KB |
Output is correct |
3 |
Correct |
12 ms |
23816 KB |
Output is correct |
4 |
Correct |
12 ms |
23764 KB |
Output is correct |
5 |
Correct |
12 ms |
23840 KB |
Output is correct |
6 |
Correct |
12 ms |
23828 KB |
Output is correct |
7 |
Correct |
17 ms |
23892 KB |
Output is correct |
8 |
Correct |
17 ms |
23884 KB |
Output is correct |
9 |
Correct |
17 ms |
23828 KB |
Output is correct |
10 |
Correct |
15 ms |
23784 KB |
Output is correct |
11 |
Correct |
14 ms |
24020 KB |
Output is correct |
12 |
Correct |
22 ms |
24208 KB |
Output is correct |
13 |
Correct |
20 ms |
24240 KB |
Output is correct |
14 |
Correct |
26 ms |
24324 KB |
Output is correct |
15 |
Correct |
26 ms |
24408 KB |
Output is correct |
16 |
Correct |
17 ms |
24260 KB |
Output is correct |
17 |
Correct |
17 ms |
24148 KB |
Output is correct |
18 |
Correct |
23 ms |
24148 KB |
Output is correct |
19 |
Correct |
405 ms |
42724 KB |
Output is correct |
20 |
Correct |
373 ms |
42672 KB |
Output is correct |
21 |
Correct |
443 ms |
41548 KB |
Output is correct |
22 |
Correct |
438 ms |
41576 KB |
Output is correct |
23 |
Correct |
369 ms |
41608 KB |
Output is correct |
24 |
Correct |
363 ms |
37304 KB |
Output is correct |
25 |
Correct |
348 ms |
37584 KB |
Output is correct |
26 |
Correct |
403 ms |
38120 KB |
Output is correct |
27 |
Correct |
400 ms |
38184 KB |
Output is correct |
28 |
Correct |
362 ms |
38276 KB |
Output is correct |
29 |
Correct |
385 ms |
39080 KB |
Output is correct |
30 |
Correct |
431 ms |
39048 KB |
Output is correct |
31 |
Correct |
456 ms |
39072 KB |
Output is correct |
32 |
Correct |
342 ms |
39020 KB |
Output is correct |
33 |
Correct |
427 ms |
39108 KB |
Output is correct |
34 |
Correct |
456 ms |
37756 KB |
Output is correct |
35 |
Correct |
392 ms |
37712 KB |
Output is correct |
36 |
Correct |
396 ms |
37816 KB |
Output is correct |
37 |
Correct |
377 ms |
37912 KB |
Output is correct |
38 |
Correct |
385 ms |
37848 KB |
Output is correct |
39 |
Correct |
411 ms |
40452 KB |
Output is correct |
40 |
Correct |
383 ms |
38152 KB |
Output is correct |
41 |
Correct |
344 ms |
39320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
23764 KB |
Output is correct |
2 |
Correct |
11 ms |
23764 KB |
Output is correct |
3 |
Correct |
12 ms |
23816 KB |
Output is correct |
4 |
Correct |
12 ms |
23764 KB |
Output is correct |
5 |
Correct |
12 ms |
23840 KB |
Output is correct |
6 |
Correct |
12 ms |
23828 KB |
Output is correct |
7 |
Correct |
17 ms |
23892 KB |
Output is correct |
8 |
Correct |
17 ms |
23884 KB |
Output is correct |
9 |
Correct |
17 ms |
23828 KB |
Output is correct |
10 |
Correct |
15 ms |
23784 KB |
Output is correct |
11 |
Correct |
14 ms |
24020 KB |
Output is correct |
12 |
Correct |
22 ms |
24208 KB |
Output is correct |
13 |
Correct |
20 ms |
24240 KB |
Output is correct |
14 |
Correct |
26 ms |
24324 KB |
Output is correct |
15 |
Correct |
26 ms |
24408 KB |
Output is correct |
16 |
Correct |
17 ms |
24260 KB |
Output is correct |
17 |
Correct |
17 ms |
24148 KB |
Output is correct |
18 |
Correct |
23 ms |
24148 KB |
Output is correct |
19 |
Correct |
2285 ms |
93396 KB |
Output is correct |
20 |
Correct |
2208 ms |
93412 KB |
Output is correct |
21 |
Correct |
2167 ms |
93356 KB |
Output is correct |
22 |
Correct |
2155 ms |
93364 KB |
Output is correct |
23 |
Correct |
2099 ms |
84712 KB |
Output is correct |
24 |
Correct |
238 ms |
32372 KB |
Output is correct |
25 |
Correct |
226 ms |
33332 KB |
Output is correct |
26 |
Correct |
203 ms |
31620 KB |
Output is correct |
27 |
Correct |
194 ms |
31744 KB |
Output is correct |
28 |
Correct |
171 ms |
31756 KB |
Output is correct |
29 |
Correct |
208 ms |
30104 KB |
Output is correct |
30 |
Correct |
196 ms |
30156 KB |
Output is correct |
31 |
Correct |
202 ms |
31360 KB |
Output is correct |
32 |
Correct |
187 ms |
29400 KB |
Output is correct |
33 |
Correct |
205 ms |
31328 KB |
Output is correct |
34 |
Correct |
405 ms |
42724 KB |
Output is correct |
35 |
Correct |
373 ms |
42672 KB |
Output is correct |
36 |
Correct |
443 ms |
41548 KB |
Output is correct |
37 |
Correct |
438 ms |
41576 KB |
Output is correct |
38 |
Correct |
369 ms |
41608 KB |
Output is correct |
39 |
Correct |
363 ms |
37304 KB |
Output is correct |
40 |
Correct |
348 ms |
37584 KB |
Output is correct |
41 |
Correct |
403 ms |
38120 KB |
Output is correct |
42 |
Correct |
400 ms |
38184 KB |
Output is correct |
43 |
Correct |
362 ms |
38276 KB |
Output is correct |
44 |
Correct |
385 ms |
39080 KB |
Output is correct |
45 |
Correct |
431 ms |
39048 KB |
Output is correct |
46 |
Correct |
456 ms |
39072 KB |
Output is correct |
47 |
Correct |
342 ms |
39020 KB |
Output is correct |
48 |
Correct |
427 ms |
39108 KB |
Output is correct |
49 |
Correct |
456 ms |
37756 KB |
Output is correct |
50 |
Correct |
392 ms |
37712 KB |
Output is correct |
51 |
Correct |
396 ms |
37816 KB |
Output is correct |
52 |
Correct |
377 ms |
37912 KB |
Output is correct |
53 |
Correct |
385 ms |
37848 KB |
Output is correct |
54 |
Correct |
411 ms |
40452 KB |
Output is correct |
55 |
Correct |
383 ms |
38152 KB |
Output is correct |
56 |
Correct |
344 ms |
39320 KB |
Output is correct |
57 |
Correct |
2573 ms |
100388 KB |
Output is correct |
58 |
Correct |
2566 ms |
100232 KB |
Output is correct |
59 |
Correct |
2507 ms |
97540 KB |
Output is correct |
60 |
Correct |
2403 ms |
97584 KB |
Output is correct |
61 |
Correct |
2441 ms |
97576 KB |
Output is correct |
62 |
Correct |
2508 ms |
97508 KB |
Output is correct |
63 |
Correct |
1785 ms |
77436 KB |
Output is correct |
64 |
Correct |
1932 ms |
77376 KB |
Output is correct |
65 |
Correct |
2223 ms |
80796 KB |
Output is correct |
66 |
Correct |
2101 ms |
80776 KB |
Output is correct |
67 |
Correct |
2062 ms |
80972 KB |
Output is correct |
68 |
Correct |
2148 ms |
83740 KB |
Output is correct |
69 |
Correct |
2413 ms |
84336 KB |
Output is correct |
70 |
Correct |
2323 ms |
83428 KB |
Output is correct |
71 |
Correct |
2349 ms |
86372 KB |
Output is correct |
72 |
Correct |
2175 ms |
87020 KB |
Output is correct |
73 |
Correct |
2031 ms |
79528 KB |
Output is correct |
74 |
Correct |
1701 ms |
79260 KB |
Output is correct |
75 |
Correct |
2005 ms |
79428 KB |
Output is correct |
76 |
Correct |
1934 ms |
79496 KB |
Output is correct |
77 |
Correct |
1811 ms |
79280 KB |
Output is correct |
78 |
Correct |
2176 ms |
90736 KB |
Output is correct |
79 |
Correct |
1705 ms |
78596 KB |
Output is correct |
80 |
Correct |
1967 ms |
84968 KB |
Output is correct |