#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] << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23832 KB |
Output is correct |
3 |
Correct |
12 ms |
23796 KB |
Output is correct |
4 |
Correct |
12 ms |
23828 KB |
Output is correct |
5 |
Correct |
12 ms |
23736 KB |
Output is correct |
6 |
Correct |
15 ms |
23820 KB |
Output is correct |
7 |
Correct |
12 ms |
23824 KB |
Output is correct |
8 |
Correct |
12 ms |
23788 KB |
Output is correct |
9 |
Correct |
12 ms |
23764 KB |
Output is correct |
10 |
Correct |
13 ms |
23772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23832 KB |
Output is correct |
3 |
Correct |
12 ms |
23796 KB |
Output is correct |
4 |
Correct |
12 ms |
23828 KB |
Output is correct |
5 |
Correct |
12 ms |
23736 KB |
Output is correct |
6 |
Correct |
15 ms |
23820 KB |
Output is correct |
7 |
Correct |
12 ms |
23824 KB |
Output is correct |
8 |
Correct |
12 ms |
23788 KB |
Output is correct |
9 |
Correct |
12 ms |
23764 KB |
Output is correct |
10 |
Correct |
13 ms |
23772 KB |
Output is correct |
11 |
Correct |
14 ms |
23892 KB |
Output is correct |
12 |
Correct |
14 ms |
24064 KB |
Output is correct |
13 |
Correct |
18 ms |
24020 KB |
Output is correct |
14 |
Correct |
15 ms |
24148 KB |
Output is correct |
15 |
Correct |
14 ms |
24184 KB |
Output is correct |
16 |
Correct |
15 ms |
24020 KB |
Output is correct |
17 |
Correct |
14 ms |
24020 KB |
Output is correct |
18 |
Correct |
14 ms |
24084 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1008 ms |
63840 KB |
Output is correct |
2 |
Correct |
919 ms |
63728 KB |
Output is correct |
3 |
Correct |
909 ms |
63844 KB |
Output is correct |
4 |
Correct |
981 ms |
63840 KB |
Output is correct |
5 |
Correct |
869 ms |
59796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
71 ms |
28020 KB |
Output is correct |
2 |
Correct |
85 ms |
28740 KB |
Output is correct |
3 |
Correct |
60 ms |
28928 KB |
Output is correct |
4 |
Correct |
72 ms |
29092 KB |
Output is correct |
5 |
Correct |
74 ms |
29252 KB |
Output is correct |
6 |
Correct |
53 ms |
27916 KB |
Output is correct |
7 |
Correct |
56 ms |
28012 KB |
Output is correct |
8 |
Correct |
67 ms |
28820 KB |
Output is correct |
9 |
Correct |
43 ms |
27068 KB |
Output is correct |
10 |
Correct |
62 ms |
28760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23832 KB |
Output is correct |
3 |
Correct |
12 ms |
23796 KB |
Output is correct |
4 |
Correct |
12 ms |
23828 KB |
Output is correct |
5 |
Correct |
12 ms |
23736 KB |
Output is correct |
6 |
Correct |
15 ms |
23820 KB |
Output is correct |
7 |
Correct |
12 ms |
23824 KB |
Output is correct |
8 |
Correct |
12 ms |
23788 KB |
Output is correct |
9 |
Correct |
12 ms |
23764 KB |
Output is correct |
10 |
Correct |
13 ms |
23772 KB |
Output is correct |
11 |
Correct |
14 ms |
23892 KB |
Output is correct |
12 |
Correct |
14 ms |
24064 KB |
Output is correct |
13 |
Correct |
18 ms |
24020 KB |
Output is correct |
14 |
Correct |
15 ms |
24148 KB |
Output is correct |
15 |
Correct |
14 ms |
24184 KB |
Output is correct |
16 |
Correct |
15 ms |
24020 KB |
Output is correct |
17 |
Correct |
14 ms |
24020 KB |
Output is correct |
18 |
Correct |
14 ms |
24084 KB |
Output is correct |
19 |
Correct |
202 ms |
34876 KB |
Output is correct |
20 |
Correct |
192 ms |
34776 KB |
Output is correct |
21 |
Correct |
125 ms |
33228 KB |
Output is correct |
22 |
Correct |
124 ms |
33104 KB |
Output is correct |
23 |
Correct |
124 ms |
33080 KB |
Output is correct |
24 |
Correct |
118 ms |
32136 KB |
Output is correct |
25 |
Correct |
127 ms |
32208 KB |
Output is correct |
26 |
Correct |
127 ms |
32940 KB |
Output is correct |
27 |
Correct |
124 ms |
32844 KB |
Output is correct |
28 |
Correct |
127 ms |
33152 KB |
Output is correct |
29 |
Correct |
134 ms |
34096 KB |
Output is correct |
30 |
Correct |
142 ms |
34076 KB |
Output is correct |
31 |
Correct |
145 ms |
34004 KB |
Output is correct |
32 |
Correct |
138 ms |
33916 KB |
Output is correct |
33 |
Correct |
139 ms |
33964 KB |
Output is correct |
34 |
Correct |
153 ms |
31904 KB |
Output is correct |
35 |
Correct |
111 ms |
31912 KB |
Output is correct |
36 |
Correct |
113 ms |
32460 KB |
Output is correct |
37 |
Correct |
110 ms |
32460 KB |
Output is correct |
38 |
Correct |
111 ms |
32016 KB |
Output is correct |
39 |
Correct |
126 ms |
34456 KB |
Output is correct |
40 |
Correct |
127 ms |
33628 KB |
Output is correct |
41 |
Correct |
167 ms |
34388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23832 KB |
Output is correct |
3 |
Correct |
12 ms |
23796 KB |
Output is correct |
4 |
Correct |
12 ms |
23828 KB |
Output is correct |
5 |
Correct |
12 ms |
23736 KB |
Output is correct |
6 |
Correct |
15 ms |
23820 KB |
Output is correct |
7 |
Correct |
12 ms |
23824 KB |
Output is correct |
8 |
Correct |
12 ms |
23788 KB |
Output is correct |
9 |
Correct |
12 ms |
23764 KB |
Output is correct |
10 |
Correct |
13 ms |
23772 KB |
Output is correct |
11 |
Correct |
14 ms |
23892 KB |
Output is correct |
12 |
Correct |
14 ms |
24064 KB |
Output is correct |
13 |
Correct |
18 ms |
24020 KB |
Output is correct |
14 |
Correct |
15 ms |
24148 KB |
Output is correct |
15 |
Correct |
14 ms |
24184 KB |
Output is correct |
16 |
Correct |
15 ms |
24020 KB |
Output is correct |
17 |
Correct |
14 ms |
24020 KB |
Output is correct |
18 |
Correct |
14 ms |
24084 KB |
Output is correct |
19 |
Correct |
1008 ms |
63840 KB |
Output is correct |
20 |
Correct |
919 ms |
63728 KB |
Output is correct |
21 |
Correct |
909 ms |
63844 KB |
Output is correct |
22 |
Correct |
981 ms |
63840 KB |
Output is correct |
23 |
Correct |
869 ms |
59796 KB |
Output is correct |
24 |
Correct |
71 ms |
28020 KB |
Output is correct |
25 |
Correct |
85 ms |
28740 KB |
Output is correct |
26 |
Correct |
60 ms |
28928 KB |
Output is correct |
27 |
Correct |
72 ms |
29092 KB |
Output is correct |
28 |
Correct |
74 ms |
29252 KB |
Output is correct |
29 |
Correct |
53 ms |
27916 KB |
Output is correct |
30 |
Correct |
56 ms |
28012 KB |
Output is correct |
31 |
Correct |
67 ms |
28820 KB |
Output is correct |
32 |
Correct |
43 ms |
27068 KB |
Output is correct |
33 |
Correct |
62 ms |
28760 KB |
Output is correct |
34 |
Correct |
202 ms |
34876 KB |
Output is correct |
35 |
Correct |
192 ms |
34776 KB |
Output is correct |
36 |
Correct |
125 ms |
33228 KB |
Output is correct |
37 |
Correct |
124 ms |
33104 KB |
Output is correct |
38 |
Correct |
124 ms |
33080 KB |
Output is correct |
39 |
Correct |
118 ms |
32136 KB |
Output is correct |
40 |
Correct |
127 ms |
32208 KB |
Output is correct |
41 |
Correct |
127 ms |
32940 KB |
Output is correct |
42 |
Correct |
124 ms |
32844 KB |
Output is correct |
43 |
Correct |
127 ms |
33152 KB |
Output is correct |
44 |
Correct |
134 ms |
34096 KB |
Output is correct |
45 |
Correct |
142 ms |
34076 KB |
Output is correct |
46 |
Correct |
145 ms |
34004 KB |
Output is correct |
47 |
Correct |
138 ms |
33916 KB |
Output is correct |
48 |
Correct |
139 ms |
33964 KB |
Output is correct |
49 |
Correct |
153 ms |
31904 KB |
Output is correct |
50 |
Correct |
111 ms |
31912 KB |
Output is correct |
51 |
Correct |
113 ms |
32460 KB |
Output is correct |
52 |
Correct |
110 ms |
32460 KB |
Output is correct |
53 |
Correct |
111 ms |
32016 KB |
Output is correct |
54 |
Correct |
126 ms |
34456 KB |
Output is correct |
55 |
Correct |
127 ms |
33628 KB |
Output is correct |
56 |
Correct |
167 ms |
34388 KB |
Output is correct |
57 |
Correct |
920 ms |
62360 KB |
Output is correct |
58 |
Correct |
950 ms |
62404 KB |
Output is correct |
59 |
Correct |
897 ms |
58032 KB |
Output is correct |
60 |
Correct |
849 ms |
57988 KB |
Output is correct |
61 |
Correct |
864 ms |
58032 KB |
Output is correct |
62 |
Correct |
827 ms |
58012 KB |
Output is correct |
63 |
Correct |
553 ms |
48212 KB |
Output is correct |
64 |
Correct |
568 ms |
48064 KB |
Output is correct |
65 |
Correct |
761 ms |
53664 KB |
Output is correct |
66 |
Correct |
790 ms |
53520 KB |
Output is correct |
67 |
Correct |
804 ms |
53864 KB |
Output is correct |
68 |
Correct |
867 ms |
58328 KB |
Output is correct |
69 |
Correct |
881 ms |
58220 KB |
Output is correct |
70 |
Correct |
828 ms |
57440 KB |
Output is correct |
71 |
Correct |
832 ms |
57528 KB |
Output is correct |
72 |
Correct |
832 ms |
57656 KB |
Output is correct |
73 |
Correct |
518 ms |
47620 KB |
Output is correct |
74 |
Correct |
557 ms |
47716 KB |
Output is correct |
75 |
Correct |
530 ms |
47628 KB |
Output is correct |
76 |
Correct |
528 ms |
47768 KB |
Output is correct |
77 |
Correct |
568 ms |
47552 KB |
Output is correct |
78 |
Correct |
739 ms |
57660 KB |
Output is correct |
79 |
Correct |
605 ms |
52052 KB |
Output is correct |
80 |
Correct |
766 ms |
56792 KB |
Output is correct |