#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
using namespace std;
#define endl '\n'
#define pi pair<int, int>
struct segTree{
int l, r;
segTree *left, *right;
int val = 0;
segTree(int a, int b){
l = a;
r = b;
if(l != r){
int mid = (l + r) / 2;
left = new segTree(l, mid);
right = new segTree(mid + 1, r);
}
}
void add(int x, int v){
if(x < l || r < x) return;
if(l == r){
val = max(val, v);
return;
}
left->add(x, v);
right->add(x, v);
val = max(left->val, right->val);
}
int qry(int a, int b){
if(r < a || b < l) return 0;
if(a <= l && r <= b) return val;
return max(left->qry(a, b), right->qry(a, b));
}
};
const int maxn = 1000000;
int n, q;
int a[maxn], l[maxn], r[maxn], s[maxn];
vector<int> p[maxn], qry[maxn];
stack<int> stk;
int ans[maxn];
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> q;
for(int i = 0; i < n; i++){
cin >> a[i];
while(!stk.empty() && a[stk.top()] <= a[i]) stk.pop();
if(!stk.empty()) p[stk.top()].push_back(i);
stk.push(i);
}
for(int i = 0; i < q; i++){
cin >> l[i] >> r[i] >> s[i];
l[i]--, r[i]--;
qry[l[i]].push_back(i);
}
segTree tre(0, n);
for(int i = n - 1; i >= 0; i--){
for(int j : p[i]) tre.add(j, a[i] + a[j]);
for(int j : qry[i]) ans[j] = tre.qry(i, r[j]) <= s[j];
}
for(int i = 0; i < q; i++) cout << ans[i] << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
47356 KB |
Output is correct |
2 |
Correct |
31 ms |
47352 KB |
Output is correct |
3 |
Correct |
30 ms |
47352 KB |
Output is correct |
4 |
Correct |
31 ms |
47352 KB |
Output is correct |
5 |
Correct |
31 ms |
47352 KB |
Output is correct |
6 |
Correct |
31 ms |
47480 KB |
Output is correct |
7 |
Correct |
33 ms |
47352 KB |
Output is correct |
8 |
Correct |
32 ms |
47352 KB |
Output is correct |
9 |
Correct |
32 ms |
47352 KB |
Output is correct |
10 |
Correct |
32 ms |
47352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
47356 KB |
Output is correct |
2 |
Correct |
31 ms |
47352 KB |
Output is correct |
3 |
Correct |
30 ms |
47352 KB |
Output is correct |
4 |
Correct |
31 ms |
47352 KB |
Output is correct |
5 |
Correct |
31 ms |
47352 KB |
Output is correct |
6 |
Correct |
31 ms |
47480 KB |
Output is correct |
7 |
Correct |
33 ms |
47352 KB |
Output is correct |
8 |
Correct |
32 ms |
47352 KB |
Output is correct |
9 |
Correct |
32 ms |
47352 KB |
Output is correct |
10 |
Correct |
32 ms |
47352 KB |
Output is correct |
11 |
Correct |
32 ms |
47612 KB |
Output is correct |
12 |
Correct |
36 ms |
48120 KB |
Output is correct |
13 |
Correct |
37 ms |
48120 KB |
Output is correct |
14 |
Correct |
38 ms |
48248 KB |
Output is correct |
15 |
Correct |
37 ms |
48248 KB |
Output is correct |
16 |
Correct |
36 ms |
47992 KB |
Output is correct |
17 |
Correct |
36 ms |
47992 KB |
Output is correct |
18 |
Correct |
35 ms |
48120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2486 ms |
197544 KB |
Output is correct |
2 |
Correct |
2494 ms |
196988 KB |
Output is correct |
3 |
Correct |
2547 ms |
197112 KB |
Output is correct |
4 |
Correct |
2536 ms |
196932 KB |
Output is correct |
5 |
Correct |
2210 ms |
180728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
187 ms |
62968 KB |
Output is correct |
2 |
Correct |
149 ms |
63352 KB |
Output is correct |
3 |
Correct |
150 ms |
62584 KB |
Output is correct |
4 |
Correct |
161 ms |
62840 KB |
Output is correct |
5 |
Correct |
157 ms |
62840 KB |
Output is correct |
6 |
Correct |
111 ms |
61304 KB |
Output is correct |
7 |
Correct |
117 ms |
61304 KB |
Output is correct |
8 |
Correct |
144 ms |
62068 KB |
Output is correct |
9 |
Correct |
79 ms |
50932 KB |
Output is correct |
10 |
Correct |
144 ms |
62068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
47356 KB |
Output is correct |
2 |
Correct |
31 ms |
47352 KB |
Output is correct |
3 |
Correct |
30 ms |
47352 KB |
Output is correct |
4 |
Correct |
31 ms |
47352 KB |
Output is correct |
5 |
Correct |
31 ms |
47352 KB |
Output is correct |
6 |
Correct |
31 ms |
47480 KB |
Output is correct |
7 |
Correct |
33 ms |
47352 KB |
Output is correct |
8 |
Correct |
32 ms |
47352 KB |
Output is correct |
9 |
Correct |
32 ms |
47352 KB |
Output is correct |
10 |
Correct |
32 ms |
47352 KB |
Output is correct |
11 |
Correct |
32 ms |
47612 KB |
Output is correct |
12 |
Correct |
36 ms |
48120 KB |
Output is correct |
13 |
Correct |
37 ms |
48120 KB |
Output is correct |
14 |
Correct |
38 ms |
48248 KB |
Output is correct |
15 |
Correct |
37 ms |
48248 KB |
Output is correct |
16 |
Correct |
36 ms |
47992 KB |
Output is correct |
17 |
Correct |
36 ms |
47992 KB |
Output is correct |
18 |
Correct |
35 ms |
48120 KB |
Output is correct |
19 |
Correct |
415 ms |
83192 KB |
Output is correct |
20 |
Correct |
417 ms |
84256 KB |
Output is correct |
21 |
Correct |
302 ms |
81656 KB |
Output is correct |
22 |
Correct |
294 ms |
81528 KB |
Output is correct |
23 |
Correct |
297 ms |
81528 KB |
Output is correct |
24 |
Correct |
232 ms |
78072 KB |
Output is correct |
25 |
Correct |
234 ms |
78072 KB |
Output is correct |
26 |
Correct |
294 ms |
79224 KB |
Output is correct |
27 |
Correct |
287 ms |
79224 KB |
Output is correct |
28 |
Correct |
314 ms |
79808 KB |
Output is correct |
29 |
Correct |
355 ms |
81016 KB |
Output is correct |
30 |
Correct |
342 ms |
81020 KB |
Output is correct |
31 |
Correct |
360 ms |
80888 KB |
Output is correct |
32 |
Correct |
350 ms |
80888 KB |
Output is correct |
33 |
Correct |
352 ms |
80888 KB |
Output is correct |
34 |
Correct |
220 ms |
77688 KB |
Output is correct |
35 |
Correct |
213 ms |
77688 KB |
Output is correct |
36 |
Correct |
212 ms |
77560 KB |
Output is correct |
37 |
Correct |
215 ms |
77432 KB |
Output is correct |
38 |
Correct |
218 ms |
77688 KB |
Output is correct |
39 |
Correct |
302 ms |
79220 KB |
Output is correct |
40 |
Correct |
247 ms |
70512 KB |
Output is correct |
41 |
Correct |
307 ms |
78196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
47356 KB |
Output is correct |
2 |
Correct |
31 ms |
47352 KB |
Output is correct |
3 |
Correct |
30 ms |
47352 KB |
Output is correct |
4 |
Correct |
31 ms |
47352 KB |
Output is correct |
5 |
Correct |
31 ms |
47352 KB |
Output is correct |
6 |
Correct |
31 ms |
47480 KB |
Output is correct |
7 |
Correct |
33 ms |
47352 KB |
Output is correct |
8 |
Correct |
32 ms |
47352 KB |
Output is correct |
9 |
Correct |
32 ms |
47352 KB |
Output is correct |
10 |
Correct |
32 ms |
47352 KB |
Output is correct |
11 |
Correct |
32 ms |
47612 KB |
Output is correct |
12 |
Correct |
36 ms |
48120 KB |
Output is correct |
13 |
Correct |
37 ms |
48120 KB |
Output is correct |
14 |
Correct |
38 ms |
48248 KB |
Output is correct |
15 |
Correct |
37 ms |
48248 KB |
Output is correct |
16 |
Correct |
36 ms |
47992 KB |
Output is correct |
17 |
Correct |
36 ms |
47992 KB |
Output is correct |
18 |
Correct |
35 ms |
48120 KB |
Output is correct |
19 |
Correct |
2486 ms |
197544 KB |
Output is correct |
20 |
Correct |
2494 ms |
196988 KB |
Output is correct |
21 |
Correct |
2547 ms |
197112 KB |
Output is correct |
22 |
Correct |
2536 ms |
196932 KB |
Output is correct |
23 |
Correct |
2210 ms |
180728 KB |
Output is correct |
24 |
Correct |
187 ms |
62968 KB |
Output is correct |
25 |
Correct |
149 ms |
63352 KB |
Output is correct |
26 |
Correct |
150 ms |
62584 KB |
Output is correct |
27 |
Correct |
161 ms |
62840 KB |
Output is correct |
28 |
Correct |
157 ms |
62840 KB |
Output is correct |
29 |
Correct |
111 ms |
61304 KB |
Output is correct |
30 |
Correct |
117 ms |
61304 KB |
Output is correct |
31 |
Correct |
144 ms |
62068 KB |
Output is correct |
32 |
Correct |
79 ms |
50932 KB |
Output is correct |
33 |
Correct |
144 ms |
62068 KB |
Output is correct |
34 |
Correct |
415 ms |
83192 KB |
Output is correct |
35 |
Correct |
417 ms |
84256 KB |
Output is correct |
36 |
Correct |
302 ms |
81656 KB |
Output is correct |
37 |
Correct |
294 ms |
81528 KB |
Output is correct |
38 |
Correct |
297 ms |
81528 KB |
Output is correct |
39 |
Correct |
232 ms |
78072 KB |
Output is correct |
40 |
Correct |
234 ms |
78072 KB |
Output is correct |
41 |
Correct |
294 ms |
79224 KB |
Output is correct |
42 |
Correct |
287 ms |
79224 KB |
Output is correct |
43 |
Correct |
314 ms |
79808 KB |
Output is correct |
44 |
Correct |
355 ms |
81016 KB |
Output is correct |
45 |
Correct |
342 ms |
81020 KB |
Output is correct |
46 |
Correct |
360 ms |
80888 KB |
Output is correct |
47 |
Correct |
350 ms |
80888 KB |
Output is correct |
48 |
Correct |
352 ms |
80888 KB |
Output is correct |
49 |
Correct |
220 ms |
77688 KB |
Output is correct |
50 |
Correct |
213 ms |
77688 KB |
Output is correct |
51 |
Correct |
212 ms |
77560 KB |
Output is correct |
52 |
Correct |
215 ms |
77432 KB |
Output is correct |
53 |
Correct |
218 ms |
77688 KB |
Output is correct |
54 |
Correct |
302 ms |
79220 KB |
Output is correct |
55 |
Correct |
247 ms |
70512 KB |
Output is correct |
56 |
Correct |
307 ms |
78196 KB |
Output is correct |
57 |
Correct |
2498 ms |
232392 KB |
Output is correct |
58 |
Correct |
2453 ms |
232452 KB |
Output is correct |
59 |
Correct |
2307 ms |
226740 KB |
Output is correct |
60 |
Correct |
2255 ms |
226792 KB |
Output is correct |
61 |
Correct |
2317 ms |
226792 KB |
Output is correct |
62 |
Correct |
2353 ms |
226744 KB |
Output is correct |
63 |
Correct |
1136 ms |
199672 KB |
Output is correct |
64 |
Correct |
1117 ms |
199664 KB |
Output is correct |
65 |
Correct |
1973 ms |
209656 KB |
Output is correct |
66 |
Correct |
1933 ms |
209640 KB |
Output is correct |
67 |
Correct |
1978 ms |
210272 KB |
Output is correct |
68 |
Correct |
2154 ms |
216160 KB |
Output is correct |
69 |
Correct |
2193 ms |
216160 KB |
Output is correct |
70 |
Correct |
2121 ms |
215288 KB |
Output is correct |
71 |
Correct |
2100 ms |
215400 KB |
Output is correct |
72 |
Correct |
2155 ms |
215392 KB |
Output is correct |
73 |
Correct |
1030 ms |
197872 KB |
Output is correct |
74 |
Correct |
1079 ms |
198764 KB |
Output is correct |
75 |
Correct |
1018 ms |
197892 KB |
Output is correct |
76 |
Correct |
1061 ms |
197752 KB |
Output is correct |
77 |
Correct |
1079 ms |
197936 KB |
Output is correct |
78 |
Correct |
1889 ms |
208068 KB |
Output is correct |
79 |
Correct |
1377 ms |
149740 KB |
Output is correct |
80 |
Correct |
1857 ms |
202928 KB |
Output is correct |