#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e6 + 66;
// l<=i<=j<=r a[i] > a[j] a[i]+a[j]>x
//
int a[N], ans[N];
vector<tuple<int,int,int>> q[N];
int f[N];
void upd(int i, int j) {
i = N - 1 - i;
while (i < N) {
f[i] = max(f[i], j);
i |= i + 1;
}
}
int get(int i) {
i = N - 1 - i;
int j = 0;
while (i >= 0) {
j = max(j, f[i]);
i &= i + 1;
i--;
}
return j;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int n, m;
cin >> n >> m;
for (int i = 1 ; i <= n ; ++ i) cin >> a[i];
for (int i = 1 ; i <= m ; ++ i) {
int l, r, k;
cin >> l >> r >> k;
q[r].push_back({l, k, i});
}
stack<int> s;
for (int i = 1 ; i <= n ; ++ i) {
while (s.size() && a[s.top()] <= a[i]) s.pop();
if (s.size()) {
int j = s.top();
upd(j, a[i] + a[j]);
}
s.push(i);
for (auto [l, k, j] : q[i]) {
ans[j] = (get(l) <= k);
}
}
for (int i = 1 ; i <= m ; ++ i) cout << ans[i] << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23788 KB |
Output is correct |
2 |
Correct |
16 ms |
23788 KB |
Output is correct |
3 |
Correct |
16 ms |
23916 KB |
Output is correct |
4 |
Correct |
16 ms |
23916 KB |
Output is correct |
5 |
Correct |
16 ms |
23788 KB |
Output is correct |
6 |
Correct |
16 ms |
23916 KB |
Output is correct |
7 |
Correct |
16 ms |
23916 KB |
Output is correct |
8 |
Correct |
16 ms |
23916 KB |
Output is correct |
9 |
Correct |
16 ms |
23916 KB |
Output is correct |
10 |
Correct |
16 ms |
23916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23788 KB |
Output is correct |
2 |
Correct |
16 ms |
23788 KB |
Output is correct |
3 |
Correct |
16 ms |
23916 KB |
Output is correct |
4 |
Correct |
16 ms |
23916 KB |
Output is correct |
5 |
Correct |
16 ms |
23788 KB |
Output is correct |
6 |
Correct |
16 ms |
23916 KB |
Output is correct |
7 |
Correct |
16 ms |
23916 KB |
Output is correct |
8 |
Correct |
16 ms |
23916 KB |
Output is correct |
9 |
Correct |
16 ms |
23916 KB |
Output is correct |
10 |
Correct |
16 ms |
23916 KB |
Output is correct |
11 |
Correct |
17 ms |
23916 KB |
Output is correct |
12 |
Correct |
18 ms |
23916 KB |
Output is correct |
13 |
Correct |
18 ms |
24064 KB |
Output is correct |
14 |
Correct |
19 ms |
24044 KB |
Output is correct |
15 |
Correct |
21 ms |
24064 KB |
Output is correct |
16 |
Correct |
19 ms |
24044 KB |
Output is correct |
17 |
Correct |
20 ms |
24044 KB |
Output is correct |
18 |
Correct |
19 ms |
24044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1016 ms |
59352 KB |
Output is correct |
2 |
Correct |
1097 ms |
59392 KB |
Output is correct |
3 |
Correct |
1036 ms |
59584 KB |
Output is correct |
4 |
Correct |
1006 ms |
59536 KB |
Output is correct |
5 |
Correct |
981 ms |
56004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
85 ms |
27372 KB |
Output is correct |
2 |
Correct |
75 ms |
27372 KB |
Output is correct |
3 |
Correct |
85 ms |
26988 KB |
Output is correct |
4 |
Correct |
80 ms |
27552 KB |
Output is correct |
5 |
Correct |
80 ms |
27620 KB |
Output is correct |
6 |
Correct |
67 ms |
27208 KB |
Output is correct |
7 |
Correct |
78 ms |
27244 KB |
Output is correct |
8 |
Correct |
72 ms |
27428 KB |
Output is correct |
9 |
Correct |
72 ms |
26660 KB |
Output is correct |
10 |
Correct |
71 ms |
27540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23788 KB |
Output is correct |
2 |
Correct |
16 ms |
23788 KB |
Output is correct |
3 |
Correct |
16 ms |
23916 KB |
Output is correct |
4 |
Correct |
16 ms |
23916 KB |
Output is correct |
5 |
Correct |
16 ms |
23788 KB |
Output is correct |
6 |
Correct |
16 ms |
23916 KB |
Output is correct |
7 |
Correct |
16 ms |
23916 KB |
Output is correct |
8 |
Correct |
16 ms |
23916 KB |
Output is correct |
9 |
Correct |
16 ms |
23916 KB |
Output is correct |
10 |
Correct |
16 ms |
23916 KB |
Output is correct |
11 |
Correct |
17 ms |
23916 KB |
Output is correct |
12 |
Correct |
18 ms |
23916 KB |
Output is correct |
13 |
Correct |
18 ms |
24064 KB |
Output is correct |
14 |
Correct |
19 ms |
24044 KB |
Output is correct |
15 |
Correct |
21 ms |
24064 KB |
Output is correct |
16 |
Correct |
19 ms |
24044 KB |
Output is correct |
17 |
Correct |
20 ms |
24044 KB |
Output is correct |
18 |
Correct |
19 ms |
24044 KB |
Output is correct |
19 |
Correct |
193 ms |
31084 KB |
Output is correct |
20 |
Correct |
183 ms |
31164 KB |
Output is correct |
21 |
Correct |
153 ms |
31340 KB |
Output is correct |
22 |
Correct |
156 ms |
31596 KB |
Output is correct |
23 |
Correct |
158 ms |
31700 KB |
Output is correct |
24 |
Correct |
168 ms |
30752 KB |
Output is correct |
25 |
Correct |
143 ms |
30828 KB |
Output is correct |
26 |
Correct |
166 ms |
31084 KB |
Output is correct |
27 |
Correct |
158 ms |
30956 KB |
Output is correct |
28 |
Correct |
163 ms |
31084 KB |
Output is correct |
29 |
Correct |
181 ms |
31396 KB |
Output is correct |
30 |
Correct |
181 ms |
31336 KB |
Output is correct |
31 |
Correct |
174 ms |
31284 KB |
Output is correct |
32 |
Correct |
178 ms |
31300 KB |
Output is correct |
33 |
Correct |
185 ms |
31336 KB |
Output is correct |
34 |
Correct |
146 ms |
30560 KB |
Output is correct |
35 |
Correct |
132 ms |
30444 KB |
Output is correct |
36 |
Correct |
176 ms |
30572 KB |
Output is correct |
37 |
Correct |
126 ms |
30444 KB |
Output is correct |
38 |
Correct |
140 ms |
30572 KB |
Output is correct |
39 |
Correct |
165 ms |
31028 KB |
Output is correct |
40 |
Correct |
132 ms |
29728 KB |
Output is correct |
41 |
Correct |
150 ms |
30368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23788 KB |
Output is correct |
2 |
Correct |
16 ms |
23788 KB |
Output is correct |
3 |
Correct |
16 ms |
23916 KB |
Output is correct |
4 |
Correct |
16 ms |
23916 KB |
Output is correct |
5 |
Correct |
16 ms |
23788 KB |
Output is correct |
6 |
Correct |
16 ms |
23916 KB |
Output is correct |
7 |
Correct |
16 ms |
23916 KB |
Output is correct |
8 |
Correct |
16 ms |
23916 KB |
Output is correct |
9 |
Correct |
16 ms |
23916 KB |
Output is correct |
10 |
Correct |
16 ms |
23916 KB |
Output is correct |
11 |
Correct |
17 ms |
23916 KB |
Output is correct |
12 |
Correct |
18 ms |
23916 KB |
Output is correct |
13 |
Correct |
18 ms |
24064 KB |
Output is correct |
14 |
Correct |
19 ms |
24044 KB |
Output is correct |
15 |
Correct |
21 ms |
24064 KB |
Output is correct |
16 |
Correct |
19 ms |
24044 KB |
Output is correct |
17 |
Correct |
20 ms |
24044 KB |
Output is correct |
18 |
Correct |
19 ms |
24044 KB |
Output is correct |
19 |
Correct |
1016 ms |
59352 KB |
Output is correct |
20 |
Correct |
1097 ms |
59392 KB |
Output is correct |
21 |
Correct |
1036 ms |
59584 KB |
Output is correct |
22 |
Correct |
1006 ms |
59536 KB |
Output is correct |
23 |
Correct |
981 ms |
56004 KB |
Output is correct |
24 |
Correct |
85 ms |
27372 KB |
Output is correct |
25 |
Correct |
75 ms |
27372 KB |
Output is correct |
26 |
Correct |
85 ms |
26988 KB |
Output is correct |
27 |
Correct |
80 ms |
27552 KB |
Output is correct |
28 |
Correct |
80 ms |
27620 KB |
Output is correct |
29 |
Correct |
67 ms |
27208 KB |
Output is correct |
30 |
Correct |
78 ms |
27244 KB |
Output is correct |
31 |
Correct |
72 ms |
27428 KB |
Output is correct |
32 |
Correct |
72 ms |
26660 KB |
Output is correct |
33 |
Correct |
71 ms |
27540 KB |
Output is correct |
34 |
Correct |
193 ms |
31084 KB |
Output is correct |
35 |
Correct |
183 ms |
31164 KB |
Output is correct |
36 |
Correct |
153 ms |
31340 KB |
Output is correct |
37 |
Correct |
156 ms |
31596 KB |
Output is correct |
38 |
Correct |
158 ms |
31700 KB |
Output is correct |
39 |
Correct |
168 ms |
30752 KB |
Output is correct |
40 |
Correct |
143 ms |
30828 KB |
Output is correct |
41 |
Correct |
166 ms |
31084 KB |
Output is correct |
42 |
Correct |
158 ms |
30956 KB |
Output is correct |
43 |
Correct |
163 ms |
31084 KB |
Output is correct |
44 |
Correct |
181 ms |
31396 KB |
Output is correct |
45 |
Correct |
181 ms |
31336 KB |
Output is correct |
46 |
Correct |
174 ms |
31284 KB |
Output is correct |
47 |
Correct |
178 ms |
31300 KB |
Output is correct |
48 |
Correct |
185 ms |
31336 KB |
Output is correct |
49 |
Correct |
146 ms |
30560 KB |
Output is correct |
50 |
Correct |
132 ms |
30444 KB |
Output is correct |
51 |
Correct |
176 ms |
30572 KB |
Output is correct |
52 |
Correct |
126 ms |
30444 KB |
Output is correct |
53 |
Correct |
140 ms |
30572 KB |
Output is correct |
54 |
Correct |
165 ms |
31028 KB |
Output is correct |
55 |
Correct |
132 ms |
29728 KB |
Output is correct |
56 |
Correct |
150 ms |
30368 KB |
Output is correct |
57 |
Correct |
1000 ms |
59376 KB |
Output is correct |
58 |
Correct |
1068 ms |
59508 KB |
Output is correct |
59 |
Correct |
1086 ms |
58012 KB |
Output is correct |
60 |
Correct |
964 ms |
57936 KB |
Output is correct |
61 |
Correct |
933 ms |
58156 KB |
Output is correct |
62 |
Correct |
930 ms |
57964 KB |
Output is correct |
63 |
Correct |
654 ms |
52332 KB |
Output is correct |
64 |
Correct |
716 ms |
52164 KB |
Output is correct |
65 |
Correct |
885 ms |
53840 KB |
Output is correct |
66 |
Correct |
910 ms |
53804 KB |
Output is correct |
67 |
Correct |
886 ms |
53812 KB |
Output is correct |
68 |
Correct |
928 ms |
55332 KB |
Output is correct |
69 |
Correct |
939 ms |
55252 KB |
Output is correct |
70 |
Correct |
975 ms |
55096 KB |
Output is correct |
71 |
Correct |
911 ms |
55020 KB |
Output is correct |
72 |
Correct |
900 ms |
55148 KB |
Output is correct |
73 |
Correct |
582 ms |
49644 KB |
Output is correct |
74 |
Correct |
592 ms |
50156 KB |
Output is correct |
75 |
Correct |
570 ms |
50072 KB |
Output is correct |
76 |
Correct |
569 ms |
49900 KB |
Output is correct |
77 |
Correct |
565 ms |
49444 KB |
Output is correct |
78 |
Correct |
812 ms |
54608 KB |
Output is correct |
79 |
Correct |
653 ms |
49220 KB |
Output is correct |
80 |
Correct |
818 ms |
53368 KB |
Output is correct |