#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000005;
int n, q;
int a[maxn];
struct query
{
int l;
int k;
int idx;
query()
{
}
query(int _l, int _k, int _idx)
{
l = _l;
k = _k;
idx = _idx;
}
};
vector<query> queries[maxn];
int answers[maxn];
struct segment_tree
{
struct state
{
int maxv;
int lazy;
};
state tree[4 * maxn];
void push_lazy(int node, int l, int r)
{
if (tree[node].lazy == 0)
{
return;
}
tree[node].maxv = max(tree[node].maxv, tree[node].lazy);
if (l != r)
{
tree[2 * node].lazy = max(tree[2 * node].lazy, tree[node].lazy);
tree[2 * node + 1].lazy = max(tree[2 * node + 1].lazy, tree[node].lazy);
}
tree[node].lazy = 0;
}
void update(int node, int l, int r, int ql, int qr, int val)
{
push_lazy(node, l, r);
if (l > qr || r < ql)
{
return;
}
if (ql <= l && r <= qr)
{
tree[node].lazy = max(tree[node].lazy, val);
push_lazy(node, l, r);
return;
}
int mid = (l + r) / 2;
update(2 * node, l, mid, ql, qr, val);
update(2 * node + 1, mid + 1, r, ql, qr, val);
tree[node].maxv = max(tree[2 * node].maxv, tree[2 * node + 1].maxv);
}
int query(int node, int l, int r, int ql, int qr)
{
push_lazy(node, l, r);
if (l > qr || r < ql)
{
return 0;
}
if (ql <= l && r <= qr)
{
return tree[node].maxv;
}
int mid = (l + r) / 2;
return max(query(2 * node, l, mid, ql, qr), query(2 * node + 1, mid + 1, r, ql, qr));
}
void update(int l, int r, int val)
{
update(1, 1, n, l, r, val);
}
int query(int l, int r)
{
return query(1, 1, n, l, r);
}
};
segment_tree tree;
void fastIO()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int main()
{
fastIO();
cin >> n >> q;
for (int i = 1; i <= n; ++i)
{
cin >> a[i];
}
for (int i = 1; i <= q; ++i)
{
int l, r, k;
cin >> l >> r >> k;
queries[r].push_back(query(l, k, i));
}
stack<int> st;
for (int i = 1; i <= n; ++i)
{
while (!st.empty() && a[st.top()] <= a[i])
{
st.pop();
}
if (!st.empty())
{
tree.update(1, st.top(), a[i] + a[st.top()]);
}
for (int j = 0; j < queries[i].size(); ++j)
{
int l = queries[i][j].l;
int idx = queries[i][j].idx;
if (tree.query(l, i) <= queries[i][j].k)
{
answers[idx] = 1;
}
else
{
answers[idx] = 0;
}
}
st.push(i);
}
for (int i = 1; i <= q; ++i)
{
cout << answers[i] << "\n";
}
return 0;
}
Compilation message
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:156:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<query>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
156 | for (int j = 0; j < queries[i].size(); ++j)
| ~~^~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23716 KB |
Output is correct |
3 |
Correct |
12 ms |
23764 KB |
Output is correct |
4 |
Correct |
12 ms |
23792 KB |
Output is correct |
5 |
Correct |
12 ms |
23764 KB |
Output is correct |
6 |
Correct |
12 ms |
23780 KB |
Output is correct |
7 |
Correct |
12 ms |
23812 KB |
Output is correct |
8 |
Correct |
12 ms |
23764 KB |
Output is correct |
9 |
Correct |
12 ms |
23816 KB |
Output is correct |
10 |
Correct |
12 ms |
23820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23716 KB |
Output is correct |
3 |
Correct |
12 ms |
23764 KB |
Output is correct |
4 |
Correct |
12 ms |
23792 KB |
Output is correct |
5 |
Correct |
12 ms |
23764 KB |
Output is correct |
6 |
Correct |
12 ms |
23780 KB |
Output is correct |
7 |
Correct |
12 ms |
23812 KB |
Output is correct |
8 |
Correct |
12 ms |
23764 KB |
Output is correct |
9 |
Correct |
12 ms |
23816 KB |
Output is correct |
10 |
Correct |
12 ms |
23820 KB |
Output is correct |
11 |
Correct |
13 ms |
23952 KB |
Output is correct |
12 |
Correct |
14 ms |
24084 KB |
Output is correct |
13 |
Correct |
14 ms |
24168 KB |
Output is correct |
14 |
Correct |
17 ms |
24172 KB |
Output is correct |
15 |
Correct |
16 ms |
24212 KB |
Output is correct |
16 |
Correct |
15 ms |
24148 KB |
Output is correct |
17 |
Correct |
15 ms |
24060 KB |
Output is correct |
18 |
Correct |
14 ms |
24152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1241 ms |
71688 KB |
Output is correct |
2 |
Correct |
1356 ms |
72144 KB |
Output is correct |
3 |
Correct |
1278 ms |
72180 KB |
Output is correct |
4 |
Correct |
1333 ms |
72196 KB |
Output is correct |
5 |
Correct |
956 ms |
88340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
93 ms |
28872 KB |
Output is correct |
2 |
Correct |
103 ms |
30604 KB |
Output is correct |
3 |
Correct |
70 ms |
28820 KB |
Output is correct |
4 |
Correct |
76 ms |
28800 KB |
Output is correct |
5 |
Correct |
74 ms |
28848 KB |
Output is correct |
6 |
Correct |
59 ms |
28324 KB |
Output is correct |
7 |
Correct |
59 ms |
28372 KB |
Output is correct |
8 |
Correct |
79 ms |
29820 KB |
Output is correct |
9 |
Correct |
38 ms |
27224 KB |
Output is correct |
10 |
Correct |
73 ms |
30296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23716 KB |
Output is correct |
3 |
Correct |
12 ms |
23764 KB |
Output is correct |
4 |
Correct |
12 ms |
23792 KB |
Output is correct |
5 |
Correct |
12 ms |
23764 KB |
Output is correct |
6 |
Correct |
12 ms |
23780 KB |
Output is correct |
7 |
Correct |
12 ms |
23812 KB |
Output is correct |
8 |
Correct |
12 ms |
23764 KB |
Output is correct |
9 |
Correct |
12 ms |
23816 KB |
Output is correct |
10 |
Correct |
12 ms |
23820 KB |
Output is correct |
11 |
Correct |
13 ms |
23952 KB |
Output is correct |
12 |
Correct |
14 ms |
24084 KB |
Output is correct |
13 |
Correct |
14 ms |
24168 KB |
Output is correct |
14 |
Correct |
17 ms |
24172 KB |
Output is correct |
15 |
Correct |
16 ms |
24212 KB |
Output is correct |
16 |
Correct |
15 ms |
24148 KB |
Output is correct |
17 |
Correct |
15 ms |
24060 KB |
Output is correct |
18 |
Correct |
14 ms |
24152 KB |
Output is correct |
19 |
Correct |
200 ms |
40680 KB |
Output is correct |
20 |
Correct |
207 ms |
40612 KB |
Output is correct |
21 |
Correct |
185 ms |
39996 KB |
Output is correct |
22 |
Correct |
178 ms |
39980 KB |
Output is correct |
23 |
Correct |
175 ms |
39988 KB |
Output is correct |
24 |
Correct |
129 ms |
35848 KB |
Output is correct |
25 |
Correct |
149 ms |
35824 KB |
Output is correct |
26 |
Correct |
146 ms |
36088 KB |
Output is correct |
27 |
Correct |
142 ms |
36140 KB |
Output is correct |
28 |
Correct |
141 ms |
36196 KB |
Output is correct |
29 |
Correct |
162 ms |
36620 KB |
Output is correct |
30 |
Correct |
146 ms |
36556 KB |
Output is correct |
31 |
Correct |
154 ms |
36580 KB |
Output is correct |
32 |
Correct |
167 ms |
36592 KB |
Output is correct |
33 |
Correct |
148 ms |
36472 KB |
Output is correct |
34 |
Correct |
117 ms |
35428 KB |
Output is correct |
35 |
Correct |
124 ms |
35312 KB |
Output is correct |
36 |
Correct |
116 ms |
35148 KB |
Output is correct |
37 |
Correct |
116 ms |
35204 KB |
Output is correct |
38 |
Correct |
122 ms |
35404 KB |
Output is correct |
39 |
Correct |
152 ms |
37508 KB |
Output is correct |
40 |
Correct |
104 ms |
34548 KB |
Output is correct |
41 |
Correct |
185 ms |
37572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23716 KB |
Output is correct |
3 |
Correct |
12 ms |
23764 KB |
Output is correct |
4 |
Correct |
12 ms |
23792 KB |
Output is correct |
5 |
Correct |
12 ms |
23764 KB |
Output is correct |
6 |
Correct |
12 ms |
23780 KB |
Output is correct |
7 |
Correct |
12 ms |
23812 KB |
Output is correct |
8 |
Correct |
12 ms |
23764 KB |
Output is correct |
9 |
Correct |
12 ms |
23816 KB |
Output is correct |
10 |
Correct |
12 ms |
23820 KB |
Output is correct |
11 |
Correct |
13 ms |
23952 KB |
Output is correct |
12 |
Correct |
14 ms |
24084 KB |
Output is correct |
13 |
Correct |
14 ms |
24168 KB |
Output is correct |
14 |
Correct |
17 ms |
24172 KB |
Output is correct |
15 |
Correct |
16 ms |
24212 KB |
Output is correct |
16 |
Correct |
15 ms |
24148 KB |
Output is correct |
17 |
Correct |
15 ms |
24060 KB |
Output is correct |
18 |
Correct |
14 ms |
24152 KB |
Output is correct |
19 |
Correct |
1241 ms |
71688 KB |
Output is correct |
20 |
Correct |
1356 ms |
72144 KB |
Output is correct |
21 |
Correct |
1278 ms |
72180 KB |
Output is correct |
22 |
Correct |
1333 ms |
72196 KB |
Output is correct |
23 |
Correct |
956 ms |
88340 KB |
Output is correct |
24 |
Correct |
93 ms |
28872 KB |
Output is correct |
25 |
Correct |
103 ms |
30604 KB |
Output is correct |
26 |
Correct |
70 ms |
28820 KB |
Output is correct |
27 |
Correct |
76 ms |
28800 KB |
Output is correct |
28 |
Correct |
74 ms |
28848 KB |
Output is correct |
29 |
Correct |
59 ms |
28324 KB |
Output is correct |
30 |
Correct |
59 ms |
28372 KB |
Output is correct |
31 |
Correct |
79 ms |
29820 KB |
Output is correct |
32 |
Correct |
38 ms |
27224 KB |
Output is correct |
33 |
Correct |
73 ms |
30296 KB |
Output is correct |
34 |
Correct |
200 ms |
40680 KB |
Output is correct |
35 |
Correct |
207 ms |
40612 KB |
Output is correct |
36 |
Correct |
185 ms |
39996 KB |
Output is correct |
37 |
Correct |
178 ms |
39980 KB |
Output is correct |
38 |
Correct |
175 ms |
39988 KB |
Output is correct |
39 |
Correct |
129 ms |
35848 KB |
Output is correct |
40 |
Correct |
149 ms |
35824 KB |
Output is correct |
41 |
Correct |
146 ms |
36088 KB |
Output is correct |
42 |
Correct |
142 ms |
36140 KB |
Output is correct |
43 |
Correct |
141 ms |
36196 KB |
Output is correct |
44 |
Correct |
162 ms |
36620 KB |
Output is correct |
45 |
Correct |
146 ms |
36556 KB |
Output is correct |
46 |
Correct |
154 ms |
36580 KB |
Output is correct |
47 |
Correct |
167 ms |
36592 KB |
Output is correct |
48 |
Correct |
148 ms |
36472 KB |
Output is correct |
49 |
Correct |
117 ms |
35428 KB |
Output is correct |
50 |
Correct |
124 ms |
35312 KB |
Output is correct |
51 |
Correct |
116 ms |
35148 KB |
Output is correct |
52 |
Correct |
116 ms |
35204 KB |
Output is correct |
53 |
Correct |
122 ms |
35404 KB |
Output is correct |
54 |
Correct |
152 ms |
37508 KB |
Output is correct |
55 |
Correct |
104 ms |
34548 KB |
Output is correct |
56 |
Correct |
185 ms |
37572 KB |
Output is correct |
57 |
Correct |
1324 ms |
104928 KB |
Output is correct |
58 |
Correct |
1317 ms |
104908 KB |
Output is correct |
59 |
Correct |
1287 ms |
103240 KB |
Output is correct |
60 |
Correct |
1500 ms |
103152 KB |
Output is correct |
61 |
Correct |
1325 ms |
103156 KB |
Output is correct |
62 |
Correct |
1236 ms |
103324 KB |
Output is correct |
63 |
Correct |
618 ms |
83600 KB |
Output is correct |
64 |
Correct |
633 ms |
83552 KB |
Output is correct |
65 |
Correct |
902 ms |
86740 KB |
Output is correct |
66 |
Correct |
882 ms |
86628 KB |
Output is correct |
67 |
Correct |
895 ms |
86664 KB |
Output is correct |
68 |
Correct |
947 ms |
88384 KB |
Output is correct |
69 |
Correct |
933 ms |
88448 KB |
Output is correct |
70 |
Correct |
957 ms |
87984 KB |
Output is correct |
71 |
Correct |
941 ms |
87984 KB |
Output is correct |
72 |
Correct |
934 ms |
87968 KB |
Output is correct |
73 |
Correct |
579 ms |
79468 KB |
Output is correct |
74 |
Correct |
575 ms |
80484 KB |
Output is correct |
75 |
Correct |
582 ms |
79536 KB |
Output is correct |
76 |
Correct |
573 ms |
79804 KB |
Output is correct |
77 |
Correct |
568 ms |
79272 KB |
Output is correct |
78 |
Correct |
951 ms |
91408 KB |
Output is correct |
79 |
Correct |
618 ms |
75756 KB |
Output is correct |
80 |
Correct |
978 ms |
90496 KB |
Output is correct |