#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)1e6 + 6;
struct Query {
int l, k, id;
Query (int l_, int k_, int id_) {
l = l_, k = k_, id = id_;
}
Query () {
}
};
vector <Query> query[MAXN];
int a[MAXN];
int ans[MAXN];
int tree[MAXN * 4];
void upd(int pos, int val, int v = 1, int tl = 1, int tr = MAXN) {
tl = 1, tr = MAXN;
while (tl != tr) {
int mid = (tl + tr) >> 1;
if (pos <= mid) {
tr = mid;
v = v + v;
} else {
tl = mid + 1;
v = v + v + 1;
}
}
tree[v] = max(tree[v], val);
v = (v >> 1);
for (v; v >= 1; v = (v >> 1)) {
tree[v] = max(tree[v + v], tree[v + v + 1]);
}
}
int get(int l, int r, int v = 1, int tl = 1, int tr = MAXN) {
if (l <= tl && tr <= r) {
return tree[v];
}
if (l > tr || tl > r) {
return 0;
}
int mid = (tl + tr) >> 1;
return max(get(l, r, v + v, tl, mid), get(l, r, v + v + 1, mid + 1, tr));
}
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int n, q;
cin >> n >> q;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
vector <Query> vec;
for (int i = 1; i <= q; i++) {
int l, r, k;
cin >> l >> r >> k;
query[r].push_back(Query(l, k, i));
}
vector <pair<int, int>> st;
for (int r = 1; r <= n; r++) {
while (!st.empty() && st.back().first < a[r]) {
st.pop_back();
}
if (!st.empty() && st.back().first > a[r]) {
upd(st.back().second, st.back().first + a[r]);
}
st.push_back({a[r], r});
while (!query[r].empty()) {
int l = query[r].back().l;
int k = query[r].back().k;
int id = query[r].back().id;
query[r].pop_back();
ans[id] = (get(l, r) <= k);
}
}
for (int i = 1; i <= q; i++) {
cout << ans[i] << "\n";
}
}
Compilation message
sortbooks.cpp: In function 'void upd(int, int, int, int, int)':
sortbooks.cpp:35:8: warning: statement has no effect [-Wunused-value]
35 | for (v; v >= 1; v = (v >> 1)) {
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
23916 KB |
Output is correct |
2 |
Correct |
16 ms |
23788 KB |
Output is correct |
3 |
Correct |
17 ms |
23916 KB |
Output is correct |
4 |
Correct |
17 ms |
23916 KB |
Output is correct |
5 |
Correct |
17 ms |
23916 KB |
Output is correct |
6 |
Correct |
17 ms |
23980 KB |
Output is correct |
7 |
Correct |
17 ms |
23916 KB |
Output is correct |
8 |
Correct |
18 ms |
23916 KB |
Output is correct |
9 |
Correct |
17 ms |
23916 KB |
Output is correct |
10 |
Correct |
17 ms |
23916 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
23916 KB |
Output is correct |
2 |
Correct |
16 ms |
23788 KB |
Output is correct |
3 |
Correct |
17 ms |
23916 KB |
Output is correct |
4 |
Correct |
17 ms |
23916 KB |
Output is correct |
5 |
Correct |
17 ms |
23916 KB |
Output is correct |
6 |
Correct |
17 ms |
23980 KB |
Output is correct |
7 |
Correct |
17 ms |
23916 KB |
Output is correct |
8 |
Correct |
18 ms |
23916 KB |
Output is correct |
9 |
Correct |
17 ms |
23916 KB |
Output is correct |
10 |
Correct |
17 ms |
23916 KB |
Output is correct |
11 |
Correct |
20 ms |
24100 KB |
Output is correct |
12 |
Correct |
21 ms |
24056 KB |
Output is correct |
13 |
Correct |
21 ms |
24044 KB |
Output is correct |
14 |
Correct |
22 ms |
24172 KB |
Output is correct |
15 |
Correct |
22 ms |
24172 KB |
Output is correct |
16 |
Correct |
21 ms |
24172 KB |
Output is correct |
17 |
Correct |
21 ms |
24044 KB |
Output is correct |
18 |
Correct |
21 ms |
24300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1674 ms |
63752 KB |
Output is correct |
2 |
Correct |
1674 ms |
63804 KB |
Output is correct |
3 |
Correct |
1688 ms |
63972 KB |
Output is correct |
4 |
Correct |
1671 ms |
63856 KB |
Output is correct |
5 |
Correct |
1411 ms |
55704 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
142 ms |
27756 KB |
Output is correct |
2 |
Correct |
124 ms |
27628 KB |
Output is correct |
3 |
Correct |
120 ms |
26860 KB |
Output is correct |
4 |
Correct |
118 ms |
26988 KB |
Output is correct |
5 |
Correct |
120 ms |
26988 KB |
Output is correct |
6 |
Correct |
99 ms |
26604 KB |
Output is correct |
7 |
Correct |
103 ms |
26604 KB |
Output is correct |
8 |
Correct |
109 ms |
27684 KB |
Output is correct |
9 |
Correct |
75 ms |
26020 KB |
Output is correct |
10 |
Correct |
107 ms |
27812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
23916 KB |
Output is correct |
2 |
Correct |
16 ms |
23788 KB |
Output is correct |
3 |
Correct |
17 ms |
23916 KB |
Output is correct |
4 |
Correct |
17 ms |
23916 KB |
Output is correct |
5 |
Correct |
17 ms |
23916 KB |
Output is correct |
6 |
Correct |
17 ms |
23980 KB |
Output is correct |
7 |
Correct |
17 ms |
23916 KB |
Output is correct |
8 |
Correct |
18 ms |
23916 KB |
Output is correct |
9 |
Correct |
17 ms |
23916 KB |
Output is correct |
10 |
Correct |
17 ms |
23916 KB |
Output is correct |
11 |
Correct |
20 ms |
24100 KB |
Output is correct |
12 |
Correct |
21 ms |
24056 KB |
Output is correct |
13 |
Correct |
21 ms |
24044 KB |
Output is correct |
14 |
Correct |
22 ms |
24172 KB |
Output is correct |
15 |
Correct |
22 ms |
24172 KB |
Output is correct |
16 |
Correct |
21 ms |
24172 KB |
Output is correct |
17 |
Correct |
21 ms |
24044 KB |
Output is correct |
18 |
Correct |
21 ms |
24300 KB |
Output is correct |
19 |
Correct |
307 ms |
31724 KB |
Output is correct |
20 |
Correct |
305 ms |
31724 KB |
Output is correct |
21 |
Correct |
255 ms |
31212 KB |
Output is correct |
22 |
Correct |
251 ms |
31232 KB |
Output is correct |
23 |
Correct |
254 ms |
31340 KB |
Output is correct |
24 |
Correct |
218 ms |
29548 KB |
Output is correct |
25 |
Correct |
219 ms |
29548 KB |
Output is correct |
26 |
Correct |
250 ms |
29804 KB |
Output is correct |
27 |
Correct |
241 ms |
29676 KB |
Output is correct |
28 |
Correct |
260 ms |
29804 KB |
Output is correct |
29 |
Correct |
256 ms |
30060 KB |
Output is correct |
30 |
Correct |
264 ms |
30188 KB |
Output is correct |
31 |
Correct |
255 ms |
30060 KB |
Output is correct |
32 |
Correct |
255 ms |
30060 KB |
Output is correct |
33 |
Correct |
268 ms |
30060 KB |
Output is correct |
34 |
Correct |
203 ms |
29292 KB |
Output is correct |
35 |
Correct |
205 ms |
29248 KB |
Output is correct |
36 |
Correct |
200 ms |
29292 KB |
Output is correct |
37 |
Correct |
204 ms |
29420 KB |
Output is correct |
38 |
Correct |
210 ms |
29292 KB |
Output is correct |
39 |
Correct |
237 ms |
30260 KB |
Output is correct |
40 |
Correct |
200 ms |
29184 KB |
Output is correct |
41 |
Correct |
222 ms |
31392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
23916 KB |
Output is correct |
2 |
Correct |
16 ms |
23788 KB |
Output is correct |
3 |
Correct |
17 ms |
23916 KB |
Output is correct |
4 |
Correct |
17 ms |
23916 KB |
Output is correct |
5 |
Correct |
17 ms |
23916 KB |
Output is correct |
6 |
Correct |
17 ms |
23980 KB |
Output is correct |
7 |
Correct |
17 ms |
23916 KB |
Output is correct |
8 |
Correct |
18 ms |
23916 KB |
Output is correct |
9 |
Correct |
17 ms |
23916 KB |
Output is correct |
10 |
Correct |
17 ms |
23916 KB |
Output is correct |
11 |
Correct |
20 ms |
24100 KB |
Output is correct |
12 |
Correct |
21 ms |
24056 KB |
Output is correct |
13 |
Correct |
21 ms |
24044 KB |
Output is correct |
14 |
Correct |
22 ms |
24172 KB |
Output is correct |
15 |
Correct |
22 ms |
24172 KB |
Output is correct |
16 |
Correct |
21 ms |
24172 KB |
Output is correct |
17 |
Correct |
21 ms |
24044 KB |
Output is correct |
18 |
Correct |
21 ms |
24300 KB |
Output is correct |
19 |
Correct |
1674 ms |
63752 KB |
Output is correct |
20 |
Correct |
1674 ms |
63804 KB |
Output is correct |
21 |
Correct |
1688 ms |
63972 KB |
Output is correct |
22 |
Correct |
1671 ms |
63856 KB |
Output is correct |
23 |
Correct |
1411 ms |
55704 KB |
Output is correct |
24 |
Correct |
142 ms |
27756 KB |
Output is correct |
25 |
Correct |
124 ms |
27628 KB |
Output is correct |
26 |
Correct |
120 ms |
26860 KB |
Output is correct |
27 |
Correct |
118 ms |
26988 KB |
Output is correct |
28 |
Correct |
120 ms |
26988 KB |
Output is correct |
29 |
Correct |
99 ms |
26604 KB |
Output is correct |
30 |
Correct |
103 ms |
26604 KB |
Output is correct |
31 |
Correct |
109 ms |
27684 KB |
Output is correct |
32 |
Correct |
75 ms |
26020 KB |
Output is correct |
33 |
Correct |
107 ms |
27812 KB |
Output is correct |
34 |
Correct |
307 ms |
31724 KB |
Output is correct |
35 |
Correct |
305 ms |
31724 KB |
Output is correct |
36 |
Correct |
255 ms |
31212 KB |
Output is correct |
37 |
Correct |
251 ms |
31232 KB |
Output is correct |
38 |
Correct |
254 ms |
31340 KB |
Output is correct |
39 |
Correct |
218 ms |
29548 KB |
Output is correct |
40 |
Correct |
219 ms |
29548 KB |
Output is correct |
41 |
Correct |
250 ms |
29804 KB |
Output is correct |
42 |
Correct |
241 ms |
29676 KB |
Output is correct |
43 |
Correct |
260 ms |
29804 KB |
Output is correct |
44 |
Correct |
256 ms |
30060 KB |
Output is correct |
45 |
Correct |
264 ms |
30188 KB |
Output is correct |
46 |
Correct |
255 ms |
30060 KB |
Output is correct |
47 |
Correct |
255 ms |
30060 KB |
Output is correct |
48 |
Correct |
268 ms |
30060 KB |
Output is correct |
49 |
Correct |
203 ms |
29292 KB |
Output is correct |
50 |
Correct |
205 ms |
29248 KB |
Output is correct |
51 |
Correct |
200 ms |
29292 KB |
Output is correct |
52 |
Correct |
204 ms |
29420 KB |
Output is correct |
53 |
Correct |
210 ms |
29292 KB |
Output is correct |
54 |
Correct |
237 ms |
30260 KB |
Output is correct |
55 |
Correct |
200 ms |
29184 KB |
Output is correct |
56 |
Correct |
222 ms |
31392 KB |
Output is correct |
57 |
Correct |
1682 ms |
63468 KB |
Output is correct |
58 |
Correct |
1686 ms |
63372 KB |
Output is correct |
59 |
Correct |
1623 ms |
61852 KB |
Output is correct |
60 |
Correct |
1614 ms |
61848 KB |
Output is correct |
61 |
Correct |
1614 ms |
61844 KB |
Output is correct |
62 |
Correct |
1599 ms |
61880 KB |
Output is correct |
63 |
Correct |
1100 ms |
52460 KB |
Output is correct |
64 |
Correct |
1087 ms |
52480 KB |
Output is correct |
65 |
Correct |
1396 ms |
53512 KB |
Output is correct |
66 |
Correct |
1375 ms |
53540 KB |
Output is correct |
67 |
Correct |
1371 ms |
53600 KB |
Output is correct |
68 |
Correct |
1403 ms |
55148 KB |
Output is correct |
69 |
Correct |
1405 ms |
55280 KB |
Output is correct |
70 |
Correct |
1446 ms |
55048 KB |
Output is correct |
71 |
Correct |
1450 ms |
54848 KB |
Output is correct |
72 |
Correct |
1448 ms |
54788 KB |
Output is correct |
73 |
Correct |
983 ms |
49660 KB |
Output is correct |
74 |
Correct |
1031 ms |
49888 KB |
Output is correct |
75 |
Correct |
963 ms |
50076 KB |
Output is correct |
76 |
Correct |
972 ms |
49944 KB |
Output is correct |
77 |
Correct |
997 ms |
49444 KB |
Output is correct |
78 |
Correct |
1273 ms |
56092 KB |
Output is correct |
79 |
Correct |
993 ms |
49296 KB |
Output is correct |
80 |
Correct |
1184 ms |
61568 KB |
Output is correct |