#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];
upd(i, a[i], 1, 1, n);
}
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 <= 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:54:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<node>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | for(int j = 0; j < qu[i].size(); j++) {
| ~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 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 |
5 ms |
29020 KB |
Output is correct |
5 |
Correct |
5 ms |
29020 KB |
Output is correct |
6 |
Correct |
6 ms |
29020 KB |
Output is correct |
7 |
Correct |
5 ms |
29016 KB |
Output is correct |
8 |
Correct |
4 ms |
29020 KB |
Output is correct |
9 |
Correct |
4 ms |
29132 KB |
Output is correct |
10 |
Correct |
5 ms |
29020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 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 |
5 ms |
29020 KB |
Output is correct |
5 |
Correct |
5 ms |
29020 KB |
Output is correct |
6 |
Correct |
6 ms |
29020 KB |
Output is correct |
7 |
Correct |
5 ms |
29016 KB |
Output is correct |
8 |
Correct |
4 ms |
29020 KB |
Output is correct |
9 |
Correct |
4 ms |
29132 KB |
Output is correct |
10 |
Correct |
5 ms |
29020 KB |
Output is correct |
11 |
Correct |
5 ms |
29276 KB |
Output is correct |
12 |
Correct |
6 ms |
29276 KB |
Output is correct |
13 |
Correct |
7 ms |
29272 KB |
Output is correct |
14 |
Correct |
8 ms |
29276 KB |
Output is correct |
15 |
Correct |
12 ms |
29272 KB |
Output is correct |
16 |
Correct |
10 ms |
29528 KB |
Output is correct |
17 |
Correct |
6 ms |
29276 KB |
Output is correct |
18 |
Correct |
6 ms |
29276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1138 ms |
90332 KB |
Output is correct |
2 |
Correct |
1020 ms |
101456 KB |
Output is correct |
3 |
Correct |
1060 ms |
101312 KB |
Output is correct |
4 |
Correct |
1092 ms |
101476 KB |
Output is correct |
5 |
Correct |
950 ms |
101456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
77 ms |
36432 KB |
Output is correct |
2 |
Correct |
74 ms |
36384 KB |
Output is correct |
3 |
Correct |
69 ms |
37716 KB |
Output is correct |
4 |
Correct |
74 ms |
37712 KB |
Output is correct |
5 |
Correct |
69 ms |
37716 KB |
Output is correct |
6 |
Correct |
62 ms |
37200 KB |
Output is correct |
7 |
Correct |
60 ms |
37204 KB |
Output is correct |
8 |
Correct |
69 ms |
36364 KB |
Output is correct |
9 |
Correct |
26 ms |
32784 KB |
Output is correct |
10 |
Correct |
74 ms |
36364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 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 |
5 ms |
29020 KB |
Output is correct |
5 |
Correct |
5 ms |
29020 KB |
Output is correct |
6 |
Correct |
6 ms |
29020 KB |
Output is correct |
7 |
Correct |
5 ms |
29016 KB |
Output is correct |
8 |
Correct |
4 ms |
29020 KB |
Output is correct |
9 |
Correct |
4 ms |
29132 KB |
Output is correct |
10 |
Correct |
5 ms |
29020 KB |
Output is correct |
11 |
Correct |
5 ms |
29276 KB |
Output is correct |
12 |
Correct |
6 ms |
29276 KB |
Output is correct |
13 |
Correct |
7 ms |
29272 KB |
Output is correct |
14 |
Correct |
8 ms |
29276 KB |
Output is correct |
15 |
Correct |
12 ms |
29272 KB |
Output is correct |
16 |
Correct |
10 ms |
29528 KB |
Output is correct |
17 |
Correct |
6 ms |
29276 KB |
Output is correct |
18 |
Correct |
6 ms |
29276 KB |
Output is correct |
19 |
Correct |
173 ms |
41812 KB |
Output is correct |
20 |
Correct |
184 ms |
41988 KB |
Output is correct |
21 |
Correct |
168 ms |
41476 KB |
Output is correct |
22 |
Correct |
158 ms |
41296 KB |
Output is correct |
23 |
Correct |
170 ms |
41424 KB |
Output is correct |
24 |
Correct |
142 ms |
41296 KB |
Output is correct |
25 |
Correct |
141 ms |
41296 KB |
Output is correct |
26 |
Correct |
145 ms |
41552 KB |
Output is correct |
27 |
Correct |
148 ms |
41556 KB |
Output is correct |
28 |
Correct |
147 ms |
41552 KB |
Output is correct |
29 |
Correct |
155 ms |
41888 KB |
Output is correct |
30 |
Correct |
157 ms |
41812 KB |
Output is correct |
31 |
Correct |
166 ms |
42068 KB |
Output is correct |
32 |
Correct |
153 ms |
41812 KB |
Output is correct |
33 |
Correct |
161 ms |
41892 KB |
Output is correct |
34 |
Correct |
133 ms |
40936 KB |
Output is correct |
35 |
Correct |
133 ms |
40960 KB |
Output is correct |
36 |
Correct |
131 ms |
41044 KB |
Output is correct |
37 |
Correct |
127 ms |
41040 KB |
Output is correct |
38 |
Correct |
135 ms |
41044 KB |
Output is correct |
39 |
Correct |
152 ms |
41672 KB |
Output is correct |
40 |
Correct |
105 ms |
40212 KB |
Output is correct |
41 |
Correct |
139 ms |
41476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 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 |
5 ms |
29020 KB |
Output is correct |
5 |
Correct |
5 ms |
29020 KB |
Output is correct |
6 |
Correct |
6 ms |
29020 KB |
Output is correct |
7 |
Correct |
5 ms |
29016 KB |
Output is correct |
8 |
Correct |
4 ms |
29020 KB |
Output is correct |
9 |
Correct |
4 ms |
29132 KB |
Output is correct |
10 |
Correct |
5 ms |
29020 KB |
Output is correct |
11 |
Correct |
5 ms |
29276 KB |
Output is correct |
12 |
Correct |
6 ms |
29276 KB |
Output is correct |
13 |
Correct |
7 ms |
29272 KB |
Output is correct |
14 |
Correct |
8 ms |
29276 KB |
Output is correct |
15 |
Correct |
12 ms |
29272 KB |
Output is correct |
16 |
Correct |
10 ms |
29528 KB |
Output is correct |
17 |
Correct |
6 ms |
29276 KB |
Output is correct |
18 |
Correct |
6 ms |
29276 KB |
Output is correct |
19 |
Correct |
1138 ms |
90332 KB |
Output is correct |
20 |
Correct |
1020 ms |
101456 KB |
Output is correct |
21 |
Correct |
1060 ms |
101312 KB |
Output is correct |
22 |
Correct |
1092 ms |
101476 KB |
Output is correct |
23 |
Correct |
950 ms |
101456 KB |
Output is correct |
24 |
Correct |
77 ms |
36432 KB |
Output is correct |
25 |
Correct |
74 ms |
36384 KB |
Output is correct |
26 |
Correct |
69 ms |
37716 KB |
Output is correct |
27 |
Correct |
74 ms |
37712 KB |
Output is correct |
28 |
Correct |
69 ms |
37716 KB |
Output is correct |
29 |
Correct |
62 ms |
37200 KB |
Output is correct |
30 |
Correct |
60 ms |
37204 KB |
Output is correct |
31 |
Correct |
69 ms |
36364 KB |
Output is correct |
32 |
Correct |
26 ms |
32784 KB |
Output is correct |
33 |
Correct |
74 ms |
36364 KB |
Output is correct |
34 |
Correct |
173 ms |
41812 KB |
Output is correct |
35 |
Correct |
184 ms |
41988 KB |
Output is correct |
36 |
Correct |
168 ms |
41476 KB |
Output is correct |
37 |
Correct |
158 ms |
41296 KB |
Output is correct |
38 |
Correct |
170 ms |
41424 KB |
Output is correct |
39 |
Correct |
142 ms |
41296 KB |
Output is correct |
40 |
Correct |
141 ms |
41296 KB |
Output is correct |
41 |
Correct |
145 ms |
41552 KB |
Output is correct |
42 |
Correct |
148 ms |
41556 KB |
Output is correct |
43 |
Correct |
147 ms |
41552 KB |
Output is correct |
44 |
Correct |
155 ms |
41888 KB |
Output is correct |
45 |
Correct |
157 ms |
41812 KB |
Output is correct |
46 |
Correct |
166 ms |
42068 KB |
Output is correct |
47 |
Correct |
153 ms |
41812 KB |
Output is correct |
48 |
Correct |
161 ms |
41892 KB |
Output is correct |
49 |
Correct |
133 ms |
40936 KB |
Output is correct |
50 |
Correct |
133 ms |
40960 KB |
Output is correct |
51 |
Correct |
131 ms |
41044 KB |
Output is correct |
52 |
Correct |
127 ms |
41040 KB |
Output is correct |
53 |
Correct |
135 ms |
41044 KB |
Output is correct |
54 |
Correct |
152 ms |
41672 KB |
Output is correct |
55 |
Correct |
105 ms |
40212 KB |
Output is correct |
56 |
Correct |
139 ms |
41476 KB |
Output is correct |
57 |
Correct |
1069 ms |
101716 KB |
Output is correct |
58 |
Correct |
986 ms |
101580 KB |
Output is correct |
59 |
Correct |
983 ms |
100148 KB |
Output is correct |
60 |
Correct |
983 ms |
100180 KB |
Output is correct |
61 |
Correct |
932 ms |
100180 KB |
Output is correct |
62 |
Correct |
972 ms |
100236 KB |
Output is correct |
63 |
Correct |
748 ms |
96852 KB |
Output is correct |
64 |
Correct |
731 ms |
96852 KB |
Output is correct |
65 |
Correct |
883 ms |
99900 KB |
Output is correct |
66 |
Correct |
858 ms |
99876 KB |
Output is correct |
67 |
Correct |
849 ms |
100048 KB |
Output is correct |
68 |
Correct |
941 ms |
101600 KB |
Output is correct |
69 |
Correct |
935 ms |
101716 KB |
Output is correct |
70 |
Correct |
910 ms |
101460 KB |
Output is correct |
71 |
Correct |
932 ms |
101460 KB |
Output is correct |
72 |
Correct |
943 ms |
101344 KB |
Output is correct |
73 |
Correct |
743 ms |
92712 KB |
Output is correct |
74 |
Correct |
675 ms |
93780 KB |
Output is correct |
75 |
Correct |
733 ms |
92752 KB |
Output is correct |
76 |
Correct |
672 ms |
93008 KB |
Output is correct |
77 |
Correct |
695 ms |
92760 KB |
Output is correct |
78 |
Correct |
919 ms |
93920 KB |
Output is correct |
79 |
Correct |
592 ms |
81144 KB |
Output is correct |
80 |
Correct |
806 ms |
91368 KB |
Output is correct |