#include <bits/stdc++.h>
//#define int long long
using namespace std;
const int N = 1e6 + 7;
int a[N], lg[N + 1], s[21][N + 1], mx[N], ans[N];
int get(int l, int r) {
if(l > r)return 0;
int le = lg[r - l + 1];
return max(s[l][le], s[r - (1 << le) + 1][le]);
}
struct node {
int l, k, in;
};
vector<node> qu[N];
int tr[4 * N];
void upd(int i, int x, int v, int lx, int rx) {
if(lx == rx) {
tr[v] = max(tr[v], x);
if(x == 0)tr[v] = 0;
return;
}
int m = (lx + rx) >> 1;
if(i <= m)upd(i, x, v + v, lx, m);
else upd(i, x, v + v + 1, m + 1, rx);
tr[v] = max(tr[v + v], tr[v + v + 1]);
}
int get(int l, int r, int v, int lx, int rx) {
if(lx > r || l > rx)return 0;
if(lx >= l && r >= rx)return tr[v];
int m = (lx + rx) >> 1;
return max(get(l, r, v + v, lx, m), get(l, r, v + v + 1, m + 1, rx));
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, m;
cin>>n>>m;
for(int i = 1; i <= n; i++) {
cin>>a[i];
upd(i, a[i], 1, 1, n);
}
for(int i = 1; i <= n; i++) {
if(get(1, i - 1, 1, 1, n) <= a[i]) {
mx[i] = 0;
continue;
}
int l = 1, r = i - 1, res = 0;
while(l <= r) {
int m = (l + r) >> 1;
if(get(m, i - 1, 1, 1, n) > a[i])l = m + 1, res = m;
else r = m - 1;
}
mx[i] = res;
}
for(int i = 1; i <= n; i++)upd(i, 0, 1, 1, n);
for(int i = 1; i <= m; i++) {
int l, r, k;
cin>>l>>r>>k;
qu[r].push_back({l, k, i});
}
//хахахахаха, буквально второй парой каждой позиции, при том что мы хотим увеличить стоимость, это просто ближайший больший слева. Ведь если есть другой больше слева, который мы можем взять, его можно взять в пару вместе с нашим максом и его)
for(int i = 1; i <= n; i++) {
if(mx[i])upd(mx[i], a[i] + a[mx[i]], 1, 1, n);
for(int j = 0; j < qu[i].size(); j++) {
int l = qu[i][j].l, r = i, k = qu[i][j].k, index = qu[i][j].in;
int mxx = get(l, r, 1, 1, n);
if(mxx > k)ans[index] = 0;
else ans[index] = 1;
}
}
for(int i = 1; i <= m; i++)cout << ans[i] << '\n';
}
Compilation message
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:65:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<node>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for(int j = 0; j < qu[i].size(); j++) {
| ~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
29016 KB |
Output is correct |
2 |
Correct |
4 ms |
29020 KB |
Output is correct |
3 |
Correct |
4 ms |
29020 KB |
Output is correct |
4 |
Correct |
6 ms |
29020 KB |
Output is correct |
5 |
Correct |
4 ms |
29020 KB |
Output is correct |
6 |
Correct |
5 ms |
29020 KB |
Output is correct |
7 |
Correct |
5 ms |
29272 KB |
Output is correct |
8 |
Correct |
5 ms |
29020 KB |
Output is correct |
9 |
Correct |
4 ms |
29020 KB |
Output is correct |
10 |
Correct |
5 ms |
29020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
29016 KB |
Output is correct |
2 |
Correct |
4 ms |
29020 KB |
Output is correct |
3 |
Correct |
4 ms |
29020 KB |
Output is correct |
4 |
Correct |
6 ms |
29020 KB |
Output is correct |
5 |
Correct |
4 ms |
29020 KB |
Output is correct |
6 |
Correct |
5 ms |
29020 KB |
Output is correct |
7 |
Correct |
5 ms |
29272 KB |
Output is correct |
8 |
Correct |
5 ms |
29020 KB |
Output is correct |
9 |
Correct |
4 ms |
29020 KB |
Output is correct |
10 |
Correct |
5 ms |
29020 KB |
Output is correct |
11 |
Correct |
7 ms |
29276 KB |
Output is correct |
12 |
Correct |
13 ms |
29356 KB |
Output is correct |
13 |
Correct |
13 ms |
29276 KB |
Output is correct |
14 |
Correct |
14 ms |
29532 KB |
Output is correct |
15 |
Correct |
15 ms |
29404 KB |
Output is correct |
16 |
Correct |
10 ms |
29276 KB |
Output is correct |
17 |
Correct |
9 ms |
29272 KB |
Output is correct |
18 |
Correct |
15 ms |
29276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3075 ms |
54612 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
298 ms |
38480 KB |
Output is correct |
2 |
Correct |
298 ms |
38228 KB |
Output is correct |
3 |
Correct |
79 ms |
39576 KB |
Output is correct |
4 |
Correct |
85 ms |
39580 KB |
Output is correct |
5 |
Correct |
79 ms |
39764 KB |
Output is correct |
6 |
Correct |
94 ms |
38996 KB |
Output is correct |
7 |
Correct |
106 ms |
39200 KB |
Output is correct |
8 |
Correct |
286 ms |
37968 KB |
Output is correct |
9 |
Correct |
39 ms |
34064 KB |
Output is correct |
10 |
Correct |
230 ms |
37900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
29016 KB |
Output is correct |
2 |
Correct |
4 ms |
29020 KB |
Output is correct |
3 |
Correct |
4 ms |
29020 KB |
Output is correct |
4 |
Correct |
6 ms |
29020 KB |
Output is correct |
5 |
Correct |
4 ms |
29020 KB |
Output is correct |
6 |
Correct |
5 ms |
29020 KB |
Output is correct |
7 |
Correct |
5 ms |
29272 KB |
Output is correct |
8 |
Correct |
5 ms |
29020 KB |
Output is correct |
9 |
Correct |
4 ms |
29020 KB |
Output is correct |
10 |
Correct |
5 ms |
29020 KB |
Output is correct |
11 |
Correct |
7 ms |
29276 KB |
Output is correct |
12 |
Correct |
13 ms |
29356 KB |
Output is correct |
13 |
Correct |
13 ms |
29276 KB |
Output is correct |
14 |
Correct |
14 ms |
29532 KB |
Output is correct |
15 |
Correct |
15 ms |
29404 KB |
Output is correct |
16 |
Correct |
10 ms |
29276 KB |
Output is correct |
17 |
Correct |
9 ms |
29272 KB |
Output is correct |
18 |
Correct |
15 ms |
29276 KB |
Output is correct |
19 |
Correct |
672 ms |
48464 KB |
Output is correct |
20 |
Correct |
678 ms |
48540 KB |
Output is correct |
21 |
Correct |
679 ms |
47932 KB |
Output is correct |
22 |
Correct |
723 ms |
47952 KB |
Output is correct |
23 |
Correct |
674 ms |
47696 KB |
Output is correct |
24 |
Correct |
161 ms |
47700 KB |
Output is correct |
25 |
Correct |
161 ms |
47700 KB |
Output is correct |
26 |
Correct |
176 ms |
47952 KB |
Output is correct |
27 |
Correct |
219 ms |
47984 KB |
Output is correct |
28 |
Correct |
184 ms |
48208 KB |
Output is correct |
29 |
Correct |
179 ms |
48468 KB |
Output is correct |
30 |
Correct |
186 ms |
48468 KB |
Output is correct |
31 |
Correct |
167 ms |
48468 KB |
Output is correct |
32 |
Correct |
173 ms |
48464 KB |
Output is correct |
33 |
Correct |
166 ms |
48468 KB |
Output is correct |
34 |
Correct |
153 ms |
47188 KB |
Output is correct |
35 |
Correct |
152 ms |
47208 KB |
Output is correct |
36 |
Correct |
156 ms |
46928 KB |
Output is correct |
37 |
Correct |
178 ms |
46928 KB |
Output is correct |
38 |
Correct |
153 ms |
47188 KB |
Output is correct |
39 |
Correct |
357 ms |
46592 KB |
Output is correct |
40 |
Correct |
209 ms |
44656 KB |
Output is correct |
41 |
Correct |
566 ms |
46244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
29016 KB |
Output is correct |
2 |
Correct |
4 ms |
29020 KB |
Output is correct |
3 |
Correct |
4 ms |
29020 KB |
Output is correct |
4 |
Correct |
6 ms |
29020 KB |
Output is correct |
5 |
Correct |
4 ms |
29020 KB |
Output is correct |
6 |
Correct |
5 ms |
29020 KB |
Output is correct |
7 |
Correct |
5 ms |
29272 KB |
Output is correct |
8 |
Correct |
5 ms |
29020 KB |
Output is correct |
9 |
Correct |
4 ms |
29020 KB |
Output is correct |
10 |
Correct |
5 ms |
29020 KB |
Output is correct |
11 |
Correct |
7 ms |
29276 KB |
Output is correct |
12 |
Correct |
13 ms |
29356 KB |
Output is correct |
13 |
Correct |
13 ms |
29276 KB |
Output is correct |
14 |
Correct |
14 ms |
29532 KB |
Output is correct |
15 |
Correct |
15 ms |
29404 KB |
Output is correct |
16 |
Correct |
10 ms |
29276 KB |
Output is correct |
17 |
Correct |
9 ms |
29272 KB |
Output is correct |
18 |
Correct |
15 ms |
29276 KB |
Output is correct |
19 |
Execution timed out |
3075 ms |
54612 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |