#include<bits/stdc++.h>
#define STIZE(x) fprintf(stderr, "STIZE%d\n", x);
#define PRINT(x) fprintf(stderr, "%s = %d\n", #x, x);
#define NL(x) printf("%c", " \n"[(x)]);
#define lld long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define mid (l+r)/2
#define endl '\n'
#define all(a) begin(a),end(a)
#define sz(a) int((a).size())
#define LINF 1000000000000000LL
#define INF 1000000000
#define EPS 1e-9
using namespace std;
#define MAXN 1000005
int N, M, a[MAXN], rez[MAXN], seg[8*MAXN];
stack<int> st;
vector<pii> p;
struct Query{
int l, r, k, idx;
}q[MAXN];
void update(int node, int l, int r, int idx, int val) {
if(l == r) {
seg[node] = max(seg[node], val);
return;
}
if(idx <= mid) update(2*node, l, mid, idx, val);
else update(2*node+1, mid+1, r, idx, val);
seg[node] = max(seg[2*node], seg[2*node+1]);
}
int query(int node, int l, int r, int L, int R) {
if(L <= l && r <= R) return seg[node];
int rez = 0;
if(L <= mid) rez = max(rez, query(2*node, l, mid, L, R));
if(R > mid) rez = max(rez, query(2*node+1, mid+1, r, L, R));
return rez;
}
bool cmp1(Query a, Query b) {
return a.l > b.l;
}
int main() {
ios::sync_with_stdio(false);cin.tie(0);
cin >> N >> M;
a[0] = INF+1;
st.push(0);
for(int i = 1; i <= N; i++) {
cin >> a[i];
while(!st.empty() && a[i] >= a[st.top()]) st.pop();
if (!st.empty())
p.pb({st.top(), i});
st.push(i);
}
for(int i = 1; i <= M; i++) {
cin >> q[i].l >> q[i].r >> q[i].k;
q[i].idx = i;
}
sort(q+1, q+1+M, cmp1);
sort(all(p));
int id = N-1;
for(int i = 1; i <= M; i++) {
int l = q[i].l, r = q[i].r, k = q[i].k, idx = q[i].idx;
while(id >= 0 && l <= p[id].fi) {
update(1, 1, N, p[id].se, a[p[id].fi]+a[p[id].se]);
id--;
}
rez[idx] = (query(1, 1, N, l, r) <= k);
}
for(int i = 1; i <= M; i++) cout << rez[i] << endl;
return 0;
}
Compilation message
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:52:8: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
52 | if (!st.empty())
| ^~
sortbooks.cpp:54:9: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
54 | st.push(i);
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
3 ms |
460 KB |
Output is correct |
12 |
Correct |
6 ms |
588 KB |
Output is correct |
13 |
Correct |
6 ms |
588 KB |
Output is correct |
14 |
Correct |
6 ms |
588 KB |
Output is correct |
15 |
Correct |
6 ms |
588 KB |
Output is correct |
16 |
Correct |
5 ms |
588 KB |
Output is correct |
17 |
Correct |
4 ms |
460 KB |
Output is correct |
18 |
Correct |
5 ms |
588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1732 ms |
72636 KB |
Output is correct |
2 |
Correct |
1809 ms |
74900 KB |
Output is correct |
3 |
Correct |
1817 ms |
74672 KB |
Output is correct |
4 |
Correct |
1748 ms |
74824 KB |
Output is correct |
5 |
Correct |
1398 ms |
66640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
144 ms |
4732 KB |
Output is correct |
2 |
Correct |
125 ms |
4788 KB |
Output is correct |
3 |
Correct |
107 ms |
3772 KB |
Output is correct |
4 |
Correct |
106 ms |
3716 KB |
Output is correct |
5 |
Correct |
98 ms |
3776 KB |
Output is correct |
6 |
Correct |
92 ms |
3868 KB |
Output is correct |
7 |
Correct |
95 ms |
3876 KB |
Output is correct |
8 |
Correct |
97 ms |
4548 KB |
Output is correct |
9 |
Correct |
60 ms |
2404 KB |
Output is correct |
10 |
Correct |
97 ms |
4400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
3 ms |
460 KB |
Output is correct |
12 |
Correct |
6 ms |
588 KB |
Output is correct |
13 |
Correct |
6 ms |
588 KB |
Output is correct |
14 |
Correct |
6 ms |
588 KB |
Output is correct |
15 |
Correct |
6 ms |
588 KB |
Output is correct |
16 |
Correct |
5 ms |
588 KB |
Output is correct |
17 |
Correct |
4 ms |
460 KB |
Output is correct |
18 |
Correct |
5 ms |
588 KB |
Output is correct |
19 |
Correct |
270 ms |
14620 KB |
Output is correct |
20 |
Correct |
274 ms |
15708 KB |
Output is correct |
21 |
Correct |
276 ms |
15632 KB |
Output is correct |
22 |
Correct |
483 ms |
15664 KB |
Output is correct |
23 |
Correct |
289 ms |
15552 KB |
Output is correct |
24 |
Correct |
243 ms |
13472 KB |
Output is correct |
25 |
Correct |
216 ms |
13352 KB |
Output is correct |
26 |
Correct |
333 ms |
13652 KB |
Output is correct |
27 |
Correct |
223 ms |
13580 KB |
Output is correct |
28 |
Correct |
260 ms |
13656 KB |
Output is correct |
29 |
Correct |
224 ms |
13836 KB |
Output is correct |
30 |
Correct |
278 ms |
13816 KB |
Output is correct |
31 |
Correct |
224 ms |
13616 KB |
Output is correct |
32 |
Correct |
257 ms |
13728 KB |
Output is correct |
33 |
Correct |
265 ms |
13732 KB |
Output is correct |
34 |
Correct |
208 ms |
13396 KB |
Output is correct |
35 |
Correct |
212 ms |
13492 KB |
Output is correct |
36 |
Correct |
204 ms |
13196 KB |
Output is correct |
37 |
Correct |
224 ms |
13132 KB |
Output is correct |
38 |
Correct |
228 ms |
13392 KB |
Output is correct |
39 |
Correct |
230 ms |
13016 KB |
Output is correct |
40 |
Correct |
173 ms |
11092 KB |
Output is correct |
41 |
Correct |
231 ms |
13060 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
3 ms |
460 KB |
Output is correct |
12 |
Correct |
6 ms |
588 KB |
Output is correct |
13 |
Correct |
6 ms |
588 KB |
Output is correct |
14 |
Correct |
6 ms |
588 KB |
Output is correct |
15 |
Correct |
6 ms |
588 KB |
Output is correct |
16 |
Correct |
5 ms |
588 KB |
Output is correct |
17 |
Correct |
4 ms |
460 KB |
Output is correct |
18 |
Correct |
5 ms |
588 KB |
Output is correct |
19 |
Correct |
1732 ms |
72636 KB |
Output is correct |
20 |
Correct |
1809 ms |
74900 KB |
Output is correct |
21 |
Correct |
1817 ms |
74672 KB |
Output is correct |
22 |
Correct |
1748 ms |
74824 KB |
Output is correct |
23 |
Correct |
1398 ms |
66640 KB |
Output is correct |
24 |
Correct |
144 ms |
4732 KB |
Output is correct |
25 |
Correct |
125 ms |
4788 KB |
Output is correct |
26 |
Correct |
107 ms |
3772 KB |
Output is correct |
27 |
Correct |
106 ms |
3716 KB |
Output is correct |
28 |
Correct |
98 ms |
3776 KB |
Output is correct |
29 |
Correct |
92 ms |
3868 KB |
Output is correct |
30 |
Correct |
95 ms |
3876 KB |
Output is correct |
31 |
Correct |
97 ms |
4548 KB |
Output is correct |
32 |
Correct |
60 ms |
2404 KB |
Output is correct |
33 |
Correct |
97 ms |
4400 KB |
Output is correct |
34 |
Correct |
270 ms |
14620 KB |
Output is correct |
35 |
Correct |
274 ms |
15708 KB |
Output is correct |
36 |
Correct |
276 ms |
15632 KB |
Output is correct |
37 |
Correct |
483 ms |
15664 KB |
Output is correct |
38 |
Correct |
289 ms |
15552 KB |
Output is correct |
39 |
Correct |
243 ms |
13472 KB |
Output is correct |
40 |
Correct |
216 ms |
13352 KB |
Output is correct |
41 |
Correct |
333 ms |
13652 KB |
Output is correct |
42 |
Correct |
223 ms |
13580 KB |
Output is correct |
43 |
Correct |
260 ms |
13656 KB |
Output is correct |
44 |
Correct |
224 ms |
13836 KB |
Output is correct |
45 |
Correct |
278 ms |
13816 KB |
Output is correct |
46 |
Correct |
224 ms |
13616 KB |
Output is correct |
47 |
Correct |
257 ms |
13728 KB |
Output is correct |
48 |
Correct |
265 ms |
13732 KB |
Output is correct |
49 |
Correct |
208 ms |
13396 KB |
Output is correct |
50 |
Correct |
212 ms |
13492 KB |
Output is correct |
51 |
Correct |
204 ms |
13196 KB |
Output is correct |
52 |
Correct |
224 ms |
13132 KB |
Output is correct |
53 |
Correct |
228 ms |
13392 KB |
Output is correct |
54 |
Correct |
230 ms |
13016 KB |
Output is correct |
55 |
Correct |
173 ms |
11092 KB |
Output is correct |
56 |
Correct |
231 ms |
13060 KB |
Output is correct |
57 |
Correct |
1794 ms |
75580 KB |
Output is correct |
58 |
Correct |
1987 ms |
75448 KB |
Output is correct |
59 |
Correct |
1565 ms |
75456 KB |
Output is correct |
60 |
Correct |
1637 ms |
75476 KB |
Output is correct |
61 |
Correct |
1647 ms |
75572 KB |
Output is correct |
62 |
Correct |
1987 ms |
75364 KB |
Output is correct |
63 |
Correct |
1313 ms |
65348 KB |
Output is correct |
64 |
Correct |
1218 ms |
65336 KB |
Output is correct |
65 |
Correct |
1450 ms |
67180 KB |
Output is correct |
66 |
Correct |
1444 ms |
67216 KB |
Output is correct |
67 |
Correct |
1363 ms |
67188 KB |
Output is correct |
68 |
Correct |
1409 ms |
67284 KB |
Output is correct |
69 |
Correct |
1356 ms |
67296 KB |
Output is correct |
70 |
Correct |
1332 ms |
67328 KB |
Output is correct |
71 |
Correct |
1393 ms |
67276 KB |
Output is correct |
72 |
Correct |
1361 ms |
67272 KB |
Output is correct |
73 |
Correct |
1267 ms |
63864 KB |
Output is correct |
74 |
Correct |
1210 ms |
64840 KB |
Output is correct |
75 |
Correct |
1253 ms |
63876 KB |
Output is correct |
76 |
Correct |
1231 ms |
63872 KB |
Output is correct |
77 |
Correct |
1258 ms |
63872 KB |
Output is correct |
78 |
Correct |
1305 ms |
63904 KB |
Output is correct |
79 |
Correct |
1259 ms |
51772 KB |
Output is correct |
80 |
Correct |
1271 ms |
64292 KB |
Output is correct |