#include <bits/stdc++.h>
//#define int long long
using namespace std;
const int N = 1e6 + 7;
int a[N], mx[N], ans[N];
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];
}
stack<int> s;
for(int i = 1; i <= n; i++) {
while(!s.empty() && a[s.top()] <= a[i])s.pop();
if(s.empty())mx[i] = 0;
else mx[i] = s.top();
s.push(i);
}
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:52:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<node>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for(int j = 0; j < qu[i].size(); j++) {
| ~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
23896 KB |
Output is correct |
2 |
Correct |
10 ms |
23900 KB |
Output is correct |
3 |
Correct |
9 ms |
23900 KB |
Output is correct |
4 |
Correct |
11 ms |
23896 KB |
Output is correct |
5 |
Correct |
10 ms |
23960 KB |
Output is correct |
6 |
Correct |
11 ms |
23840 KB |
Output is correct |
7 |
Correct |
9 ms |
23900 KB |
Output is correct |
8 |
Correct |
10 ms |
23900 KB |
Output is correct |
9 |
Correct |
10 ms |
23896 KB |
Output is correct |
10 |
Correct |
9 ms |
23900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
23896 KB |
Output is correct |
2 |
Correct |
10 ms |
23900 KB |
Output is correct |
3 |
Correct |
9 ms |
23900 KB |
Output is correct |
4 |
Correct |
11 ms |
23896 KB |
Output is correct |
5 |
Correct |
10 ms |
23960 KB |
Output is correct |
6 |
Correct |
11 ms |
23840 KB |
Output is correct |
7 |
Correct |
9 ms |
23900 KB |
Output is correct |
8 |
Correct |
10 ms |
23900 KB |
Output is correct |
9 |
Correct |
10 ms |
23896 KB |
Output is correct |
10 |
Correct |
9 ms |
23900 KB |
Output is correct |
11 |
Correct |
11 ms |
23900 KB |
Output is correct |
12 |
Correct |
13 ms |
24156 KB |
Output is correct |
13 |
Correct |
13 ms |
24156 KB |
Output is correct |
14 |
Correct |
13 ms |
24156 KB |
Output is correct |
15 |
Correct |
14 ms |
24340 KB |
Output is correct |
16 |
Correct |
12 ms |
24156 KB |
Output is correct |
17 |
Correct |
12 ms |
24256 KB |
Output is correct |
18 |
Correct |
13 ms |
24156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
920 ms |
99424 KB |
Output is correct |
2 |
Correct |
881 ms |
100432 KB |
Output is correct |
3 |
Correct |
873 ms |
100260 KB |
Output is correct |
4 |
Correct |
873 ms |
100432 KB |
Output is correct |
5 |
Correct |
766 ms |
92244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
70 ms |
30292 KB |
Output is correct |
2 |
Correct |
70 ms |
30116 KB |
Output is correct |
3 |
Correct |
61 ms |
29264 KB |
Output is correct |
4 |
Correct |
66 ms |
29264 KB |
Output is correct |
5 |
Correct |
64 ms |
29268 KB |
Output is correct |
6 |
Correct |
56 ms |
28752 KB |
Output is correct |
7 |
Correct |
53 ms |
28908 KB |
Output is correct |
8 |
Correct |
61 ms |
28928 KB |
Output is correct |
9 |
Correct |
38 ms |
27156 KB |
Output is correct |
10 |
Correct |
62 ms |
28940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
23896 KB |
Output is correct |
2 |
Correct |
10 ms |
23900 KB |
Output is correct |
3 |
Correct |
9 ms |
23900 KB |
Output is correct |
4 |
Correct |
11 ms |
23896 KB |
Output is correct |
5 |
Correct |
10 ms |
23960 KB |
Output is correct |
6 |
Correct |
11 ms |
23840 KB |
Output is correct |
7 |
Correct |
9 ms |
23900 KB |
Output is correct |
8 |
Correct |
10 ms |
23900 KB |
Output is correct |
9 |
Correct |
10 ms |
23896 KB |
Output is correct |
10 |
Correct |
9 ms |
23900 KB |
Output is correct |
11 |
Correct |
11 ms |
23900 KB |
Output is correct |
12 |
Correct |
13 ms |
24156 KB |
Output is correct |
13 |
Correct |
13 ms |
24156 KB |
Output is correct |
14 |
Correct |
13 ms |
24156 KB |
Output is correct |
15 |
Correct |
14 ms |
24340 KB |
Output is correct |
16 |
Correct |
12 ms |
24156 KB |
Output is correct |
17 |
Correct |
12 ms |
24256 KB |
Output is correct |
18 |
Correct |
13 ms |
24156 KB |
Output is correct |
19 |
Correct |
156 ms |
39508 KB |
Output is correct |
20 |
Correct |
193 ms |
39504 KB |
Output is correct |
21 |
Correct |
142 ms |
38696 KB |
Output is correct |
22 |
Correct |
143 ms |
38992 KB |
Output is correct |
23 |
Correct |
137 ms |
38736 KB |
Output is correct |
24 |
Correct |
121 ms |
36644 KB |
Output is correct |
25 |
Correct |
122 ms |
36676 KB |
Output is correct |
26 |
Correct |
133 ms |
36948 KB |
Output is correct |
27 |
Correct |
134 ms |
36944 KB |
Output is correct |
28 |
Correct |
140 ms |
37152 KB |
Output is correct |
29 |
Correct |
143 ms |
37444 KB |
Output is correct |
30 |
Correct |
143 ms |
37464 KB |
Output is correct |
31 |
Correct |
144 ms |
37460 KB |
Output is correct |
32 |
Correct |
140 ms |
37396 KB |
Output is correct |
33 |
Correct |
145 ms |
37460 KB |
Output is correct |
34 |
Correct |
114 ms |
36060 KB |
Output is correct |
35 |
Correct |
121 ms |
36156 KB |
Output is correct |
36 |
Correct |
113 ms |
35920 KB |
Output is correct |
37 |
Correct |
106 ms |
35920 KB |
Output is correct |
38 |
Correct |
114 ms |
36156 KB |
Output is correct |
39 |
Correct |
120 ms |
36360 KB |
Output is correct |
40 |
Correct |
118 ms |
34048 KB |
Output is correct |
41 |
Correct |
131 ms |
35584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
23896 KB |
Output is correct |
2 |
Correct |
10 ms |
23900 KB |
Output is correct |
3 |
Correct |
9 ms |
23900 KB |
Output is correct |
4 |
Correct |
11 ms |
23896 KB |
Output is correct |
5 |
Correct |
10 ms |
23960 KB |
Output is correct |
6 |
Correct |
11 ms |
23840 KB |
Output is correct |
7 |
Correct |
9 ms |
23900 KB |
Output is correct |
8 |
Correct |
10 ms |
23900 KB |
Output is correct |
9 |
Correct |
10 ms |
23896 KB |
Output is correct |
10 |
Correct |
9 ms |
23900 KB |
Output is correct |
11 |
Correct |
11 ms |
23900 KB |
Output is correct |
12 |
Correct |
13 ms |
24156 KB |
Output is correct |
13 |
Correct |
13 ms |
24156 KB |
Output is correct |
14 |
Correct |
13 ms |
24156 KB |
Output is correct |
15 |
Correct |
14 ms |
24340 KB |
Output is correct |
16 |
Correct |
12 ms |
24156 KB |
Output is correct |
17 |
Correct |
12 ms |
24256 KB |
Output is correct |
18 |
Correct |
13 ms |
24156 KB |
Output is correct |
19 |
Correct |
920 ms |
99424 KB |
Output is correct |
20 |
Correct |
881 ms |
100432 KB |
Output is correct |
21 |
Correct |
873 ms |
100260 KB |
Output is correct |
22 |
Correct |
873 ms |
100432 KB |
Output is correct |
23 |
Correct |
766 ms |
92244 KB |
Output is correct |
24 |
Correct |
70 ms |
30292 KB |
Output is correct |
25 |
Correct |
70 ms |
30116 KB |
Output is correct |
26 |
Correct |
61 ms |
29264 KB |
Output is correct |
27 |
Correct |
66 ms |
29264 KB |
Output is correct |
28 |
Correct |
64 ms |
29268 KB |
Output is correct |
29 |
Correct |
56 ms |
28752 KB |
Output is correct |
30 |
Correct |
53 ms |
28908 KB |
Output is correct |
31 |
Correct |
61 ms |
28928 KB |
Output is correct |
32 |
Correct |
38 ms |
27156 KB |
Output is correct |
33 |
Correct |
62 ms |
28940 KB |
Output is correct |
34 |
Correct |
156 ms |
39508 KB |
Output is correct |
35 |
Correct |
193 ms |
39504 KB |
Output is correct |
36 |
Correct |
142 ms |
38696 KB |
Output is correct |
37 |
Correct |
143 ms |
38992 KB |
Output is correct |
38 |
Correct |
137 ms |
38736 KB |
Output is correct |
39 |
Correct |
121 ms |
36644 KB |
Output is correct |
40 |
Correct |
122 ms |
36676 KB |
Output is correct |
41 |
Correct |
133 ms |
36948 KB |
Output is correct |
42 |
Correct |
134 ms |
36944 KB |
Output is correct |
43 |
Correct |
140 ms |
37152 KB |
Output is correct |
44 |
Correct |
143 ms |
37444 KB |
Output is correct |
45 |
Correct |
143 ms |
37464 KB |
Output is correct |
46 |
Correct |
144 ms |
37460 KB |
Output is correct |
47 |
Correct |
140 ms |
37396 KB |
Output is correct |
48 |
Correct |
145 ms |
37460 KB |
Output is correct |
49 |
Correct |
114 ms |
36060 KB |
Output is correct |
50 |
Correct |
121 ms |
36156 KB |
Output is correct |
51 |
Correct |
113 ms |
35920 KB |
Output is correct |
52 |
Correct |
106 ms |
35920 KB |
Output is correct |
53 |
Correct |
114 ms |
36156 KB |
Output is correct |
54 |
Correct |
120 ms |
36360 KB |
Output is correct |
55 |
Correct |
118 ms |
34048 KB |
Output is correct |
56 |
Correct |
131 ms |
35584 KB |
Output is correct |
57 |
Correct |
918 ms |
100540 KB |
Output is correct |
58 |
Correct |
887 ms |
100436 KB |
Output is correct |
59 |
Correct |
818 ms |
98896 KB |
Output is correct |
60 |
Correct |
940 ms |
98896 KB |
Output is correct |
61 |
Correct |
836 ms |
98904 KB |
Output is correct |
62 |
Correct |
858 ms |
98900 KB |
Output is correct |
63 |
Correct |
564 ms |
87636 KB |
Output is correct |
64 |
Correct |
581 ms |
87604 KB |
Output is correct |
65 |
Correct |
711 ms |
90616 KB |
Output is correct |
66 |
Correct |
707 ms |
90916 KB |
Output is correct |
67 |
Correct |
725 ms |
90708 KB |
Output is correct |
68 |
Correct |
797 ms |
92416 KB |
Output is correct |
69 |
Correct |
854 ms |
92244 KB |
Output is correct |
70 |
Correct |
905 ms |
92068 KB |
Output is correct |
71 |
Correct |
957 ms |
91912 KB |
Output is correct |
72 |
Correct |
947 ms |
91960 KB |
Output is correct |
73 |
Correct |
606 ms |
83540 KB |
Output is correct |
74 |
Correct |
556 ms |
84412 KB |
Output is correct |
75 |
Correct |
542 ms |
83540 KB |
Output is correct |
76 |
Correct |
553 ms |
83536 KB |
Output is correct |
77 |
Correct |
537 ms |
83304 KB |
Output is correct |
78 |
Correct |
663 ms |
87040 KB |
Output is correct |
79 |
Correct |
524 ms |
73560 KB |
Output is correct |
80 |
Correct |
670 ms |
81648 KB |
Output is correct |