#include <bits/stdc++.h>
using namespace std;
const int N = 1000006, INF = 1000000009;
int n, qq;
int a[N];
vector<int> v[N * 4];
void bilv(int tl, int tr, int pos)
{
if (tl == tr)
{
v[pos].push_back(a[tl]);
return;
}
int m = (tl + tr) / 2;
bilv(tl, m, pos * 2);
bilv(m + 1, tr, pos * 2 + 1);
int j = 0;
for (int i = 0; i < v[pos * 2 + 1].size(); ++i)
{
while (j < v[pos * 2].size() && v[pos * 2][j] < v[pos * 2 + 1][i])
{
v[pos].push_back(v[pos * 2][j]);
++j;
}
v[pos].push_back(v[pos * 2 + 1][i]);
}
while (j < v[pos * 2].size())
{
v[pos].push_back(v[pos * 2][j]);
++j;
}
}
struct ban
{
int maxu;
int ans;
ban()
{
maxu = -INF;
ans = -INF;
}
ban(int x)
{
maxu = x;
ans = -INF;
}
};
ban t[N * 4];
ban mer(const ban& l, const ban& r, int pos)
{
ban res;
res.maxu = max(l.maxu, r.maxu);
res.ans = max(l.ans, r.ans);
int i = lower_bound(v[pos].begin(), v[pos].end(), l.maxu) - v[pos].begin();
--i;
if (i >= 0)
res.ans = max(res.ans, l.maxu + v[pos][i]);
return res;
}
void bil(int tl, int tr, int pos)
{
if (tl == tr)
{
t[pos] = ban(a[tl]);
return;
}
int m = (tl + tr) / 2;
bil(tl, m, pos * 2);
bil(m + 1, tr, pos * 2 + 1);
t[pos] = mer(t[pos * 2], t[pos * 2 + 1], pos * 2 + 1);
}
ban ans;
void qry(int tl, int tr, int l, int r, int pos)
{
if (l > r)
return;
if (tl == l && tr == r)
{
ans = mer(ans, t[pos], pos);
return;
}
int m = (tl + tr) / 2;
qry(tl, m, l, min(m, r), pos * 2);
qry(m + 1, tr, max(m + 1, l), r, pos * 2 + 1);
}
int main()
{
scanf("%d%d", &n, &qq);
for (int i = 1; i <= n; ++i)
scanf("%d", &a[i]);
bilv(1, n, 1);
bil(1, n, 1);
while (qq--)
{
int l, r, k;
scanf("%d%d%d", &l, &r, &k);
ans = ban();
qry(1, n, l, r, 1);
if (ans.ans <= k)
printf("1\n");
else
printf("0\n");
}
return 0;
}
Compilation message
sortbooks.cpp: In function 'void bilv(int, int, int)':
sortbooks.cpp:20:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < v[pos * 2 + 1].size(); ++i)
~~^~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:22:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while (j < v[pos * 2].size() && v[pos * 2][j] < v[pos * 2 + 1][i])
~~^~~~~~~~~~~~~~~~~~~
sortbooks.cpp:29:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while (j < v[pos * 2].size())
~~^~~~~~~~~~~~~~~~~~~
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:96:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &qq);
~~~~~^~~~~~~~~~~~~~~~~
sortbooks.cpp:98:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &a[i]);
~~~~~^~~~~~~~~~~~~
sortbooks.cpp:104:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", &l, &r, &k);
~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
116 ms |
125652 KB |
Output is correct |
2 |
Correct |
117 ms |
125688 KB |
Output is correct |
3 |
Correct |
117 ms |
125560 KB |
Output is correct |
4 |
Correct |
115 ms |
125560 KB |
Output is correct |
5 |
Correct |
116 ms |
125624 KB |
Output is correct |
6 |
Correct |
117 ms |
125728 KB |
Output is correct |
7 |
Correct |
115 ms |
125816 KB |
Output is correct |
8 |
Correct |
116 ms |
125560 KB |
Output is correct |
9 |
Correct |
117 ms |
125696 KB |
Output is correct |
10 |
Correct |
118 ms |
125560 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
116 ms |
125652 KB |
Output is correct |
2 |
Correct |
117 ms |
125688 KB |
Output is correct |
3 |
Correct |
117 ms |
125560 KB |
Output is correct |
4 |
Correct |
115 ms |
125560 KB |
Output is correct |
5 |
Correct |
116 ms |
125624 KB |
Output is correct |
6 |
Correct |
117 ms |
125728 KB |
Output is correct |
7 |
Correct |
115 ms |
125816 KB |
Output is correct |
8 |
Correct |
116 ms |
125560 KB |
Output is correct |
9 |
Correct |
117 ms |
125696 KB |
Output is correct |
10 |
Correct |
118 ms |
125560 KB |
Output is correct |
11 |
Correct |
124 ms |
125872 KB |
Output is correct |
12 |
Correct |
139 ms |
126476 KB |
Output is correct |
13 |
Correct |
123 ms |
126300 KB |
Output is correct |
14 |
Correct |
134 ms |
126432 KB |
Output is correct |
15 |
Correct |
163 ms |
126456 KB |
Output is correct |
16 |
Correct |
142 ms |
126328 KB |
Output is correct |
17 |
Correct |
121 ms |
126140 KB |
Output is correct |
18 |
Correct |
123 ms |
126328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
785 ms |
262144 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
367 ms |
140388 KB |
Output is correct |
2 |
Correct |
340 ms |
141552 KB |
Output is correct |
3 |
Correct |
328 ms |
141552 KB |
Output is correct |
4 |
Correct |
327 ms |
141508 KB |
Output is correct |
5 |
Correct |
322 ms |
141424 KB |
Output is correct |
6 |
Correct |
270 ms |
141168 KB |
Output is correct |
7 |
Correct |
272 ms |
141296 KB |
Output is correct |
8 |
Correct |
292 ms |
141040 KB |
Output is correct |
9 |
Correct |
164 ms |
127232 KB |
Output is correct |
10 |
Correct |
293 ms |
141296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
116 ms |
125652 KB |
Output is correct |
2 |
Correct |
117 ms |
125688 KB |
Output is correct |
3 |
Correct |
117 ms |
125560 KB |
Output is correct |
4 |
Correct |
115 ms |
125560 KB |
Output is correct |
5 |
Correct |
116 ms |
125624 KB |
Output is correct |
6 |
Correct |
117 ms |
125728 KB |
Output is correct |
7 |
Correct |
115 ms |
125816 KB |
Output is correct |
8 |
Correct |
116 ms |
125560 KB |
Output is correct |
9 |
Correct |
117 ms |
125696 KB |
Output is correct |
10 |
Correct |
118 ms |
125560 KB |
Output is correct |
11 |
Correct |
124 ms |
125872 KB |
Output is correct |
12 |
Correct |
139 ms |
126476 KB |
Output is correct |
13 |
Correct |
123 ms |
126300 KB |
Output is correct |
14 |
Correct |
134 ms |
126432 KB |
Output is correct |
15 |
Correct |
163 ms |
126456 KB |
Output is correct |
16 |
Correct |
142 ms |
126328 KB |
Output is correct |
17 |
Correct |
121 ms |
126140 KB |
Output is correct |
18 |
Correct |
123 ms |
126328 KB |
Output is correct |
19 |
Correct |
714 ms |
160780 KB |
Output is correct |
20 |
Correct |
752 ms |
160748 KB |
Output is correct |
21 |
Correct |
654 ms |
160556 KB |
Output is correct |
22 |
Correct |
704 ms |
160748 KB |
Output is correct |
23 |
Correct |
690 ms |
160748 KB |
Output is correct |
24 |
Correct |
521 ms |
160452 KB |
Output is correct |
25 |
Correct |
531 ms |
160336 KB |
Output is correct |
26 |
Correct |
623 ms |
160628 KB |
Output is correct |
27 |
Correct |
593 ms |
160620 KB |
Output is correct |
28 |
Correct |
694 ms |
160748 KB |
Output is correct |
29 |
Correct |
613 ms |
160784 KB |
Output is correct |
30 |
Correct |
604 ms |
160764 KB |
Output is correct |
31 |
Correct |
620 ms |
160716 KB |
Output is correct |
32 |
Correct |
667 ms |
160700 KB |
Output is correct |
33 |
Correct |
625 ms |
160740 KB |
Output is correct |
34 |
Correct |
475 ms |
160364 KB |
Output is correct |
35 |
Correct |
474 ms |
160304 KB |
Output is correct |
36 |
Correct |
465 ms |
160108 KB |
Output is correct |
37 |
Correct |
467 ms |
160084 KB |
Output is correct |
38 |
Correct |
489 ms |
160416 KB |
Output is correct |
39 |
Correct |
577 ms |
159368 KB |
Output is correct |
40 |
Correct |
422 ms |
146720 KB |
Output is correct |
41 |
Correct |
616 ms |
158852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
116 ms |
125652 KB |
Output is correct |
2 |
Correct |
117 ms |
125688 KB |
Output is correct |
3 |
Correct |
117 ms |
125560 KB |
Output is correct |
4 |
Correct |
115 ms |
125560 KB |
Output is correct |
5 |
Correct |
116 ms |
125624 KB |
Output is correct |
6 |
Correct |
117 ms |
125728 KB |
Output is correct |
7 |
Correct |
115 ms |
125816 KB |
Output is correct |
8 |
Correct |
116 ms |
125560 KB |
Output is correct |
9 |
Correct |
117 ms |
125696 KB |
Output is correct |
10 |
Correct |
118 ms |
125560 KB |
Output is correct |
11 |
Correct |
124 ms |
125872 KB |
Output is correct |
12 |
Correct |
139 ms |
126476 KB |
Output is correct |
13 |
Correct |
123 ms |
126300 KB |
Output is correct |
14 |
Correct |
134 ms |
126432 KB |
Output is correct |
15 |
Correct |
163 ms |
126456 KB |
Output is correct |
16 |
Correct |
142 ms |
126328 KB |
Output is correct |
17 |
Correct |
121 ms |
126140 KB |
Output is correct |
18 |
Correct |
123 ms |
126328 KB |
Output is correct |
19 |
Runtime error |
785 ms |
262144 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
20 |
Halted |
0 ms |
0 KB |
- |