#include <bits/stdc++.h>
#define ll unsigned long long
#define pii pair<ll, int>
using namespace std;
const int MAX = (1 << 20);
int tree[MAX * 2];
int ask(int ql, int qr, int node = 1, int l = 1, int r = MAX){
if(ql > r || qr < l) return 0;
if(ql <= l && r <= qr) return tree[node];
int mid = (l + r) / 2;
return max(ask(ql, qr, node * 2, l, mid), ask(ql, qr, node * 2 + 1, mid + 1, r));
}
void update(int pos, int val, int node = 1, int l = 1, int r = MAX){
if(l == r){
tree[node] = val;
return;
}
int mid = (l + r) / 2;
if(pos <= mid){
update(pos, val, node * 2, l, mid);
}
else{
update(pos, val, node * 2 + 1, mid + 1, r);
}
tree[node] = max(tree[node * 2], tree[node * 2 + 1]);
}
int n, m;
vector<array<int, 3>> quer[MAX];
bool ans[MAX];
int arr[MAX];
int main(){
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
scanf("%d", &arr[i]);
}
for (int i = 0; i < m; i++)
{
int l, r, k;
scanf("%d%d%d", &l, &r, &k);
quer[r].push_back({l, k, i});
}
stack<pii> st;
for (int i = 1; i <= n; i++)
{
while(!st.empty() && st.top().first <= arr[i]){
st.pop();
}
if(st.size()){
update(st.top().second, arr[st.top().second] + arr[i]);
}
st.push({arr[i], i});
for(auto& q:quer[i]){
ans[q[2]] = ask(q[0], i) <= q[1];
}
}
for (int i = 0; i < m; i++)
{
cout << ans[i] << '\n';
}
}
Compilation message
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:51:45: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'int' [-Wsign-compare]
51 | while(!st.empty() && st.top().first <= arr[i]){
| ~~~~~~~~~~~~~~~^~~~~~~~~
sortbooks.cpp:40:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
40 | scanf("%d", &arr[i]);
| ~~~~~^~~~~~~~~~~~~~~
sortbooks.cpp:45:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
45 | scanf("%d%d%d", &l, &r, &k);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
33112 KB |
Output is correct |
2 |
Correct |
6 ms |
29016 KB |
Output is correct |
3 |
Correct |
6 ms |
33116 KB |
Output is correct |
4 |
Correct |
7 ms |
33268 KB |
Output is correct |
5 |
Correct |
6 ms |
33116 KB |
Output is correct |
6 |
Correct |
8 ms |
33304 KB |
Output is correct |
7 |
Correct |
6 ms |
33116 KB |
Output is correct |
8 |
Correct |
6 ms |
29020 KB |
Output is correct |
9 |
Correct |
7 ms |
29176 KB |
Output is correct |
10 |
Correct |
6 ms |
29172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
33112 KB |
Output is correct |
2 |
Correct |
6 ms |
29016 KB |
Output is correct |
3 |
Correct |
6 ms |
33116 KB |
Output is correct |
4 |
Correct |
7 ms |
33268 KB |
Output is correct |
5 |
Correct |
6 ms |
33116 KB |
Output is correct |
6 |
Correct |
8 ms |
33304 KB |
Output is correct |
7 |
Correct |
6 ms |
33116 KB |
Output is correct |
8 |
Correct |
6 ms |
29020 KB |
Output is correct |
9 |
Correct |
7 ms |
29176 KB |
Output is correct |
10 |
Correct |
6 ms |
29172 KB |
Output is correct |
11 |
Correct |
8 ms |
33372 KB |
Output is correct |
12 |
Correct |
9 ms |
33372 KB |
Output is correct |
13 |
Correct |
9 ms |
33372 KB |
Output is correct |
14 |
Correct |
11 ms |
33500 KB |
Output is correct |
15 |
Correct |
10 ms |
33372 KB |
Output is correct |
16 |
Correct |
9 ms |
29408 KB |
Output is correct |
17 |
Correct |
8 ms |
29280 KB |
Output is correct |
18 |
Correct |
9 ms |
29272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1031 ms |
78164 KB |
Output is correct |
2 |
Correct |
1012 ms |
78556 KB |
Output is correct |
3 |
Correct |
1008 ms |
78416 KB |
Output is correct |
4 |
Correct |
1014 ms |
78676 KB |
Output is correct |
5 |
Correct |
918 ms |
72012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
90 ms |
38972 KB |
Output is correct |
2 |
Correct |
78 ms |
38724 KB |
Output is correct |
3 |
Correct |
71 ms |
34740 KB |
Output is correct |
4 |
Correct |
71 ms |
34896 KB |
Output is correct |
5 |
Correct |
71 ms |
34776 KB |
Output is correct |
6 |
Correct |
61 ms |
38484 KB |
Output is correct |
7 |
Correct |
64 ms |
38480 KB |
Output is correct |
8 |
Correct |
69 ms |
34568 KB |
Output is correct |
9 |
Correct |
41 ms |
31756 KB |
Output is correct |
10 |
Correct |
70 ms |
34432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
33112 KB |
Output is correct |
2 |
Correct |
6 ms |
29016 KB |
Output is correct |
3 |
Correct |
6 ms |
33116 KB |
Output is correct |
4 |
Correct |
7 ms |
33268 KB |
Output is correct |
5 |
Correct |
6 ms |
33116 KB |
Output is correct |
6 |
Correct |
8 ms |
33304 KB |
Output is correct |
7 |
Correct |
6 ms |
33116 KB |
Output is correct |
8 |
Correct |
6 ms |
29020 KB |
Output is correct |
9 |
Correct |
7 ms |
29176 KB |
Output is correct |
10 |
Correct |
6 ms |
29172 KB |
Output is correct |
11 |
Correct |
8 ms |
33372 KB |
Output is correct |
12 |
Correct |
9 ms |
33372 KB |
Output is correct |
13 |
Correct |
9 ms |
33372 KB |
Output is correct |
14 |
Correct |
11 ms |
33500 KB |
Output is correct |
15 |
Correct |
10 ms |
33372 KB |
Output is correct |
16 |
Correct |
9 ms |
29408 KB |
Output is correct |
17 |
Correct |
8 ms |
29280 KB |
Output is correct |
18 |
Correct |
9 ms |
29272 KB |
Output is correct |
19 |
Correct |
184 ms |
43560 KB |
Output is correct |
20 |
Correct |
184 ms |
43500 KB |
Output is correct |
21 |
Correct |
156 ms |
43092 KB |
Output is correct |
22 |
Correct |
166 ms |
43048 KB |
Output is correct |
23 |
Correct |
157 ms |
43092 KB |
Output is correct |
24 |
Correct |
128 ms |
38656 KB |
Output is correct |
25 |
Correct |
135 ms |
39044 KB |
Output is correct |
26 |
Correct |
139 ms |
38996 KB |
Output is correct |
27 |
Correct |
147 ms |
38996 KB |
Output is correct |
28 |
Correct |
149 ms |
39512 KB |
Output is correct |
29 |
Correct |
149 ms |
39508 KB |
Output is correct |
30 |
Correct |
149 ms |
39444 KB |
Output is correct |
31 |
Correct |
163 ms |
39456 KB |
Output is correct |
32 |
Correct |
160 ms |
39504 KB |
Output is correct |
33 |
Correct |
151 ms |
39476 KB |
Output is correct |
34 |
Correct |
128 ms |
42576 KB |
Output is correct |
35 |
Correct |
123 ms |
42324 KB |
Output is correct |
36 |
Correct |
120 ms |
42576 KB |
Output is correct |
37 |
Correct |
122 ms |
42564 KB |
Output is correct |
38 |
Correct |
131 ms |
42420 KB |
Output is correct |
39 |
Correct |
137 ms |
38664 KB |
Output is correct |
40 |
Correct |
106 ms |
37892 KB |
Output is correct |
41 |
Correct |
142 ms |
38204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
33112 KB |
Output is correct |
2 |
Correct |
6 ms |
29016 KB |
Output is correct |
3 |
Correct |
6 ms |
33116 KB |
Output is correct |
4 |
Correct |
7 ms |
33268 KB |
Output is correct |
5 |
Correct |
6 ms |
33116 KB |
Output is correct |
6 |
Correct |
8 ms |
33304 KB |
Output is correct |
7 |
Correct |
6 ms |
33116 KB |
Output is correct |
8 |
Correct |
6 ms |
29020 KB |
Output is correct |
9 |
Correct |
7 ms |
29176 KB |
Output is correct |
10 |
Correct |
6 ms |
29172 KB |
Output is correct |
11 |
Correct |
8 ms |
33372 KB |
Output is correct |
12 |
Correct |
9 ms |
33372 KB |
Output is correct |
13 |
Correct |
9 ms |
33372 KB |
Output is correct |
14 |
Correct |
11 ms |
33500 KB |
Output is correct |
15 |
Correct |
10 ms |
33372 KB |
Output is correct |
16 |
Correct |
9 ms |
29408 KB |
Output is correct |
17 |
Correct |
8 ms |
29280 KB |
Output is correct |
18 |
Correct |
9 ms |
29272 KB |
Output is correct |
19 |
Correct |
1031 ms |
78164 KB |
Output is correct |
20 |
Correct |
1012 ms |
78556 KB |
Output is correct |
21 |
Correct |
1008 ms |
78416 KB |
Output is correct |
22 |
Correct |
1014 ms |
78676 KB |
Output is correct |
23 |
Correct |
918 ms |
72012 KB |
Output is correct |
24 |
Correct |
90 ms |
38972 KB |
Output is correct |
25 |
Correct |
78 ms |
38724 KB |
Output is correct |
26 |
Correct |
71 ms |
34740 KB |
Output is correct |
27 |
Correct |
71 ms |
34896 KB |
Output is correct |
28 |
Correct |
71 ms |
34776 KB |
Output is correct |
29 |
Correct |
61 ms |
38484 KB |
Output is correct |
30 |
Correct |
64 ms |
38480 KB |
Output is correct |
31 |
Correct |
69 ms |
34568 KB |
Output is correct |
32 |
Correct |
41 ms |
31756 KB |
Output is correct |
33 |
Correct |
70 ms |
34432 KB |
Output is correct |
34 |
Correct |
184 ms |
43560 KB |
Output is correct |
35 |
Correct |
184 ms |
43500 KB |
Output is correct |
36 |
Correct |
156 ms |
43092 KB |
Output is correct |
37 |
Correct |
166 ms |
43048 KB |
Output is correct |
38 |
Correct |
157 ms |
43092 KB |
Output is correct |
39 |
Correct |
128 ms |
38656 KB |
Output is correct |
40 |
Correct |
135 ms |
39044 KB |
Output is correct |
41 |
Correct |
139 ms |
38996 KB |
Output is correct |
42 |
Correct |
147 ms |
38996 KB |
Output is correct |
43 |
Correct |
149 ms |
39512 KB |
Output is correct |
44 |
Correct |
149 ms |
39508 KB |
Output is correct |
45 |
Correct |
149 ms |
39444 KB |
Output is correct |
46 |
Correct |
163 ms |
39456 KB |
Output is correct |
47 |
Correct |
160 ms |
39504 KB |
Output is correct |
48 |
Correct |
151 ms |
39476 KB |
Output is correct |
49 |
Correct |
128 ms |
42576 KB |
Output is correct |
50 |
Correct |
123 ms |
42324 KB |
Output is correct |
51 |
Correct |
120 ms |
42576 KB |
Output is correct |
52 |
Correct |
122 ms |
42564 KB |
Output is correct |
53 |
Correct |
131 ms |
42420 KB |
Output is correct |
54 |
Correct |
137 ms |
38664 KB |
Output is correct |
55 |
Correct |
106 ms |
37892 KB |
Output is correct |
56 |
Correct |
142 ms |
38204 KB |
Output is correct |
57 |
Correct |
1089 ms |
78400 KB |
Output is correct |
58 |
Correct |
1020 ms |
78212 KB |
Output is correct |
59 |
Correct |
947 ms |
76824 KB |
Output is correct |
60 |
Correct |
912 ms |
76852 KB |
Output is correct |
61 |
Correct |
973 ms |
77320 KB |
Output is correct |
62 |
Correct |
933 ms |
76788 KB |
Output is correct |
63 |
Correct |
619 ms |
67876 KB |
Output is correct |
64 |
Correct |
624 ms |
67884 KB |
Output is correct |
65 |
Correct |
833 ms |
69716 KB |
Output is correct |
66 |
Correct |
817 ms |
69992 KB |
Output is correct |
67 |
Correct |
830 ms |
69972 KB |
Output is correct |
68 |
Correct |
897 ms |
71308 KB |
Output is correct |
69 |
Correct |
952 ms |
71568 KB |
Output is correct |
70 |
Correct |
923 ms |
71120 KB |
Output is correct |
71 |
Correct |
899 ms |
71000 KB |
Output is correct |
72 |
Correct |
905 ms |
71180 KB |
Output is correct |
73 |
Correct |
584 ms |
68560 KB |
Output is correct |
74 |
Correct |
595 ms |
69016 KB |
Output is correct |
75 |
Correct |
581 ms |
53712 KB |
Output is correct |
76 |
Correct |
616 ms |
53180 KB |
Output is correct |
77 |
Correct |
587 ms |
53076 KB |
Output is correct |
78 |
Correct |
790 ms |
54996 KB |
Output is correct |
79 |
Correct |
552 ms |
50552 KB |
Output is correct |
80 |
Correct |
772 ms |
53420 KB |
Output is correct |