#include <bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
size_t n, m;
cin >> n >> m;
size_t l = 1 << (32 - __builtin_clz(n));
vector<vector<unsigned>> tree(2 * l);
vector<unsigned> max_inv(2 * l, 0);
for (size_t i = 0; i < n; i++)
{
unsigned x;
cin >> x;
tree[l + i] = {x};
}
for (size_t i = n; i < l; i++)
tree[l + i] = {UINT_MAX / 2};
for (size_t i = l - 1; i; i--)
{
auto it = tree[2 * i].begin();
auto jt = tree[2 * i + 1].begin();
while (it != tree[2 * i].end() && jt != tree[2 * i + 1].end())
{
if (*it < *jt)
tree[i].push_back(*it++);
else
tree[i].push_back(*jt++);
}
while (it != tree[2 * i].end())
tree[i].push_back(*it++);
while (jt != tree[2 * i + 1].end())
tree[i].push_back(*jt++);
max_inv[i] = max(max_inv[2 * i], max_inv[2 * i + 1]);
jt = lower_bound(tree[2 * i + 1].begin(), tree[2 * i + 1].end(), tree[2 * i].back());
if (jt != tree[2 * i + 1].begin())
max_inv[i] = max(max_inv[i], tree[2 * i].back() + *(jt - 1));
}
for (size_t i = 0; i < m; i++)
{
size_t u, v;
unsigned k, y = 0, z = 0;
cin >> u >> v >> k;
u += l - 1, v += l - 1;
vector<size_t> comb1, comb2;
while (u <= v)
{
if (u & 1)
comb1.push_back(u++);
if (!(v & 1))
comb2.push_back(v--);
u >>= 1;
v >>= 1;
}
for (auto it = comb1.begin(); it != comb1.end(); it++)
{
z = max(z, max_inv[*it]);
auto jt = lower_bound(tree[*it].begin(), tree[*it].end(), y);
if (jt != tree[*it].begin())
z = max(z, y + *(jt - 1));
y = max(y, tree[*it].back());
}
for (auto it = comb2.rbegin(); it != comb2.rend(); it++)
{
z = max(z, max_inv[*it]);
auto jt = lower_bound(tree[*it].begin(), tree[*it].end(), y);
if (jt != tree[*it].begin())
z = max(z, y + *(jt - 1));
y = max(y, tree[*it].back());
}
cout << (int)(z <= k) << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
3 ms |
596 KB |
Output is correct |
12 |
Correct |
6 ms |
1748 KB |
Output is correct |
13 |
Correct |
6 ms |
1688 KB |
Output is correct |
14 |
Correct |
8 ms |
1736 KB |
Output is correct |
15 |
Correct |
7 ms |
1748 KB |
Output is correct |
16 |
Correct |
7 ms |
1736 KB |
Output is correct |
17 |
Correct |
5 ms |
1748 KB |
Output is correct |
18 |
Correct |
6 ms |
1620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2783 ms |
195672 KB |
Output is correct |
2 |
Correct |
2757 ms |
196180 KB |
Output is correct |
3 |
Correct |
2789 ms |
196052 KB |
Output is correct |
4 |
Correct |
2729 ms |
196072 KB |
Output is correct |
5 |
Correct |
2511 ms |
196060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
191 ms |
23392 KB |
Output is correct |
2 |
Correct |
173 ms |
25140 KB |
Output is correct |
3 |
Correct |
188 ms |
25228 KB |
Output is correct |
4 |
Correct |
171 ms |
25192 KB |
Output is correct |
5 |
Correct |
168 ms |
25288 KB |
Output is correct |
6 |
Correct |
136 ms |
25140 KB |
Output is correct |
7 |
Correct |
138 ms |
25144 KB |
Output is correct |
8 |
Correct |
145 ms |
24936 KB |
Output is correct |
9 |
Correct |
47 ms |
1928 KB |
Output is correct |
10 |
Correct |
151 ms |
24932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
3 ms |
596 KB |
Output is correct |
12 |
Correct |
6 ms |
1748 KB |
Output is correct |
13 |
Correct |
6 ms |
1688 KB |
Output is correct |
14 |
Correct |
8 ms |
1736 KB |
Output is correct |
15 |
Correct |
7 ms |
1748 KB |
Output is correct |
16 |
Correct |
7 ms |
1736 KB |
Output is correct |
17 |
Correct |
5 ms |
1748 KB |
Output is correct |
18 |
Correct |
6 ms |
1620 KB |
Output is correct |
19 |
Correct |
444 ms |
53952 KB |
Output is correct |
20 |
Correct |
440 ms |
54080 KB |
Output is correct |
21 |
Correct |
409 ms |
53796 KB |
Output is correct |
22 |
Correct |
371 ms |
53836 KB |
Output is correct |
23 |
Correct |
369 ms |
53900 KB |
Output is correct |
24 |
Correct |
315 ms |
53696 KB |
Output is correct |
25 |
Correct |
320 ms |
53856 KB |
Output is correct |
26 |
Correct |
403 ms |
53936 KB |
Output is correct |
27 |
Correct |
389 ms |
53976 KB |
Output is correct |
28 |
Correct |
401 ms |
53972 KB |
Output is correct |
29 |
Correct |
398 ms |
54012 KB |
Output is correct |
30 |
Correct |
406 ms |
53996 KB |
Output is correct |
31 |
Correct |
449 ms |
54028 KB |
Output is correct |
32 |
Correct |
451 ms |
53952 KB |
Output is correct |
33 |
Correct |
397 ms |
53952 KB |
Output is correct |
34 |
Correct |
298 ms |
53732 KB |
Output is correct |
35 |
Correct |
300 ms |
53652 KB |
Output is correct |
36 |
Correct |
295 ms |
53388 KB |
Output is correct |
37 |
Correct |
296 ms |
53540 KB |
Output is correct |
38 |
Correct |
296 ms |
53548 KB |
Output is correct |
39 |
Correct |
357 ms |
52580 KB |
Output is correct |
40 |
Correct |
291 ms |
51904 KB |
Output is correct |
41 |
Correct |
338 ms |
52180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
324 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
3 ms |
596 KB |
Output is correct |
12 |
Correct |
6 ms |
1748 KB |
Output is correct |
13 |
Correct |
6 ms |
1688 KB |
Output is correct |
14 |
Correct |
8 ms |
1736 KB |
Output is correct |
15 |
Correct |
7 ms |
1748 KB |
Output is correct |
16 |
Correct |
7 ms |
1736 KB |
Output is correct |
17 |
Correct |
5 ms |
1748 KB |
Output is correct |
18 |
Correct |
6 ms |
1620 KB |
Output is correct |
19 |
Correct |
2783 ms |
195672 KB |
Output is correct |
20 |
Correct |
2757 ms |
196180 KB |
Output is correct |
21 |
Correct |
2789 ms |
196052 KB |
Output is correct |
22 |
Correct |
2729 ms |
196072 KB |
Output is correct |
23 |
Correct |
2511 ms |
196060 KB |
Output is correct |
24 |
Correct |
191 ms |
23392 KB |
Output is correct |
25 |
Correct |
173 ms |
25140 KB |
Output is correct |
26 |
Correct |
188 ms |
25228 KB |
Output is correct |
27 |
Correct |
171 ms |
25192 KB |
Output is correct |
28 |
Correct |
168 ms |
25288 KB |
Output is correct |
29 |
Correct |
136 ms |
25140 KB |
Output is correct |
30 |
Correct |
138 ms |
25144 KB |
Output is correct |
31 |
Correct |
145 ms |
24936 KB |
Output is correct |
32 |
Correct |
47 ms |
1928 KB |
Output is correct |
33 |
Correct |
151 ms |
24932 KB |
Output is correct |
34 |
Correct |
444 ms |
53952 KB |
Output is correct |
35 |
Correct |
440 ms |
54080 KB |
Output is correct |
36 |
Correct |
409 ms |
53796 KB |
Output is correct |
37 |
Correct |
371 ms |
53836 KB |
Output is correct |
38 |
Correct |
369 ms |
53900 KB |
Output is correct |
39 |
Correct |
315 ms |
53696 KB |
Output is correct |
40 |
Correct |
320 ms |
53856 KB |
Output is correct |
41 |
Correct |
403 ms |
53936 KB |
Output is correct |
42 |
Correct |
389 ms |
53976 KB |
Output is correct |
43 |
Correct |
401 ms |
53972 KB |
Output is correct |
44 |
Correct |
398 ms |
54012 KB |
Output is correct |
45 |
Correct |
406 ms |
53996 KB |
Output is correct |
46 |
Correct |
449 ms |
54028 KB |
Output is correct |
47 |
Correct |
451 ms |
53952 KB |
Output is correct |
48 |
Correct |
397 ms |
53952 KB |
Output is correct |
49 |
Correct |
298 ms |
53732 KB |
Output is correct |
50 |
Correct |
300 ms |
53652 KB |
Output is correct |
51 |
Correct |
295 ms |
53388 KB |
Output is correct |
52 |
Correct |
296 ms |
53540 KB |
Output is correct |
53 |
Correct |
296 ms |
53548 KB |
Output is correct |
54 |
Correct |
357 ms |
52580 KB |
Output is correct |
55 |
Correct |
291 ms |
51904 KB |
Output is correct |
56 |
Correct |
338 ms |
52180 KB |
Output is correct |
57 |
Correct |
2737 ms |
209380 KB |
Output is correct |
58 |
Correct |
2826 ms |
209288 KB |
Output is correct |
59 |
Correct |
2739 ms |
208440 KB |
Output is correct |
60 |
Correct |
2767 ms |
208300 KB |
Output is correct |
61 |
Correct |
2762 ms |
208292 KB |
Output is correct |
62 |
Correct |
2864 ms |
208056 KB |
Output is correct |
63 |
Correct |
1745 ms |
210836 KB |
Output is correct |
64 |
Correct |
1677 ms |
210728 KB |
Output is correct |
65 |
Correct |
2385 ms |
207932 KB |
Output is correct |
66 |
Correct |
2429 ms |
207864 KB |
Output is correct |
67 |
Correct |
2481 ms |
213036 KB |
Output is correct |
68 |
Correct |
2371 ms |
211852 KB |
Output is correct |
69 |
Correct |
2398 ms |
211672 KB |
Output is correct |
70 |
Correct |
2450 ms |
211616 KB |
Output is correct |
71 |
Correct |
2418 ms |
211852 KB |
Output is correct |
72 |
Correct |
2438 ms |
211632 KB |
Output is correct |
73 |
Correct |
1636 ms |
210620 KB |
Output is correct |
74 |
Correct |
1641 ms |
211020 KB |
Output is correct |
75 |
Correct |
1592 ms |
210788 KB |
Output is correct |
76 |
Correct |
1682 ms |
210712 KB |
Output is correct |
77 |
Correct |
1742 ms |
211072 KB |
Output is correct |
78 |
Correct |
2405 ms |
209740 KB |
Output is correct |
79 |
Correct |
1513 ms |
207900 KB |
Output is correct |
80 |
Correct |
2037 ms |
208220 KB |
Output is correct |