#include <bits/stdc++.h>
using namespace std;
#define st first
#define nd second
#define pb push_back
#define int long long int
#define endl '\n'
#define MOD (int)(1e9 + 7)
#define all(x) x.begin(), x.end()
#define mid start+(end-start)/2
#define debug(x) cerr << #x << " = " << x << endl
#define binary(x) cerr << #x << " = " << bitset<8>(x) << endl
#define N (int)(1e6)+5
int n, m, a, b, c;
vector<int> v;
vector<pair<pair<int, int>, pair<int, int> > > q;
int tree[4*N];
int cevs[N];
void update(int wai, int start, int end, int indis, int val){
if(start > indis || end < indis) return;
if(start == end){
tree[wai] = max(tree[wai], val);
return;
}
update(wai*2, start, mid, indis, val), update(wai*2+1, mid+1, end, indis, val);
tree[wai] = max(tree[wai*2], tree[wai*2+1]);
}
int query(int wai, int start, int end, int l, int r){
if(start > r || end < l) return 0;
if(start >= l && end <= r) return tree[wai];
return max(query(wai*2, start, mid, l, r), query(wai*2+1, mid+1, end, l, r));
}
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie(0); cout.tie(0);
cin >> n >> m;
for(int i = 0; i < n; i++){
cin >> a;
v.pb(a);
}
for(int i = 0; i < m; i++){
cin >> a >> b >> c;
q.pb({{a,b}, {c, i}});
}
sort(all(q));
stack<pair<int, int> > st;
int las = m-1;
for(int i = n-1; i >= 0; i--){
int son = i;
while(!st.empty() && v[i] > st.top().st){
update(1, 1, n, son+2, v[i]+st.top().st);
son = st.top().nd;
st.pop();
}
if(st.empty()) son = n-1;
st.push({v[i], son});
while(las >= 0 && q[las].st.st == i+1){
// debug(query(1, 1, n, i, q[las].st.nd));
if(query(1, 1, n, i+1, q[las].st.nd) <= q[las].nd.st) cevs[q[las].nd.nd] = 1;
las--;
}
}
for(int i = 0; i < m; i++) cout << cevs[i] << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
3 ms |
620 KB |
Output is correct |
12 |
Correct |
4 ms |
748 KB |
Output is correct |
13 |
Correct |
5 ms |
748 KB |
Output is correct |
14 |
Correct |
6 ms |
872 KB |
Output is correct |
15 |
Correct |
6 ms |
872 KB |
Output is correct |
16 |
Correct |
5 ms |
748 KB |
Output is correct |
17 |
Correct |
4 ms |
800 KB |
Output is correct |
18 |
Correct |
5 ms |
872 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1559 ms |
58256 KB |
Output is correct |
2 |
Correct |
1650 ms |
58264 KB |
Output is correct |
3 |
Correct |
1657 ms |
60920 KB |
Output is correct |
4 |
Correct |
1566 ms |
62992 KB |
Output is correct |
5 |
Correct |
1252 ms |
70852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
122 ms |
7396 KB |
Output is correct |
2 |
Correct |
121 ms |
9444 KB |
Output is correct |
3 |
Correct |
100 ms |
8932 KB |
Output is correct |
4 |
Correct |
100 ms |
8932 KB |
Output is correct |
5 |
Correct |
99 ms |
8932 KB |
Output is correct |
6 |
Correct |
93 ms |
8168 KB |
Output is correct |
7 |
Correct |
90 ms |
8036 KB |
Output is correct |
8 |
Correct |
101 ms |
9188 KB |
Output is correct |
9 |
Correct |
55 ms |
5980 KB |
Output is correct |
10 |
Correct |
99 ms |
8932 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
3 ms |
620 KB |
Output is correct |
12 |
Correct |
4 ms |
748 KB |
Output is correct |
13 |
Correct |
5 ms |
748 KB |
Output is correct |
14 |
Correct |
6 ms |
872 KB |
Output is correct |
15 |
Correct |
6 ms |
872 KB |
Output is correct |
16 |
Correct |
5 ms |
748 KB |
Output is correct |
17 |
Correct |
4 ms |
800 KB |
Output is correct |
18 |
Correct |
5 ms |
872 KB |
Output is correct |
19 |
Correct |
278 ms |
18132 KB |
Output is correct |
20 |
Correct |
281 ms |
19092 KB |
Output is correct |
21 |
Correct |
274 ms |
19156 KB |
Output is correct |
22 |
Correct |
269 ms |
19156 KB |
Output is correct |
23 |
Correct |
270 ms |
19156 KB |
Output is correct |
24 |
Correct |
216 ms |
18132 KB |
Output is correct |
25 |
Correct |
224 ms |
18132 KB |
Output is correct |
26 |
Correct |
224 ms |
18132 KB |
Output is correct |
27 |
Correct |
228 ms |
18260 KB |
Output is correct |
28 |
Correct |
226 ms |
18260 KB |
Output is correct |
29 |
Correct |
227 ms |
18132 KB |
Output is correct |
30 |
Correct |
227 ms |
18260 KB |
Output is correct |
31 |
Correct |
225 ms |
18132 KB |
Output is correct |
32 |
Correct |
227 ms |
18132 KB |
Output is correct |
33 |
Correct |
226 ms |
18260 KB |
Output is correct |
34 |
Correct |
203 ms |
18260 KB |
Output is correct |
35 |
Correct |
208 ms |
18388 KB |
Output is correct |
36 |
Correct |
202 ms |
18260 KB |
Output is correct |
37 |
Correct |
201 ms |
18260 KB |
Output is correct |
38 |
Correct |
211 ms |
18344 KB |
Output is correct |
39 |
Correct |
215 ms |
18516 KB |
Output is correct |
40 |
Correct |
165 ms |
16344 KB |
Output is correct |
41 |
Correct |
224 ms |
18644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
3 ms |
620 KB |
Output is correct |
12 |
Correct |
4 ms |
748 KB |
Output is correct |
13 |
Correct |
5 ms |
748 KB |
Output is correct |
14 |
Correct |
6 ms |
872 KB |
Output is correct |
15 |
Correct |
6 ms |
872 KB |
Output is correct |
16 |
Correct |
5 ms |
748 KB |
Output is correct |
17 |
Correct |
4 ms |
800 KB |
Output is correct |
18 |
Correct |
5 ms |
872 KB |
Output is correct |
19 |
Correct |
1559 ms |
58256 KB |
Output is correct |
20 |
Correct |
1650 ms |
58264 KB |
Output is correct |
21 |
Correct |
1657 ms |
60920 KB |
Output is correct |
22 |
Correct |
1566 ms |
62992 KB |
Output is correct |
23 |
Correct |
1252 ms |
70852 KB |
Output is correct |
24 |
Correct |
122 ms |
7396 KB |
Output is correct |
25 |
Correct |
121 ms |
9444 KB |
Output is correct |
26 |
Correct |
100 ms |
8932 KB |
Output is correct |
27 |
Correct |
100 ms |
8932 KB |
Output is correct |
28 |
Correct |
99 ms |
8932 KB |
Output is correct |
29 |
Correct |
93 ms |
8168 KB |
Output is correct |
30 |
Correct |
90 ms |
8036 KB |
Output is correct |
31 |
Correct |
101 ms |
9188 KB |
Output is correct |
32 |
Correct |
55 ms |
5980 KB |
Output is correct |
33 |
Correct |
99 ms |
8932 KB |
Output is correct |
34 |
Correct |
278 ms |
18132 KB |
Output is correct |
35 |
Correct |
281 ms |
19092 KB |
Output is correct |
36 |
Correct |
274 ms |
19156 KB |
Output is correct |
37 |
Correct |
269 ms |
19156 KB |
Output is correct |
38 |
Correct |
270 ms |
19156 KB |
Output is correct |
39 |
Correct |
216 ms |
18132 KB |
Output is correct |
40 |
Correct |
224 ms |
18132 KB |
Output is correct |
41 |
Correct |
224 ms |
18132 KB |
Output is correct |
42 |
Correct |
228 ms |
18260 KB |
Output is correct |
43 |
Correct |
226 ms |
18260 KB |
Output is correct |
44 |
Correct |
227 ms |
18132 KB |
Output is correct |
45 |
Correct |
227 ms |
18260 KB |
Output is correct |
46 |
Correct |
225 ms |
18132 KB |
Output is correct |
47 |
Correct |
227 ms |
18132 KB |
Output is correct |
48 |
Correct |
226 ms |
18260 KB |
Output is correct |
49 |
Correct |
203 ms |
18260 KB |
Output is correct |
50 |
Correct |
208 ms |
18388 KB |
Output is correct |
51 |
Correct |
202 ms |
18260 KB |
Output is correct |
52 |
Correct |
201 ms |
18260 KB |
Output is correct |
53 |
Correct |
211 ms |
18344 KB |
Output is correct |
54 |
Correct |
215 ms |
18516 KB |
Output is correct |
55 |
Correct |
165 ms |
16344 KB |
Output is correct |
56 |
Correct |
224 ms |
18644 KB |
Output is correct |
57 |
Correct |
1574 ms |
71520 KB |
Output is correct |
58 |
Correct |
1561 ms |
70684 KB |
Output is correct |
59 |
Correct |
1525 ms |
70672 KB |
Output is correct |
60 |
Correct |
1532 ms |
70644 KB |
Output is correct |
61 |
Correct |
1576 ms |
70580 KB |
Output is correct |
62 |
Correct |
1579 ms |
70456 KB |
Output is correct |
63 |
Correct |
1233 ms |
66048 KB |
Output is correct |
64 |
Correct |
1204 ms |
65936 KB |
Output is correct |
65 |
Correct |
1319 ms |
70308 KB |
Output is correct |
66 |
Correct |
1245 ms |
70288 KB |
Output is correct |
67 |
Correct |
1269 ms |
70400 KB |
Output is correct |
68 |
Correct |
1248 ms |
70384 KB |
Output is correct |
69 |
Correct |
1273 ms |
70228 KB |
Output is correct |
70 |
Correct |
1262 ms |
70452 KB |
Output is correct |
71 |
Correct |
1263 ms |
70288 KB |
Output is correct |
72 |
Correct |
1264 ms |
70416 KB |
Output is correct |
73 |
Correct |
1058 ms |
66160 KB |
Output is correct |
74 |
Correct |
1093 ms |
66064 KB |
Output is correct |
75 |
Correct |
1060 ms |
66248 KB |
Output is correct |
76 |
Correct |
1063 ms |
66192 KB |
Output is correct |
77 |
Correct |
1150 ms |
65936 KB |
Output is correct |
78 |
Correct |
1148 ms |
65936 KB |
Output is correct |
79 |
Correct |
873 ms |
54296 KB |
Output is correct |
80 |
Correct |
1240 ms |
69520 KB |
Output is correct |