#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<long long, long long> pll;
typedef pair<int,int> pii;
typedef vector<long long> vl;
typedef vector<int> vi;
int n, m;
vi arr;
const int MXN = 1e6+5;
vector<array<int, 3>> queries[MXN];
bool comp(array<int, 3>& a, array<int, 3>& b){
return a[0] < b[0];
}
int tree[4 * MXN], lazy[4 * MXN];
void push(int node, int l, int r){
if(lazy[node] == 0) return;
tree[node] = max(tree[node], lazy[node]);
if(l != r){
lazy[node*2] = max(lazy[node*2], lazy[node]);
lazy[node*2+1] = max(lazy[node*2+1], lazy[node]);
}
lazy[node] = 0;
}
void update(int node, int l, int r, int L, int R, int val){
push(node, l, r);
if(r < L || l > R) return;
if(L <= l && r <= R){
lazy[node] = max(lazy[node], val);
push(node, l, r);
return;
}
int mid = (l + r) / 2;
update(node*2, l, mid, L, R, val);
update(node*2+1, mid+1, r, L, R, val);
tree[node] = max(tree[node*2], tree[node*2+1]);
}
int query(int node, int l, int r, int L, int R){
push(node, l, r);
if(r < L || l > R) return 0;
if(L <= l && r <= R) return tree[node];
int mid = (l + r) / 2;
return max(query(node*2, l, mid, L, R), query(node*2+1, mid+1, r, L, R));
}
int main(){
cin>>n>>m;
arr.resize(n);
for(int i = 0; i < n; i++) cin>>arr[i];
vi ans(m);
for(int i = 0; i < m; i++){
int l, r, k;
cin>>l>>r>>k;
l--;
r--;
queries[r].pb({l, k, i});
}
stack<int> store;
for(int i = 0; i < n; i++){
while(!store.empty() && arr[store.top()] <= arr[i])
store.pop();
if(!store.empty()){
update(1, 0, n-1, 1, store.top(), arr[i] + arr[store.top()]);
}
for(auto t : queries[i]){
int l = t[0];
int k = t[1];
int id = t[2];
if(query(1, 0, n-1, l, i) <= k)
ans[id] = 1;
else
ans[id] = 0;
}
store.push(i);
}
for(auto t : ans)
cout<<t<<"\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23764 KB |
Output is correct |
3 |
Correct |
14 ms |
23764 KB |
Output is correct |
4 |
Correct |
14 ms |
23764 KB |
Output is correct |
5 |
Correct |
12 ms |
23792 KB |
Output is correct |
6 |
Correct |
12 ms |
23764 KB |
Output is correct |
7 |
Correct |
14 ms |
23764 KB |
Output is correct |
8 |
Correct |
13 ms |
23764 KB |
Output is correct |
9 |
Correct |
13 ms |
23764 KB |
Output is correct |
10 |
Correct |
13 ms |
23764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23764 KB |
Output is correct |
3 |
Correct |
14 ms |
23764 KB |
Output is correct |
4 |
Correct |
14 ms |
23764 KB |
Output is correct |
5 |
Correct |
12 ms |
23792 KB |
Output is correct |
6 |
Correct |
12 ms |
23764 KB |
Output is correct |
7 |
Correct |
14 ms |
23764 KB |
Output is correct |
8 |
Correct |
13 ms |
23764 KB |
Output is correct |
9 |
Correct |
13 ms |
23764 KB |
Output is correct |
10 |
Correct |
13 ms |
23764 KB |
Output is correct |
11 |
Correct |
16 ms |
23984 KB |
Output is correct |
12 |
Correct |
18 ms |
24020 KB |
Output is correct |
13 |
Correct |
19 ms |
24020 KB |
Output is correct |
14 |
Correct |
20 ms |
24148 KB |
Output is correct |
15 |
Correct |
21 ms |
24140 KB |
Output is correct |
16 |
Correct |
19 ms |
24148 KB |
Output is correct |
17 |
Correct |
17 ms |
24020 KB |
Output is correct |
18 |
Correct |
18 ms |
24020 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2635 ms |
103556 KB |
Output is correct |
2 |
Correct |
2694 ms |
104608 KB |
Output is correct |
3 |
Correct |
2550 ms |
104364 KB |
Output is correct |
4 |
Correct |
2597 ms |
104652 KB |
Output is correct |
5 |
Correct |
1886 ms |
88188 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
180 ms |
30820 KB |
Output is correct |
2 |
Correct |
189 ms |
30544 KB |
Output is correct |
3 |
Correct |
138 ms |
28748 KB |
Output is correct |
4 |
Correct |
140 ms |
28812 KB |
Output is correct |
5 |
Correct |
151 ms |
28816 KB |
Output is correct |
6 |
Correct |
124 ms |
28340 KB |
Output is correct |
7 |
Correct |
123 ms |
28336 KB |
Output is correct |
8 |
Correct |
148 ms |
29828 KB |
Output is correct |
9 |
Correct |
81 ms |
27140 KB |
Output is correct |
10 |
Correct |
146 ms |
30296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23764 KB |
Output is correct |
3 |
Correct |
14 ms |
23764 KB |
Output is correct |
4 |
Correct |
14 ms |
23764 KB |
Output is correct |
5 |
Correct |
12 ms |
23792 KB |
Output is correct |
6 |
Correct |
12 ms |
23764 KB |
Output is correct |
7 |
Correct |
14 ms |
23764 KB |
Output is correct |
8 |
Correct |
13 ms |
23764 KB |
Output is correct |
9 |
Correct |
13 ms |
23764 KB |
Output is correct |
10 |
Correct |
13 ms |
23764 KB |
Output is correct |
11 |
Correct |
16 ms |
23984 KB |
Output is correct |
12 |
Correct |
18 ms |
24020 KB |
Output is correct |
13 |
Correct |
19 ms |
24020 KB |
Output is correct |
14 |
Correct |
20 ms |
24148 KB |
Output is correct |
15 |
Correct |
21 ms |
24140 KB |
Output is correct |
16 |
Correct |
19 ms |
24148 KB |
Output is correct |
17 |
Correct |
17 ms |
24020 KB |
Output is correct |
18 |
Correct |
18 ms |
24020 KB |
Output is correct |
19 |
Correct |
463 ms |
40656 KB |
Output is correct |
20 |
Correct |
470 ms |
40668 KB |
Output is correct |
21 |
Correct |
408 ms |
40024 KB |
Output is correct |
22 |
Correct |
402 ms |
40036 KB |
Output is correct |
23 |
Correct |
420 ms |
39980 KB |
Output is correct |
24 |
Correct |
310 ms |
35828 KB |
Output is correct |
25 |
Correct |
313 ms |
35796 KB |
Output is correct |
26 |
Correct |
349 ms |
36048 KB |
Output is correct |
27 |
Correct |
332 ms |
36084 KB |
Output is correct |
28 |
Correct |
324 ms |
36172 KB |
Output is correct |
29 |
Correct |
336 ms |
36592 KB |
Output is correct |
30 |
Correct |
376 ms |
36600 KB |
Output is correct |
31 |
Correct |
343 ms |
36684 KB |
Output is correct |
32 |
Correct |
335 ms |
36560 KB |
Output is correct |
33 |
Correct |
332 ms |
36560 KB |
Output is correct |
34 |
Correct |
302 ms |
35400 KB |
Output is correct |
35 |
Correct |
298 ms |
35420 KB |
Output is correct |
36 |
Correct |
287 ms |
35244 KB |
Output is correct |
37 |
Correct |
287 ms |
35276 KB |
Output is correct |
38 |
Correct |
306 ms |
35428 KB |
Output is correct |
39 |
Correct |
311 ms |
37596 KB |
Output is correct |
40 |
Correct |
244 ms |
34560 KB |
Output is correct |
41 |
Correct |
329 ms |
37612 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23764 KB |
Output is correct |
2 |
Correct |
12 ms |
23764 KB |
Output is correct |
3 |
Correct |
14 ms |
23764 KB |
Output is correct |
4 |
Correct |
14 ms |
23764 KB |
Output is correct |
5 |
Correct |
12 ms |
23792 KB |
Output is correct |
6 |
Correct |
12 ms |
23764 KB |
Output is correct |
7 |
Correct |
14 ms |
23764 KB |
Output is correct |
8 |
Correct |
13 ms |
23764 KB |
Output is correct |
9 |
Correct |
13 ms |
23764 KB |
Output is correct |
10 |
Correct |
13 ms |
23764 KB |
Output is correct |
11 |
Correct |
16 ms |
23984 KB |
Output is correct |
12 |
Correct |
18 ms |
24020 KB |
Output is correct |
13 |
Correct |
19 ms |
24020 KB |
Output is correct |
14 |
Correct |
20 ms |
24148 KB |
Output is correct |
15 |
Correct |
21 ms |
24140 KB |
Output is correct |
16 |
Correct |
19 ms |
24148 KB |
Output is correct |
17 |
Correct |
17 ms |
24020 KB |
Output is correct |
18 |
Correct |
18 ms |
24020 KB |
Output is correct |
19 |
Correct |
2635 ms |
103556 KB |
Output is correct |
20 |
Correct |
2694 ms |
104608 KB |
Output is correct |
21 |
Correct |
2550 ms |
104364 KB |
Output is correct |
22 |
Correct |
2597 ms |
104652 KB |
Output is correct |
23 |
Correct |
1886 ms |
88188 KB |
Output is correct |
24 |
Correct |
180 ms |
30820 KB |
Output is correct |
25 |
Correct |
189 ms |
30544 KB |
Output is correct |
26 |
Correct |
138 ms |
28748 KB |
Output is correct |
27 |
Correct |
140 ms |
28812 KB |
Output is correct |
28 |
Correct |
151 ms |
28816 KB |
Output is correct |
29 |
Correct |
124 ms |
28340 KB |
Output is correct |
30 |
Correct |
123 ms |
28336 KB |
Output is correct |
31 |
Correct |
148 ms |
29828 KB |
Output is correct |
32 |
Correct |
81 ms |
27140 KB |
Output is correct |
33 |
Correct |
146 ms |
30296 KB |
Output is correct |
34 |
Correct |
463 ms |
40656 KB |
Output is correct |
35 |
Correct |
470 ms |
40668 KB |
Output is correct |
36 |
Correct |
408 ms |
40024 KB |
Output is correct |
37 |
Correct |
402 ms |
40036 KB |
Output is correct |
38 |
Correct |
420 ms |
39980 KB |
Output is correct |
39 |
Correct |
310 ms |
35828 KB |
Output is correct |
40 |
Correct |
313 ms |
35796 KB |
Output is correct |
41 |
Correct |
349 ms |
36048 KB |
Output is correct |
42 |
Correct |
332 ms |
36084 KB |
Output is correct |
43 |
Correct |
324 ms |
36172 KB |
Output is correct |
44 |
Correct |
336 ms |
36592 KB |
Output is correct |
45 |
Correct |
376 ms |
36600 KB |
Output is correct |
46 |
Correct |
343 ms |
36684 KB |
Output is correct |
47 |
Correct |
335 ms |
36560 KB |
Output is correct |
48 |
Correct |
332 ms |
36560 KB |
Output is correct |
49 |
Correct |
302 ms |
35400 KB |
Output is correct |
50 |
Correct |
298 ms |
35420 KB |
Output is correct |
51 |
Correct |
287 ms |
35244 KB |
Output is correct |
52 |
Correct |
287 ms |
35276 KB |
Output is correct |
53 |
Correct |
306 ms |
35428 KB |
Output is correct |
54 |
Correct |
311 ms |
37596 KB |
Output is correct |
55 |
Correct |
244 ms |
34560 KB |
Output is correct |
56 |
Correct |
329 ms |
37612 KB |
Output is correct |
57 |
Correct |
2505 ms |
104768 KB |
Output is correct |
58 |
Correct |
2574 ms |
104780 KB |
Output is correct |
59 |
Correct |
2502 ms |
103272 KB |
Output is correct |
60 |
Correct |
2356 ms |
103224 KB |
Output is correct |
61 |
Correct |
2483 ms |
103368 KB |
Output is correct |
62 |
Correct |
2410 ms |
103344 KB |
Output is correct |
63 |
Correct |
1583 ms |
83548 KB |
Output is correct |
64 |
Correct |
1533 ms |
83660 KB |
Output is correct |
65 |
Correct |
1796 ms |
86876 KB |
Output is correct |
66 |
Correct |
1784 ms |
86752 KB |
Output is correct |
67 |
Correct |
1774 ms |
86868 KB |
Output is correct |
68 |
Correct |
1945 ms |
88580 KB |
Output is correct |
69 |
Correct |
1878 ms |
88388 KB |
Output is correct |
70 |
Correct |
1898 ms |
88072 KB |
Output is correct |
71 |
Correct |
1884 ms |
88076 KB |
Output is correct |
72 |
Correct |
2021 ms |
88068 KB |
Output is correct |
73 |
Correct |
1494 ms |
79656 KB |
Output is correct |
74 |
Correct |
1517 ms |
80500 KB |
Output is correct |
75 |
Correct |
1426 ms |
79676 KB |
Output is correct |
76 |
Correct |
1511 ms |
79696 KB |
Output is correct |
77 |
Correct |
1491 ms |
79588 KB |
Output is correct |
78 |
Correct |
1780 ms |
91464 KB |
Output is correct |
79 |
Correct |
1237 ms |
75752 KB |
Output is correct |
80 |
Correct |
1880 ms |
90556 KB |
Output is correct |