#include <bits/stdc++.h>
using namespace std;
#define tp3 tuple<int, int, int>
const int N = 1e6, L = 20, inf = INT_MAX;
int n, m, a[N], b[N], seg[N*4];
vector<int> lf[N];
vector<tp3> q[N];
bitset<N> ans;
void build(int p=1, int l=0, int r=n-1) {
if (l == r) {
seg[p] = (b[l] == -1 ? 0 : (a[l] + a[b[l]]));
return;
}
int mid = (l+r) >> 1;
build(p*2, l, mid);
build(p*2+1, mid+1, r);
seg[p] = max(seg[p*2], seg[p*2+1]);
}
void update(int x, int p=1, int l=0, int r=n-1) {
if (l == r) {
seg[p] = 0;
return;
}
int mid = (l+r) >> 1;
if (x <= mid) update(x, p*2, l, mid);
else update(x, p*2+1, mid+1, r);
seg[p] = max(seg[p*2], seg[p*2+1]);
}
int query(int x, int y, int p=1, int l=0, int r=n-1) {
if (x <= l && r <= y) {
return seg[p];
}
int mid = (l+r) >> 1;
if (y <= mid) {
return query(x, y, p*2, l, mid);
}
else if(mid+1 <= x) {
return query(x, y, p*2+1, mid+1, r);
}
else {
return max(query(x, y, p*2, l, mid), query(x, y, p*2+1, mid+1, r));
}
}
signed main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n >> m;
stack<pair<int, int>> st;
for (int i = 0; i < n; i++) {
cin >> a[i];
while (!st.empty() && st.top().first <= a[i]) st.pop();
b[i] = (st.empty() ? -1 : st.top().second);
if (b[i] != -1) lf[b[i]].push_back(i);
st.push(make_pair(a[i], i));
}
for (int i = 0; i < m; i++) {
int l, r, k;
cin >> l >> r >> k;
l--; r--;
q[l].push_back(make_tuple(r, k, i));
}
build();
for (int l = 0; l < n; l++) {
for (auto& [r, k, idx] : q[l]) {
ans[idx] = (query(l, r) <= k);
}
for (int& i : lf[l]) {
update(i);
}
}
for (int i = 0; i < m; i++) {
cout << ans[i] << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
51800 KB |
Output is correct |
2 |
Correct |
10 ms |
51804 KB |
Output is correct |
3 |
Correct |
11 ms |
51836 KB |
Output is correct |
4 |
Correct |
11 ms |
51768 KB |
Output is correct |
5 |
Correct |
11 ms |
51804 KB |
Output is correct |
6 |
Correct |
12 ms |
51844 KB |
Output is correct |
7 |
Correct |
12 ms |
51800 KB |
Output is correct |
8 |
Correct |
11 ms |
51804 KB |
Output is correct |
9 |
Correct |
10 ms |
51800 KB |
Output is correct |
10 |
Correct |
11 ms |
51844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
51800 KB |
Output is correct |
2 |
Correct |
10 ms |
51804 KB |
Output is correct |
3 |
Correct |
11 ms |
51836 KB |
Output is correct |
4 |
Correct |
11 ms |
51768 KB |
Output is correct |
5 |
Correct |
11 ms |
51804 KB |
Output is correct |
6 |
Correct |
12 ms |
51844 KB |
Output is correct |
7 |
Correct |
12 ms |
51800 KB |
Output is correct |
8 |
Correct |
11 ms |
51804 KB |
Output is correct |
9 |
Correct |
10 ms |
51800 KB |
Output is correct |
10 |
Correct |
11 ms |
51844 KB |
Output is correct |
11 |
Correct |
13 ms |
51804 KB |
Output is correct |
12 |
Correct |
13 ms |
51804 KB |
Output is correct |
13 |
Correct |
13 ms |
51800 KB |
Output is correct |
14 |
Correct |
15 ms |
51800 KB |
Output is correct |
15 |
Correct |
15 ms |
52016 KB |
Output is correct |
16 |
Correct |
13 ms |
51964 KB |
Output is correct |
17 |
Correct |
13 ms |
51800 KB |
Output is correct |
18 |
Correct |
13 ms |
51800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
999 ms |
104528 KB |
Output is correct |
2 |
Correct |
1002 ms |
104664 KB |
Output is correct |
3 |
Correct |
1071 ms |
104788 KB |
Output is correct |
4 |
Correct |
1031 ms |
104752 KB |
Output is correct |
5 |
Correct |
842 ms |
88456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
91 ms |
57928 KB |
Output is correct |
2 |
Correct |
77 ms |
57620 KB |
Output is correct |
3 |
Correct |
65 ms |
55960 KB |
Output is correct |
4 |
Correct |
66 ms |
56264 KB |
Output is correct |
5 |
Correct |
68 ms |
56144 KB |
Output is correct |
6 |
Correct |
57 ms |
55628 KB |
Output is correct |
7 |
Correct |
70 ms |
55868 KB |
Output is correct |
8 |
Correct |
65 ms |
56164 KB |
Output is correct |
9 |
Correct |
36 ms |
53512 KB |
Output is correct |
10 |
Correct |
61 ms |
56076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
51800 KB |
Output is correct |
2 |
Correct |
10 ms |
51804 KB |
Output is correct |
3 |
Correct |
11 ms |
51836 KB |
Output is correct |
4 |
Correct |
11 ms |
51768 KB |
Output is correct |
5 |
Correct |
11 ms |
51804 KB |
Output is correct |
6 |
Correct |
12 ms |
51844 KB |
Output is correct |
7 |
Correct |
12 ms |
51800 KB |
Output is correct |
8 |
Correct |
11 ms |
51804 KB |
Output is correct |
9 |
Correct |
10 ms |
51800 KB |
Output is correct |
10 |
Correct |
11 ms |
51844 KB |
Output is correct |
11 |
Correct |
13 ms |
51804 KB |
Output is correct |
12 |
Correct |
13 ms |
51804 KB |
Output is correct |
13 |
Correct |
13 ms |
51800 KB |
Output is correct |
14 |
Correct |
15 ms |
51800 KB |
Output is correct |
15 |
Correct |
15 ms |
52016 KB |
Output is correct |
16 |
Correct |
13 ms |
51964 KB |
Output is correct |
17 |
Correct |
13 ms |
51800 KB |
Output is correct |
18 |
Correct |
13 ms |
51800 KB |
Output is correct |
19 |
Correct |
187 ms |
61988 KB |
Output is correct |
20 |
Correct |
186 ms |
61876 KB |
Output is correct |
21 |
Correct |
156 ms |
61388 KB |
Output is correct |
22 |
Correct |
161 ms |
61584 KB |
Output is correct |
23 |
Correct |
157 ms |
61524 KB |
Output is correct |
24 |
Correct |
122 ms |
58200 KB |
Output is correct |
25 |
Correct |
121 ms |
58196 KB |
Output is correct |
26 |
Correct |
130 ms |
58204 KB |
Output is correct |
27 |
Correct |
161 ms |
58196 KB |
Output is correct |
28 |
Correct |
134 ms |
58236 KB |
Output is correct |
29 |
Correct |
154 ms |
58700 KB |
Output is correct |
30 |
Correct |
139 ms |
58708 KB |
Output is correct |
31 |
Correct |
146 ms |
58704 KB |
Output is correct |
32 |
Correct |
150 ms |
58616 KB |
Output is correct |
33 |
Correct |
147 ms |
58708 KB |
Output is correct |
34 |
Correct |
115 ms |
57444 KB |
Output is correct |
35 |
Correct |
116 ms |
57428 KB |
Output is correct |
36 |
Correct |
134 ms |
57432 KB |
Output is correct |
37 |
Correct |
114 ms |
57636 KB |
Output is correct |
38 |
Correct |
115 ms |
57448 KB |
Output is correct |
39 |
Correct |
151 ms |
59076 KB |
Output is correct |
40 |
Correct |
113 ms |
57556 KB |
Output is correct |
41 |
Correct |
126 ms |
58188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
51800 KB |
Output is correct |
2 |
Correct |
10 ms |
51804 KB |
Output is correct |
3 |
Correct |
11 ms |
51836 KB |
Output is correct |
4 |
Correct |
11 ms |
51768 KB |
Output is correct |
5 |
Correct |
11 ms |
51804 KB |
Output is correct |
6 |
Correct |
12 ms |
51844 KB |
Output is correct |
7 |
Correct |
12 ms |
51800 KB |
Output is correct |
8 |
Correct |
11 ms |
51804 KB |
Output is correct |
9 |
Correct |
10 ms |
51800 KB |
Output is correct |
10 |
Correct |
11 ms |
51844 KB |
Output is correct |
11 |
Correct |
13 ms |
51804 KB |
Output is correct |
12 |
Correct |
13 ms |
51804 KB |
Output is correct |
13 |
Correct |
13 ms |
51800 KB |
Output is correct |
14 |
Correct |
15 ms |
51800 KB |
Output is correct |
15 |
Correct |
15 ms |
52016 KB |
Output is correct |
16 |
Correct |
13 ms |
51964 KB |
Output is correct |
17 |
Correct |
13 ms |
51800 KB |
Output is correct |
18 |
Correct |
13 ms |
51800 KB |
Output is correct |
19 |
Correct |
999 ms |
104528 KB |
Output is correct |
20 |
Correct |
1002 ms |
104664 KB |
Output is correct |
21 |
Correct |
1071 ms |
104788 KB |
Output is correct |
22 |
Correct |
1031 ms |
104752 KB |
Output is correct |
23 |
Correct |
842 ms |
88456 KB |
Output is correct |
24 |
Correct |
91 ms |
57928 KB |
Output is correct |
25 |
Correct |
77 ms |
57620 KB |
Output is correct |
26 |
Correct |
65 ms |
55960 KB |
Output is correct |
27 |
Correct |
66 ms |
56264 KB |
Output is correct |
28 |
Correct |
68 ms |
56144 KB |
Output is correct |
29 |
Correct |
57 ms |
55628 KB |
Output is correct |
30 |
Correct |
70 ms |
55868 KB |
Output is correct |
31 |
Correct |
65 ms |
56164 KB |
Output is correct |
32 |
Correct |
36 ms |
53512 KB |
Output is correct |
33 |
Correct |
61 ms |
56076 KB |
Output is correct |
34 |
Correct |
187 ms |
61988 KB |
Output is correct |
35 |
Correct |
186 ms |
61876 KB |
Output is correct |
36 |
Correct |
156 ms |
61388 KB |
Output is correct |
37 |
Correct |
161 ms |
61584 KB |
Output is correct |
38 |
Correct |
157 ms |
61524 KB |
Output is correct |
39 |
Correct |
122 ms |
58200 KB |
Output is correct |
40 |
Correct |
121 ms |
58196 KB |
Output is correct |
41 |
Correct |
130 ms |
58204 KB |
Output is correct |
42 |
Correct |
161 ms |
58196 KB |
Output is correct |
43 |
Correct |
134 ms |
58236 KB |
Output is correct |
44 |
Correct |
154 ms |
58700 KB |
Output is correct |
45 |
Correct |
139 ms |
58708 KB |
Output is correct |
46 |
Correct |
146 ms |
58704 KB |
Output is correct |
47 |
Correct |
150 ms |
58616 KB |
Output is correct |
48 |
Correct |
147 ms |
58708 KB |
Output is correct |
49 |
Correct |
115 ms |
57444 KB |
Output is correct |
50 |
Correct |
116 ms |
57428 KB |
Output is correct |
51 |
Correct |
134 ms |
57432 KB |
Output is correct |
52 |
Correct |
114 ms |
57636 KB |
Output is correct |
53 |
Correct |
115 ms |
57448 KB |
Output is correct |
54 |
Correct |
151 ms |
59076 KB |
Output is correct |
55 |
Correct |
113 ms |
57556 KB |
Output is correct |
56 |
Correct |
126 ms |
58188 KB |
Output is correct |
57 |
Correct |
1055 ms |
138920 KB |
Output is correct |
58 |
Correct |
1043 ms |
139120 KB |
Output is correct |
59 |
Correct |
1039 ms |
136872 KB |
Output is correct |
60 |
Correct |
977 ms |
137220 KB |
Output is correct |
61 |
Correct |
1000 ms |
136908 KB |
Output is correct |
62 |
Correct |
1016 ms |
136960 KB |
Output is correct |
63 |
Correct |
586 ms |
115020 KB |
Output is correct |
64 |
Correct |
600 ms |
115020 KB |
Output is correct |
65 |
Correct |
848 ms |
120744 KB |
Output is correct |
66 |
Correct |
848 ms |
120920 KB |
Output is correct |
67 |
Correct |
860 ms |
120748 KB |
Output is correct |
68 |
Correct |
955 ms |
122636 KB |
Output is correct |
69 |
Correct |
889 ms |
122740 KB |
Output is correct |
70 |
Correct |
874 ms |
122176 KB |
Output is correct |
71 |
Correct |
888 ms |
122432 KB |
Output is correct |
72 |
Correct |
902 ms |
121936 KB |
Output is correct |
73 |
Correct |
565 ms |
112600 KB |
Output is correct |
74 |
Correct |
570 ms |
113488 KB |
Output is correct |
75 |
Correct |
582 ms |
112572 KB |
Output is correct |
76 |
Correct |
580 ms |
112408 KB |
Output is correct |
77 |
Correct |
567 ms |
112580 KB |
Output is correct |
78 |
Correct |
757 ms |
118264 KB |
Output is correct |
79 |
Correct |
528 ms |
101736 KB |
Output is correct |
80 |
Correct |
784 ms |
113460 KB |
Output is correct |