#include <bits/stdc++.h>
using namespace std;
const int N = 1e6+5;
const int Q = N;
int n, q, a[N], bit[N];
vector<int> qs[N];
bitset<N> ans;
struct evan {
int l, r, k;
} query[Q];
void upd(int i, int x){
while(i>0){
bit[i] = max(bit[i], x);
i -= i&-i;
}
}
int qry(int i){
int r = 0;
while(i<=n){
r = max(r, bit[i]);
i += i&-i;
}
return r;
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> n >> q;
a[0] = int(1e9)+1;
for(int i = 1; i <= n; ++i)
cin >> a[i];
for(int i = 0; i < q; ++i){
cin >> query[i].l >> query[i].r >> query[i].k;
qs[query[i].r].push_back(i);
}
vector<int> st{0};
for(int i = 1; i <= n; ++i){
while(a[st.back()]<=a[i])
st.pop_back();
upd(st.back(), a[i]+a[st.back()]);
st.push_back(i);
for(int j: qs[i])
ans[j] = qry(query[j].l) <= query[j].k;
}
for(int i = 0; i < q; ++i)
cout << ans[i] << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23820 KB |
Output is correct |
2 |
Correct |
15 ms |
23816 KB |
Output is correct |
3 |
Correct |
13 ms |
23800 KB |
Output is correct |
4 |
Correct |
14 ms |
23824 KB |
Output is correct |
5 |
Correct |
13 ms |
23764 KB |
Output is correct |
6 |
Correct |
13 ms |
23828 KB |
Output is correct |
7 |
Correct |
15 ms |
23764 KB |
Output is correct |
8 |
Correct |
13 ms |
23824 KB |
Output is correct |
9 |
Correct |
14 ms |
23764 KB |
Output is correct |
10 |
Correct |
15 ms |
23844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23820 KB |
Output is correct |
2 |
Correct |
15 ms |
23816 KB |
Output is correct |
3 |
Correct |
13 ms |
23800 KB |
Output is correct |
4 |
Correct |
14 ms |
23824 KB |
Output is correct |
5 |
Correct |
13 ms |
23764 KB |
Output is correct |
6 |
Correct |
13 ms |
23828 KB |
Output is correct |
7 |
Correct |
15 ms |
23764 KB |
Output is correct |
8 |
Correct |
13 ms |
23824 KB |
Output is correct |
9 |
Correct |
14 ms |
23764 KB |
Output is correct |
10 |
Correct |
15 ms |
23844 KB |
Output is correct |
11 |
Correct |
18 ms |
23952 KB |
Output is correct |
12 |
Correct |
23 ms |
24040 KB |
Output is correct |
13 |
Correct |
20 ms |
24020 KB |
Output is correct |
14 |
Correct |
20 ms |
24148 KB |
Output is correct |
15 |
Correct |
23 ms |
24084 KB |
Output is correct |
16 |
Correct |
20 ms |
24120 KB |
Output is correct |
17 |
Correct |
21 ms |
24100 KB |
Output is correct |
18 |
Correct |
20 ms |
24040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1995 ms |
95200 KB |
Output is correct |
2 |
Correct |
2007 ms |
96276 KB |
Output is correct |
3 |
Correct |
2070 ms |
96088 KB |
Output is correct |
4 |
Correct |
2017 ms |
96196 KB |
Output is correct |
5 |
Correct |
1972 ms |
92404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
166 ms |
29512 KB |
Output is correct |
2 |
Correct |
169 ms |
28704 KB |
Output is correct |
3 |
Correct |
186 ms |
28876 KB |
Output is correct |
4 |
Correct |
163 ms |
29104 KB |
Output is correct |
5 |
Correct |
166 ms |
29100 KB |
Output is correct |
6 |
Correct |
173 ms |
28032 KB |
Output is correct |
7 |
Correct |
163 ms |
27960 KB |
Output is correct |
8 |
Correct |
163 ms |
28804 KB |
Output is correct |
9 |
Correct |
151 ms |
27024 KB |
Output is correct |
10 |
Correct |
164 ms |
28796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23820 KB |
Output is correct |
2 |
Correct |
15 ms |
23816 KB |
Output is correct |
3 |
Correct |
13 ms |
23800 KB |
Output is correct |
4 |
Correct |
14 ms |
23824 KB |
Output is correct |
5 |
Correct |
13 ms |
23764 KB |
Output is correct |
6 |
Correct |
13 ms |
23828 KB |
Output is correct |
7 |
Correct |
15 ms |
23764 KB |
Output is correct |
8 |
Correct |
13 ms |
23824 KB |
Output is correct |
9 |
Correct |
14 ms |
23764 KB |
Output is correct |
10 |
Correct |
15 ms |
23844 KB |
Output is correct |
11 |
Correct |
18 ms |
23952 KB |
Output is correct |
12 |
Correct |
23 ms |
24040 KB |
Output is correct |
13 |
Correct |
20 ms |
24020 KB |
Output is correct |
14 |
Correct |
20 ms |
24148 KB |
Output is correct |
15 |
Correct |
23 ms |
24084 KB |
Output is correct |
16 |
Correct |
20 ms |
24120 KB |
Output is correct |
17 |
Correct |
21 ms |
24100 KB |
Output is correct |
18 |
Correct |
20 ms |
24040 KB |
Output is correct |
19 |
Correct |
391 ms |
37932 KB |
Output is correct |
20 |
Correct |
363 ms |
38016 KB |
Output is correct |
21 |
Correct |
363 ms |
36108 KB |
Output is correct |
22 |
Correct |
355 ms |
36016 KB |
Output is correct |
23 |
Correct |
333 ms |
36052 KB |
Output is correct |
24 |
Correct |
333 ms |
35056 KB |
Output is correct |
25 |
Correct |
321 ms |
35052 KB |
Output is correct |
26 |
Correct |
345 ms |
35948 KB |
Output is correct |
27 |
Correct |
342 ms |
35840 KB |
Output is correct |
28 |
Correct |
347 ms |
36356 KB |
Output is correct |
29 |
Correct |
364 ms |
37208 KB |
Output is correct |
30 |
Correct |
354 ms |
37188 KB |
Output is correct |
31 |
Correct |
414 ms |
37180 KB |
Output is correct |
32 |
Correct |
351 ms |
37120 KB |
Output is correct |
33 |
Correct |
352 ms |
37096 KB |
Output is correct |
34 |
Correct |
320 ms |
34740 KB |
Output is correct |
35 |
Correct |
332 ms |
34736 KB |
Output is correct |
36 |
Correct |
337 ms |
34548 KB |
Output is correct |
37 |
Correct |
312 ms |
34492 KB |
Output is correct |
38 |
Correct |
318 ms |
34668 KB |
Output is correct |
39 |
Correct |
335 ms |
35652 KB |
Output is correct |
40 |
Correct |
313 ms |
34180 KB |
Output is correct |
41 |
Correct |
360 ms |
35144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23820 KB |
Output is correct |
2 |
Correct |
15 ms |
23816 KB |
Output is correct |
3 |
Correct |
13 ms |
23800 KB |
Output is correct |
4 |
Correct |
14 ms |
23824 KB |
Output is correct |
5 |
Correct |
13 ms |
23764 KB |
Output is correct |
6 |
Correct |
13 ms |
23828 KB |
Output is correct |
7 |
Correct |
15 ms |
23764 KB |
Output is correct |
8 |
Correct |
13 ms |
23824 KB |
Output is correct |
9 |
Correct |
14 ms |
23764 KB |
Output is correct |
10 |
Correct |
15 ms |
23844 KB |
Output is correct |
11 |
Correct |
18 ms |
23952 KB |
Output is correct |
12 |
Correct |
23 ms |
24040 KB |
Output is correct |
13 |
Correct |
20 ms |
24020 KB |
Output is correct |
14 |
Correct |
20 ms |
24148 KB |
Output is correct |
15 |
Correct |
23 ms |
24084 KB |
Output is correct |
16 |
Correct |
20 ms |
24120 KB |
Output is correct |
17 |
Correct |
21 ms |
24100 KB |
Output is correct |
18 |
Correct |
20 ms |
24040 KB |
Output is correct |
19 |
Correct |
1995 ms |
95200 KB |
Output is correct |
20 |
Correct |
2007 ms |
96276 KB |
Output is correct |
21 |
Correct |
2070 ms |
96088 KB |
Output is correct |
22 |
Correct |
2017 ms |
96196 KB |
Output is correct |
23 |
Correct |
1972 ms |
92404 KB |
Output is correct |
24 |
Correct |
166 ms |
29512 KB |
Output is correct |
25 |
Correct |
169 ms |
28704 KB |
Output is correct |
26 |
Correct |
186 ms |
28876 KB |
Output is correct |
27 |
Correct |
163 ms |
29104 KB |
Output is correct |
28 |
Correct |
166 ms |
29100 KB |
Output is correct |
29 |
Correct |
173 ms |
28032 KB |
Output is correct |
30 |
Correct |
163 ms |
27960 KB |
Output is correct |
31 |
Correct |
163 ms |
28804 KB |
Output is correct |
32 |
Correct |
151 ms |
27024 KB |
Output is correct |
33 |
Correct |
164 ms |
28796 KB |
Output is correct |
34 |
Correct |
391 ms |
37932 KB |
Output is correct |
35 |
Correct |
363 ms |
38016 KB |
Output is correct |
36 |
Correct |
363 ms |
36108 KB |
Output is correct |
37 |
Correct |
355 ms |
36016 KB |
Output is correct |
38 |
Correct |
333 ms |
36052 KB |
Output is correct |
39 |
Correct |
333 ms |
35056 KB |
Output is correct |
40 |
Correct |
321 ms |
35052 KB |
Output is correct |
41 |
Correct |
345 ms |
35948 KB |
Output is correct |
42 |
Correct |
342 ms |
35840 KB |
Output is correct |
43 |
Correct |
347 ms |
36356 KB |
Output is correct |
44 |
Correct |
364 ms |
37208 KB |
Output is correct |
45 |
Correct |
354 ms |
37188 KB |
Output is correct |
46 |
Correct |
414 ms |
37180 KB |
Output is correct |
47 |
Correct |
351 ms |
37120 KB |
Output is correct |
48 |
Correct |
352 ms |
37096 KB |
Output is correct |
49 |
Correct |
320 ms |
34740 KB |
Output is correct |
50 |
Correct |
332 ms |
34736 KB |
Output is correct |
51 |
Correct |
337 ms |
34548 KB |
Output is correct |
52 |
Correct |
312 ms |
34492 KB |
Output is correct |
53 |
Correct |
318 ms |
34668 KB |
Output is correct |
54 |
Correct |
335 ms |
35652 KB |
Output is correct |
55 |
Correct |
313 ms |
34180 KB |
Output is correct |
56 |
Correct |
360 ms |
35144 KB |
Output is correct |
57 |
Correct |
2033 ms |
95224 KB |
Output is correct |
58 |
Correct |
2004 ms |
95180 KB |
Output is correct |
59 |
Correct |
1877 ms |
90940 KB |
Output is correct |
60 |
Correct |
1899 ms |
91120 KB |
Output is correct |
61 |
Correct |
1991 ms |
91080 KB |
Output is correct |
62 |
Correct |
1914 ms |
90968 KB |
Output is correct |
63 |
Correct |
1629 ms |
79484 KB |
Output is correct |
64 |
Correct |
1683 ms |
79496 KB |
Output is correct |
65 |
Correct |
1934 ms |
86564 KB |
Output is correct |
66 |
Correct |
2060 ms |
86500 KB |
Output is correct |
67 |
Correct |
2199 ms |
86912 KB |
Output is correct |
68 |
Correct |
2216 ms |
91408 KB |
Output is correct |
69 |
Correct |
1984 ms |
91208 KB |
Output is correct |
70 |
Correct |
1896 ms |
90524 KB |
Output is correct |
71 |
Correct |
1881 ms |
90652 KB |
Output is correct |
72 |
Correct |
1855 ms |
90564 KB |
Output is correct |
73 |
Correct |
1604 ms |
77524 KB |
Output is correct |
74 |
Correct |
1640 ms |
78524 KB |
Output is correct |
75 |
Correct |
1613 ms |
77752 KB |
Output is correct |
76 |
Correct |
1606 ms |
77672 KB |
Output is correct |
77 |
Correct |
1575 ms |
77320 KB |
Output is correct |
78 |
Correct |
1784 ms |
84800 KB |
Output is correct |
79 |
Correct |
1669 ms |
74304 KB |
Output is correct |
80 |
Correct |
1741 ms |
81148 KB |
Output is correct |