#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define sz(x) (int) (x).size()
using namespace std;
typedef long long lint;
typedef pair<int,int> ii;
struct node{
int s, e, m;
int val = 0, lazy = 0;
node *l, *r;
node(int S, int E){
s = S, e = E, m = (s+e)/2;
if(s != e){
l = new node(s, m);
r = new node(m+1, e);
}
}
void apply(int L){
lazy += L;
val += L;
}
void push(){
if(s == e) return;
l->apply(lazy);
r->apply(lazy);
lazy = 0;
}
void update(int S, int E, int L){
push();
if(S == s && e == E){
apply(L);
return;
}
else if(E <= m) l->update(S, E, L);
else if(S >= m+1) r->update(S, E, L);
else{
update(S,m,L);
update(m+1,E,L);
}
val = max(l->val, r->val);
}
int query(int S, int E){
push();
if(S == s && e == E) return val;
else if(E <= m) return l->query(S, E);
else if(S >= m+1) return r->query(S, E);
else return max(l->query(S, m), r->query(m+1, E));
}
} *root;
int arr[1000005];
int ans[1000005];
struct query{ int r, K, id; };
vector<query> queries[1000005];
void update(int S, int E, int L){
if(S > E) return;
//cout << S << " " << E << " " << L << "U\n";
root->update(S, E, L);
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
int n, Q; cin >> n >> Q;
root = new node(1, n);
for(int i = 1;i <= n;i++){
cin >> arr[i];
}
for(int q = 0;q < Q;q++){
int l, r, K; cin >> l >> r >> K;
queries[l].push_back({r, K, q});
}
arr[n+1] = 1023456789;
vector<int> S;
S.push_back(n+1);
for(int l = n;l >= 1;l--){
//cout << l << " " << arr[l] << ":\n";
while(true){
int T = S.back();
if(arr[T] >= arr[l]) break;
///do something else here
S.pop_back();
int nxt = S.back();
update(T+1, nxt-1, -arr[T]);
update(T, T, arr[T]);
}
update(l+1, S.back()-1, arr[l]);
S.push_back(l);
//for(int i = sz(S)-1;i>=0;i--) cout << S[i] << " ";
//cout << "\n";
for(query q : queries[l]){
int res = root->query(l, q.r);
ans[q.id] = (res <= q.K);
}
}
for(int q = 0;q < Q;q++) cout << ans[q] << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23808 KB |
Output is correct |
2 |
Correct |
15 ms |
23808 KB |
Output is correct |
3 |
Correct |
15 ms |
23808 KB |
Output is correct |
4 |
Correct |
16 ms |
23808 KB |
Output is correct |
5 |
Correct |
15 ms |
23808 KB |
Output is correct |
6 |
Correct |
16 ms |
23936 KB |
Output is correct |
7 |
Correct |
16 ms |
23960 KB |
Output is correct |
8 |
Correct |
16 ms |
23928 KB |
Output is correct |
9 |
Correct |
15 ms |
23936 KB |
Output is correct |
10 |
Correct |
16 ms |
23936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23808 KB |
Output is correct |
2 |
Correct |
15 ms |
23808 KB |
Output is correct |
3 |
Correct |
15 ms |
23808 KB |
Output is correct |
4 |
Correct |
16 ms |
23808 KB |
Output is correct |
5 |
Correct |
15 ms |
23808 KB |
Output is correct |
6 |
Correct |
16 ms |
23936 KB |
Output is correct |
7 |
Correct |
16 ms |
23960 KB |
Output is correct |
8 |
Correct |
16 ms |
23928 KB |
Output is correct |
9 |
Correct |
15 ms |
23936 KB |
Output is correct |
10 |
Correct |
16 ms |
23936 KB |
Output is correct |
11 |
Correct |
18 ms |
24192 KB |
Output is correct |
12 |
Correct |
21 ms |
24448 KB |
Output is correct |
13 |
Correct |
22 ms |
24576 KB |
Output is correct |
14 |
Correct |
23 ms |
24576 KB |
Output is correct |
15 |
Correct |
23 ms |
24576 KB |
Output is correct |
16 |
Correct |
21 ms |
24552 KB |
Output is correct |
17 |
Correct |
20 ms |
24448 KB |
Output is correct |
18 |
Correct |
20 ms |
24576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2879 ms |
150016 KB |
Output is correct |
2 |
Correct |
2890 ms |
149960 KB |
Output is correct |
3 |
Correct |
2914 ms |
149868 KB |
Output is correct |
4 |
Correct |
2904 ms |
150136 KB |
Output is correct |
5 |
Correct |
2230 ms |
154088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
202 ms |
37240 KB |
Output is correct |
2 |
Correct |
185 ms |
36984 KB |
Output is correct |
3 |
Correct |
147 ms |
37620 KB |
Output is correct |
4 |
Correct |
150 ms |
37744 KB |
Output is correct |
5 |
Correct |
150 ms |
37760 KB |
Output is correct |
6 |
Correct |
121 ms |
37104 KB |
Output is correct |
7 |
Correct |
120 ms |
37100 KB |
Output is correct |
8 |
Correct |
142 ms |
37296 KB |
Output is correct |
9 |
Correct |
62 ms |
26672 KB |
Output is correct |
10 |
Correct |
138 ms |
37524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23808 KB |
Output is correct |
2 |
Correct |
15 ms |
23808 KB |
Output is correct |
3 |
Correct |
15 ms |
23808 KB |
Output is correct |
4 |
Correct |
16 ms |
23808 KB |
Output is correct |
5 |
Correct |
15 ms |
23808 KB |
Output is correct |
6 |
Correct |
16 ms |
23936 KB |
Output is correct |
7 |
Correct |
16 ms |
23960 KB |
Output is correct |
8 |
Correct |
16 ms |
23928 KB |
Output is correct |
9 |
Correct |
15 ms |
23936 KB |
Output is correct |
10 |
Correct |
16 ms |
23936 KB |
Output is correct |
11 |
Correct |
18 ms |
24192 KB |
Output is correct |
12 |
Correct |
21 ms |
24448 KB |
Output is correct |
13 |
Correct |
22 ms |
24576 KB |
Output is correct |
14 |
Correct |
23 ms |
24576 KB |
Output is correct |
15 |
Correct |
23 ms |
24576 KB |
Output is correct |
16 |
Correct |
21 ms |
24552 KB |
Output is correct |
17 |
Correct |
20 ms |
24448 KB |
Output is correct |
18 |
Correct |
20 ms |
24576 KB |
Output is correct |
19 |
Correct |
476 ms |
49916 KB |
Output is correct |
20 |
Correct |
480 ms |
49912 KB |
Output is correct |
21 |
Correct |
383 ms |
49400 KB |
Output is correct |
22 |
Correct |
392 ms |
49528 KB |
Output is correct |
23 |
Correct |
404 ms |
49528 KB |
Output is correct |
24 |
Correct |
262 ms |
50160 KB |
Output is correct |
25 |
Correct |
267 ms |
50160 KB |
Output is correct |
26 |
Correct |
310 ms |
50564 KB |
Output is correct |
27 |
Correct |
302 ms |
50288 KB |
Output is correct |
28 |
Correct |
323 ms |
50560 KB |
Output is correct |
29 |
Correct |
353 ms |
50796 KB |
Output is correct |
30 |
Correct |
349 ms |
50792 KB |
Output is correct |
31 |
Correct |
351 ms |
50672 KB |
Output is correct |
32 |
Correct |
353 ms |
50884 KB |
Output is correct |
33 |
Correct |
357 ms |
50720 KB |
Output is correct |
34 |
Correct |
254 ms |
49608 KB |
Output is correct |
35 |
Correct |
260 ms |
49516 KB |
Output is correct |
36 |
Correct |
246 ms |
49524 KB |
Output is correct |
37 |
Correct |
246 ms |
49516 KB |
Output is correct |
38 |
Correct |
255 ms |
49668 KB |
Output is correct |
39 |
Correct |
336 ms |
50224 KB |
Output is correct |
40 |
Correct |
228 ms |
42920 KB |
Output is correct |
41 |
Correct |
309 ms |
49960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23808 KB |
Output is correct |
2 |
Correct |
15 ms |
23808 KB |
Output is correct |
3 |
Correct |
15 ms |
23808 KB |
Output is correct |
4 |
Correct |
16 ms |
23808 KB |
Output is correct |
5 |
Correct |
15 ms |
23808 KB |
Output is correct |
6 |
Correct |
16 ms |
23936 KB |
Output is correct |
7 |
Correct |
16 ms |
23960 KB |
Output is correct |
8 |
Correct |
16 ms |
23928 KB |
Output is correct |
9 |
Correct |
15 ms |
23936 KB |
Output is correct |
10 |
Correct |
16 ms |
23936 KB |
Output is correct |
11 |
Correct |
18 ms |
24192 KB |
Output is correct |
12 |
Correct |
21 ms |
24448 KB |
Output is correct |
13 |
Correct |
22 ms |
24576 KB |
Output is correct |
14 |
Correct |
23 ms |
24576 KB |
Output is correct |
15 |
Correct |
23 ms |
24576 KB |
Output is correct |
16 |
Correct |
21 ms |
24552 KB |
Output is correct |
17 |
Correct |
20 ms |
24448 KB |
Output is correct |
18 |
Correct |
20 ms |
24576 KB |
Output is correct |
19 |
Correct |
2879 ms |
150016 KB |
Output is correct |
20 |
Correct |
2890 ms |
149960 KB |
Output is correct |
21 |
Correct |
2914 ms |
149868 KB |
Output is correct |
22 |
Correct |
2904 ms |
150136 KB |
Output is correct |
23 |
Correct |
2230 ms |
154088 KB |
Output is correct |
24 |
Correct |
202 ms |
37240 KB |
Output is correct |
25 |
Correct |
185 ms |
36984 KB |
Output is correct |
26 |
Correct |
147 ms |
37620 KB |
Output is correct |
27 |
Correct |
150 ms |
37744 KB |
Output is correct |
28 |
Correct |
150 ms |
37760 KB |
Output is correct |
29 |
Correct |
121 ms |
37104 KB |
Output is correct |
30 |
Correct |
120 ms |
37100 KB |
Output is correct |
31 |
Correct |
142 ms |
37296 KB |
Output is correct |
32 |
Correct |
62 ms |
26672 KB |
Output is correct |
33 |
Correct |
138 ms |
37524 KB |
Output is correct |
34 |
Correct |
476 ms |
49916 KB |
Output is correct |
35 |
Correct |
480 ms |
49912 KB |
Output is correct |
36 |
Correct |
383 ms |
49400 KB |
Output is correct |
37 |
Correct |
392 ms |
49528 KB |
Output is correct |
38 |
Correct |
404 ms |
49528 KB |
Output is correct |
39 |
Correct |
262 ms |
50160 KB |
Output is correct |
40 |
Correct |
267 ms |
50160 KB |
Output is correct |
41 |
Correct |
310 ms |
50564 KB |
Output is correct |
42 |
Correct |
302 ms |
50288 KB |
Output is correct |
43 |
Correct |
323 ms |
50560 KB |
Output is correct |
44 |
Correct |
353 ms |
50796 KB |
Output is correct |
45 |
Correct |
349 ms |
50792 KB |
Output is correct |
46 |
Correct |
351 ms |
50672 KB |
Output is correct |
47 |
Correct |
353 ms |
50884 KB |
Output is correct |
48 |
Correct |
357 ms |
50720 KB |
Output is correct |
49 |
Correct |
254 ms |
49608 KB |
Output is correct |
50 |
Correct |
260 ms |
49516 KB |
Output is correct |
51 |
Correct |
246 ms |
49524 KB |
Output is correct |
52 |
Correct |
246 ms |
49516 KB |
Output is correct |
53 |
Correct |
255 ms |
49668 KB |
Output is correct |
54 |
Correct |
336 ms |
50224 KB |
Output is correct |
55 |
Correct |
228 ms |
42920 KB |
Output is correct |
56 |
Correct |
309 ms |
49960 KB |
Output is correct |
57 |
Correct |
2821 ms |
154484 KB |
Output is correct |
58 |
Correct |
2823 ms |
154488 KB |
Output is correct |
59 |
Correct |
2709 ms |
152568 KB |
Output is correct |
60 |
Correct |
2693 ms |
152332 KB |
Output is correct |
61 |
Correct |
2655 ms |
152440 KB |
Output is correct |
62 |
Correct |
2648 ms |
152440 KB |
Output is correct |
63 |
Correct |
1362 ms |
152420 KB |
Output is correct |
64 |
Correct |
1355 ms |
152420 KB |
Output is correct |
65 |
Correct |
2000 ms |
156364 KB |
Output is correct |
66 |
Correct |
1972 ms |
156300 KB |
Output is correct |
67 |
Correct |
2072 ms |
156480 KB |
Output is correct |
68 |
Correct |
2218 ms |
158308 KB |
Output is correct |
69 |
Correct |
2125 ms |
158176 KB |
Output is correct |
70 |
Correct |
2107 ms |
157660 KB |
Output is correct |
71 |
Correct |
2087 ms |
157536 KB |
Output is correct |
72 |
Correct |
2113 ms |
157428 KB |
Output is correct |
73 |
Correct |
1290 ms |
150748 KB |
Output is correct |
74 |
Correct |
1320 ms |
150360 KB |
Output is correct |
75 |
Correct |
1312 ms |
150420 KB |
Output is correct |
76 |
Correct |
1290 ms |
150172 KB |
Output is correct |
77 |
Correct |
1289 ms |
150620 KB |
Output is correct |
78 |
Correct |
2007 ms |
153660 KB |
Output is correct |
79 |
Correct |
1296 ms |
103576 KB |
Output is correct |
80 |
Correct |
1882 ms |
152328 KB |
Output is correct |