#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn=1e6+5;
int n,m,l,r,k[maxn],w[maxn],T[4*maxn];
int ans[maxn];
vector<pair<int,int>>qr[maxn];
stack<pair<int,int>>s;
void upd(int pos,int val,int l,int r,int nd){
if(l == r){
T[nd] = max(T[nd],val);
return;
}
if(pos <= (l+r)/2) upd(pos,val,l,(l+r)/2,nd*2);
else upd(pos,val,(l+r)/2+1,r,nd*2+1);
T[nd] = max(T[nd*2],T[nd*2+1]);
}
int tap(int a,int b,int l,int r,int nd){
if(r < a or l > b) return 0;
if(l >= a and r <= b) return T[nd];
return max(tap(a,b,l,(l+r)/2,nd*2),tap(a,b,(l+r)/2+1,r,nd*2+1));
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for(int i = 1;i <= n;i++) cin >> w[i];
for(int i = 1;i <= m;i++){
cin >> l >> r >> k[i];
qr[r].push_back({l,i});
}
for(int i = 1;i <= n;i++){
while(!s.empty() and s.top().first <= w[i]) s.pop();
if(!s.empty()){
upd(s.top().second,s.top().first+w[i],1,n,1);
}
s.push({w[i],i});
for(auto j : qr[i]){
int jog = tap(j.first,i,1,n,1);
if(jog <= k[j.second]) ans[j.second]=1;
}
}
for(int i = 1;i <= m;i++) cout<<ans[i]<<'\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
23788 KB |
Output is correct |
2 |
Correct |
19 ms |
23788 KB |
Output is correct |
3 |
Correct |
17 ms |
23916 KB |
Output is correct |
4 |
Correct |
16 ms |
23916 KB |
Output is correct |
5 |
Correct |
17 ms |
23916 KB |
Output is correct |
6 |
Correct |
18 ms |
23916 KB |
Output is correct |
7 |
Correct |
17 ms |
23916 KB |
Output is correct |
8 |
Correct |
17 ms |
23936 KB |
Output is correct |
9 |
Correct |
17 ms |
23916 KB |
Output is correct |
10 |
Correct |
17 ms |
23916 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
23788 KB |
Output is correct |
2 |
Correct |
19 ms |
23788 KB |
Output is correct |
3 |
Correct |
17 ms |
23916 KB |
Output is correct |
4 |
Correct |
16 ms |
23916 KB |
Output is correct |
5 |
Correct |
17 ms |
23916 KB |
Output is correct |
6 |
Correct |
18 ms |
23916 KB |
Output is correct |
7 |
Correct |
17 ms |
23916 KB |
Output is correct |
8 |
Correct |
17 ms |
23936 KB |
Output is correct |
9 |
Correct |
17 ms |
23916 KB |
Output is correct |
10 |
Correct |
17 ms |
23916 KB |
Output is correct |
11 |
Correct |
19 ms |
24044 KB |
Output is correct |
12 |
Correct |
20 ms |
24172 KB |
Output is correct |
13 |
Correct |
20 ms |
24172 KB |
Output is correct |
14 |
Correct |
22 ms |
24300 KB |
Output is correct |
15 |
Correct |
23 ms |
24300 KB |
Output is correct |
16 |
Correct |
20 ms |
24172 KB |
Output is correct |
17 |
Correct |
20 ms |
24172 KB |
Output is correct |
18 |
Correct |
20 ms |
24172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1808 ms |
62060 KB |
Output is correct |
2 |
Correct |
1786 ms |
67564 KB |
Output is correct |
3 |
Correct |
1746 ms |
67820 KB |
Output is correct |
4 |
Correct |
1777 ms |
67008 KB |
Output is correct |
5 |
Correct |
1452 ms |
57828 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
138 ms |
30188 KB |
Output is correct |
2 |
Correct |
126 ms |
29676 KB |
Output is correct |
3 |
Correct |
119 ms |
28940 KB |
Output is correct |
4 |
Correct |
112 ms |
29036 KB |
Output is correct |
5 |
Correct |
118 ms |
29164 KB |
Output is correct |
6 |
Correct |
93 ms |
27884 KB |
Output is correct |
7 |
Correct |
100 ms |
27884 KB |
Output is correct |
8 |
Correct |
117 ms |
28644 KB |
Output is correct |
9 |
Correct |
61 ms |
27236 KB |
Output is correct |
10 |
Correct |
142 ms |
28772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
23788 KB |
Output is correct |
2 |
Correct |
19 ms |
23788 KB |
Output is correct |
3 |
Correct |
17 ms |
23916 KB |
Output is correct |
4 |
Correct |
16 ms |
23916 KB |
Output is correct |
5 |
Correct |
17 ms |
23916 KB |
Output is correct |
6 |
Correct |
18 ms |
23916 KB |
Output is correct |
7 |
Correct |
17 ms |
23916 KB |
Output is correct |
8 |
Correct |
17 ms |
23936 KB |
Output is correct |
9 |
Correct |
17 ms |
23916 KB |
Output is correct |
10 |
Correct |
17 ms |
23916 KB |
Output is correct |
11 |
Correct |
19 ms |
24044 KB |
Output is correct |
12 |
Correct |
20 ms |
24172 KB |
Output is correct |
13 |
Correct |
20 ms |
24172 KB |
Output is correct |
14 |
Correct |
22 ms |
24300 KB |
Output is correct |
15 |
Correct |
23 ms |
24300 KB |
Output is correct |
16 |
Correct |
20 ms |
24172 KB |
Output is correct |
17 |
Correct |
20 ms |
24172 KB |
Output is correct |
18 |
Correct |
20 ms |
24172 KB |
Output is correct |
19 |
Correct |
310 ms |
38764 KB |
Output is correct |
20 |
Correct |
298 ms |
38252 KB |
Output is correct |
21 |
Correct |
261 ms |
36972 KB |
Output is correct |
22 |
Correct |
260 ms |
36832 KB |
Output is correct |
23 |
Correct |
261 ms |
37100 KB |
Output is correct |
24 |
Correct |
232 ms |
34668 KB |
Output is correct |
25 |
Correct |
218 ms |
34668 KB |
Output is correct |
26 |
Correct |
238 ms |
35308 KB |
Output is correct |
27 |
Correct |
242 ms |
35308 KB |
Output is correct |
28 |
Correct |
248 ms |
35436 KB |
Output is correct |
29 |
Correct |
258 ms |
36076 KB |
Output is correct |
30 |
Correct |
259 ms |
36204 KB |
Output is correct |
31 |
Correct |
253 ms |
36076 KB |
Output is correct |
32 |
Correct |
248 ms |
36076 KB |
Output is correct |
33 |
Correct |
266 ms |
36076 KB |
Output is correct |
34 |
Correct |
208 ms |
34284 KB |
Output is correct |
35 |
Correct |
207 ms |
34284 KB |
Output is correct |
36 |
Correct |
196 ms |
34156 KB |
Output is correct |
37 |
Correct |
195 ms |
34028 KB |
Output is correct |
38 |
Correct |
226 ms |
34312 KB |
Output is correct |
39 |
Correct |
227 ms |
35684 KB |
Output is correct |
40 |
Correct |
176 ms |
33888 KB |
Output is correct |
41 |
Correct |
224 ms |
34896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
23788 KB |
Output is correct |
2 |
Correct |
19 ms |
23788 KB |
Output is correct |
3 |
Correct |
17 ms |
23916 KB |
Output is correct |
4 |
Correct |
16 ms |
23916 KB |
Output is correct |
5 |
Correct |
17 ms |
23916 KB |
Output is correct |
6 |
Correct |
18 ms |
23916 KB |
Output is correct |
7 |
Correct |
17 ms |
23916 KB |
Output is correct |
8 |
Correct |
17 ms |
23936 KB |
Output is correct |
9 |
Correct |
17 ms |
23916 KB |
Output is correct |
10 |
Correct |
17 ms |
23916 KB |
Output is correct |
11 |
Correct |
19 ms |
24044 KB |
Output is correct |
12 |
Correct |
20 ms |
24172 KB |
Output is correct |
13 |
Correct |
20 ms |
24172 KB |
Output is correct |
14 |
Correct |
22 ms |
24300 KB |
Output is correct |
15 |
Correct |
23 ms |
24300 KB |
Output is correct |
16 |
Correct |
20 ms |
24172 KB |
Output is correct |
17 |
Correct |
20 ms |
24172 KB |
Output is correct |
18 |
Correct |
20 ms |
24172 KB |
Output is correct |
19 |
Correct |
1808 ms |
62060 KB |
Output is correct |
20 |
Correct |
1786 ms |
67564 KB |
Output is correct |
21 |
Correct |
1746 ms |
67820 KB |
Output is correct |
22 |
Correct |
1777 ms |
67008 KB |
Output is correct |
23 |
Correct |
1452 ms |
57828 KB |
Output is correct |
24 |
Correct |
138 ms |
30188 KB |
Output is correct |
25 |
Correct |
126 ms |
29676 KB |
Output is correct |
26 |
Correct |
119 ms |
28940 KB |
Output is correct |
27 |
Correct |
112 ms |
29036 KB |
Output is correct |
28 |
Correct |
118 ms |
29164 KB |
Output is correct |
29 |
Correct |
93 ms |
27884 KB |
Output is correct |
30 |
Correct |
100 ms |
27884 KB |
Output is correct |
31 |
Correct |
117 ms |
28644 KB |
Output is correct |
32 |
Correct |
61 ms |
27236 KB |
Output is correct |
33 |
Correct |
142 ms |
28772 KB |
Output is correct |
34 |
Correct |
310 ms |
38764 KB |
Output is correct |
35 |
Correct |
298 ms |
38252 KB |
Output is correct |
36 |
Correct |
261 ms |
36972 KB |
Output is correct |
37 |
Correct |
260 ms |
36832 KB |
Output is correct |
38 |
Correct |
261 ms |
37100 KB |
Output is correct |
39 |
Correct |
232 ms |
34668 KB |
Output is correct |
40 |
Correct |
218 ms |
34668 KB |
Output is correct |
41 |
Correct |
238 ms |
35308 KB |
Output is correct |
42 |
Correct |
242 ms |
35308 KB |
Output is correct |
43 |
Correct |
248 ms |
35436 KB |
Output is correct |
44 |
Correct |
258 ms |
36076 KB |
Output is correct |
45 |
Correct |
259 ms |
36204 KB |
Output is correct |
46 |
Correct |
253 ms |
36076 KB |
Output is correct |
47 |
Correct |
248 ms |
36076 KB |
Output is correct |
48 |
Correct |
266 ms |
36076 KB |
Output is correct |
49 |
Correct |
208 ms |
34284 KB |
Output is correct |
50 |
Correct |
207 ms |
34284 KB |
Output is correct |
51 |
Correct |
196 ms |
34156 KB |
Output is correct |
52 |
Correct |
195 ms |
34028 KB |
Output is correct |
53 |
Correct |
226 ms |
34312 KB |
Output is correct |
54 |
Correct |
227 ms |
35684 KB |
Output is correct |
55 |
Correct |
176 ms |
33888 KB |
Output is correct |
56 |
Correct |
224 ms |
34896 KB |
Output is correct |
57 |
Correct |
1790 ms |
64984 KB |
Output is correct |
58 |
Correct |
1773 ms |
65192 KB |
Output is correct |
59 |
Correct |
1684 ms |
62440 KB |
Output is correct |
60 |
Correct |
1718 ms |
62320 KB |
Output is correct |
61 |
Correct |
1716 ms |
62276 KB |
Output is correct |
62 |
Correct |
1695 ms |
62172 KB |
Output is correct |
63 |
Correct |
1114 ms |
50284 KB |
Output is correct |
64 |
Correct |
1111 ms |
50312 KB |
Output is correct |
65 |
Correct |
1370 ms |
53848 KB |
Output is correct |
66 |
Correct |
1366 ms |
53740 KB |
Output is correct |
67 |
Correct |
1382 ms |
53996 KB |
Output is correct |
68 |
Correct |
1425 ms |
56968 KB |
Output is correct |
69 |
Correct |
1409 ms |
56696 KB |
Output is correct |
70 |
Correct |
1438 ms |
56300 KB |
Output is correct |
71 |
Correct |
1423 ms |
56172 KB |
Output is correct |
72 |
Correct |
1422 ms |
56404 KB |
Output is correct |
73 |
Correct |
1008 ms |
48804 KB |
Output is correct |
74 |
Correct |
1043 ms |
48492 KB |
Output is correct |
75 |
Correct |
1004 ms |
48768 KB |
Output is correct |
76 |
Correct |
1008 ms |
48624 KB |
Output is correct |
77 |
Correct |
1002 ms |
48588 KB |
Output is correct |
78 |
Correct |
1264 ms |
57516 KB |
Output is correct |
79 |
Correct |
888 ms |
50936 KB |
Output is correct |
80 |
Correct |
1226 ms |
55056 KB |
Output is correct |