#include <bits/stdc++.h>
using namespace std;
const int N=1e6+4;
vector<int>st[4*N];
int mx[4*N],a[N],cur,ans,n,q;
void build(int node=1,int tl=0,int tr=n-1){
if(tl==tr){
mx[node]=0;
st[node]={a[tr]};
return;
}
int mid=(tl+tr)/2;
build(node*2,tl,mid);
build(node*2+1,mid+1,tr);
st[node].resize((int)st[node*2].size()+(int)st[node*2+1].size());
merge(st[node*2].begin(),st[node*2].end(),st[node*2+1].begin(),st[node*2+1].end(),st[node].begin());
mx[node]=max(mx[node*2],mx[node*2+1]);
int levi=st[node*2].back();
auto it=upper_bound(st[node*2+1].begin(),st[node*2+1].end(),levi-1);
if(it!=st[node*2+1].begin())
it=prev(it);
if(*it<levi)
mx[node]=max(mx[node],*it+levi);
}
void qry(int l,int r,int node=1,int tl=0,int tr=n-1){
if(tl>=l&&tr<=r){
ans=max(ans,mx[node]);
assert(st[node].size());
auto it=upper_bound(st[node].begin(),st[node].end(),cur-1);
if(it!=st[node].begin())
it=prev(it);
if(*it<cur)
ans=max(ans,*it+cur);
cur=max(cur,st[node].back());
return;
}
int mid=(tl+tr)/2;
if(mid>=l)qry(l,r,2*node,tl,mid);
if(mid<=r-1)qry(l,r,2*node+1,mid+1,tr);
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin>>n>>q;
for(int i=0;i<n;++i)
cin>>a[i];
build();
while(q--){
int l,r,k;
cin>>l>>r>>k;
--l,--r;
cur=0,ans=0;
qry(l,r);
cout<<(ans<=k)<<'\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
48 ms |
95304 KB |
Output is correct |
2 |
Correct |
53 ms |
95136 KB |
Output is correct |
3 |
Correct |
51 ms |
95304 KB |
Output is correct |
4 |
Correct |
47 ms |
95280 KB |
Output is correct |
5 |
Correct |
59 ms |
95308 KB |
Output is correct |
6 |
Correct |
64 ms |
95212 KB |
Output is correct |
7 |
Correct |
65 ms |
95304 KB |
Output is correct |
8 |
Correct |
55 ms |
95316 KB |
Output is correct |
9 |
Correct |
60 ms |
95320 KB |
Output is correct |
10 |
Correct |
65 ms |
95216 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
48 ms |
95304 KB |
Output is correct |
2 |
Correct |
53 ms |
95136 KB |
Output is correct |
3 |
Correct |
51 ms |
95304 KB |
Output is correct |
4 |
Correct |
47 ms |
95280 KB |
Output is correct |
5 |
Correct |
59 ms |
95308 KB |
Output is correct |
6 |
Correct |
64 ms |
95212 KB |
Output is correct |
7 |
Correct |
65 ms |
95304 KB |
Output is correct |
8 |
Correct |
55 ms |
95316 KB |
Output is correct |
9 |
Correct |
60 ms |
95320 KB |
Output is correct |
10 |
Correct |
65 ms |
95216 KB |
Output is correct |
11 |
Correct |
59 ms |
95412 KB |
Output is correct |
12 |
Correct |
59 ms |
95816 KB |
Output is correct |
13 |
Correct |
64 ms |
95892 KB |
Output is correct |
14 |
Correct |
66 ms |
95816 KB |
Output is correct |
15 |
Correct |
63 ms |
95816 KB |
Output is correct |
16 |
Correct |
57 ms |
95876 KB |
Output is correct |
17 |
Correct |
66 ms |
94824 KB |
Output is correct |
18 |
Correct |
63 ms |
94920 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2414 ms |
237800 KB |
Output is correct |
2 |
Correct |
2231 ms |
260868 KB |
Output is correct |
3 |
Correct |
2308 ms |
255316 KB |
Output is correct |
4 |
Correct |
2146 ms |
262144 KB |
Output is correct |
5 |
Correct |
1951 ms |
261328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
198 ms |
108360 KB |
Output is correct |
2 |
Correct |
165 ms |
110152 KB |
Output is correct |
3 |
Correct |
159 ms |
109640 KB |
Output is correct |
4 |
Correct |
164 ms |
108360 KB |
Output is correct |
5 |
Correct |
180 ms |
109640 KB |
Output is correct |
6 |
Correct |
142 ms |
110168 KB |
Output is correct |
7 |
Correct |
148 ms |
108360 KB |
Output is correct |
8 |
Correct |
147 ms |
108264 KB |
Output is correct |
9 |
Correct |
88 ms |
96592 KB |
Output is correct |
10 |
Correct |
145 ms |
109384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
48 ms |
95304 KB |
Output is correct |
2 |
Correct |
53 ms |
95136 KB |
Output is correct |
3 |
Correct |
51 ms |
95304 KB |
Output is correct |
4 |
Correct |
47 ms |
95280 KB |
Output is correct |
5 |
Correct |
59 ms |
95308 KB |
Output is correct |
6 |
Correct |
64 ms |
95212 KB |
Output is correct |
7 |
Correct |
65 ms |
95304 KB |
Output is correct |
8 |
Correct |
55 ms |
95316 KB |
Output is correct |
9 |
Correct |
60 ms |
95320 KB |
Output is correct |
10 |
Correct |
65 ms |
95216 KB |
Output is correct |
11 |
Correct |
59 ms |
95412 KB |
Output is correct |
12 |
Correct |
59 ms |
95816 KB |
Output is correct |
13 |
Correct |
64 ms |
95892 KB |
Output is correct |
14 |
Correct |
66 ms |
95816 KB |
Output is correct |
15 |
Correct |
63 ms |
95816 KB |
Output is correct |
16 |
Correct |
57 ms |
95876 KB |
Output is correct |
17 |
Correct |
66 ms |
94824 KB |
Output is correct |
18 |
Correct |
63 ms |
94920 KB |
Output is correct |
19 |
Correct |
361 ms |
127560 KB |
Output is correct |
20 |
Correct |
387 ms |
128328 KB |
Output is correct |
21 |
Correct |
295 ms |
125768 KB |
Output is correct |
22 |
Correct |
323 ms |
126024 KB |
Output is correct |
23 |
Correct |
306 ms |
128288 KB |
Output is correct |
24 |
Correct |
261 ms |
127316 KB |
Output is correct |
25 |
Correct |
281 ms |
127304 KB |
Output is correct |
26 |
Correct |
276 ms |
127644 KB |
Output is correct |
27 |
Correct |
334 ms |
127648 KB |
Output is correct |
28 |
Correct |
336 ms |
125788 KB |
Output is correct |
29 |
Correct |
315 ms |
125708 KB |
Output is correct |
30 |
Correct |
294 ms |
128332 KB |
Output is correct |
31 |
Correct |
308 ms |
128256 KB |
Output is correct |
32 |
Correct |
314 ms |
128428 KB |
Output is correct |
33 |
Correct |
300 ms |
128472 KB |
Output is correct |
34 |
Correct |
252 ms |
128080 KB |
Output is correct |
35 |
Correct |
262 ms |
127304 KB |
Output is correct |
36 |
Correct |
262 ms |
127816 KB |
Output is correct |
37 |
Correct |
229 ms |
127816 KB |
Output is correct |
38 |
Correct |
230 ms |
128080 KB |
Output is correct |
39 |
Correct |
278 ms |
125256 KB |
Output is correct |
40 |
Correct |
169 ms |
112628 KB |
Output is correct |
41 |
Correct |
241 ms |
124644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
48 ms |
95304 KB |
Output is correct |
2 |
Correct |
53 ms |
95136 KB |
Output is correct |
3 |
Correct |
51 ms |
95304 KB |
Output is correct |
4 |
Correct |
47 ms |
95280 KB |
Output is correct |
5 |
Correct |
59 ms |
95308 KB |
Output is correct |
6 |
Correct |
64 ms |
95212 KB |
Output is correct |
7 |
Correct |
65 ms |
95304 KB |
Output is correct |
8 |
Correct |
55 ms |
95316 KB |
Output is correct |
9 |
Correct |
60 ms |
95320 KB |
Output is correct |
10 |
Correct |
65 ms |
95216 KB |
Output is correct |
11 |
Correct |
59 ms |
95412 KB |
Output is correct |
12 |
Correct |
59 ms |
95816 KB |
Output is correct |
13 |
Correct |
64 ms |
95892 KB |
Output is correct |
14 |
Correct |
66 ms |
95816 KB |
Output is correct |
15 |
Correct |
63 ms |
95816 KB |
Output is correct |
16 |
Correct |
57 ms |
95876 KB |
Output is correct |
17 |
Correct |
66 ms |
94824 KB |
Output is correct |
18 |
Correct |
63 ms |
94920 KB |
Output is correct |
19 |
Correct |
2414 ms |
237800 KB |
Output is correct |
20 |
Correct |
2231 ms |
260868 KB |
Output is correct |
21 |
Correct |
2308 ms |
255316 KB |
Output is correct |
22 |
Correct |
2146 ms |
262144 KB |
Output is correct |
23 |
Correct |
1951 ms |
261328 KB |
Output is correct |
24 |
Correct |
198 ms |
108360 KB |
Output is correct |
25 |
Correct |
165 ms |
110152 KB |
Output is correct |
26 |
Correct |
159 ms |
109640 KB |
Output is correct |
27 |
Correct |
164 ms |
108360 KB |
Output is correct |
28 |
Correct |
180 ms |
109640 KB |
Output is correct |
29 |
Correct |
142 ms |
110168 KB |
Output is correct |
30 |
Correct |
148 ms |
108360 KB |
Output is correct |
31 |
Correct |
147 ms |
108264 KB |
Output is correct |
32 |
Correct |
88 ms |
96592 KB |
Output is correct |
33 |
Correct |
145 ms |
109384 KB |
Output is correct |
34 |
Correct |
361 ms |
127560 KB |
Output is correct |
35 |
Correct |
387 ms |
128328 KB |
Output is correct |
36 |
Correct |
295 ms |
125768 KB |
Output is correct |
37 |
Correct |
323 ms |
126024 KB |
Output is correct |
38 |
Correct |
306 ms |
128288 KB |
Output is correct |
39 |
Correct |
261 ms |
127316 KB |
Output is correct |
40 |
Correct |
281 ms |
127304 KB |
Output is correct |
41 |
Correct |
276 ms |
127644 KB |
Output is correct |
42 |
Correct |
334 ms |
127648 KB |
Output is correct |
43 |
Correct |
336 ms |
125788 KB |
Output is correct |
44 |
Correct |
315 ms |
125708 KB |
Output is correct |
45 |
Correct |
294 ms |
128332 KB |
Output is correct |
46 |
Correct |
308 ms |
128256 KB |
Output is correct |
47 |
Correct |
314 ms |
128428 KB |
Output is correct |
48 |
Correct |
300 ms |
128472 KB |
Output is correct |
49 |
Correct |
252 ms |
128080 KB |
Output is correct |
50 |
Correct |
262 ms |
127304 KB |
Output is correct |
51 |
Correct |
262 ms |
127816 KB |
Output is correct |
52 |
Correct |
229 ms |
127816 KB |
Output is correct |
53 |
Correct |
230 ms |
128080 KB |
Output is correct |
54 |
Correct |
278 ms |
125256 KB |
Output is correct |
55 |
Correct |
169 ms |
112628 KB |
Output is correct |
56 |
Correct |
241 ms |
124644 KB |
Output is correct |
57 |
Correct |
2170 ms |
260420 KB |
Output is correct |
58 |
Correct |
2085 ms |
248908 KB |
Output is correct |
59 |
Correct |
2079 ms |
262144 KB |
Output is correct |
60 |
Correct |
2053 ms |
260364 KB |
Output is correct |
61 |
Correct |
2043 ms |
260728 KB |
Output is correct |
62 |
Correct |
2049 ms |
262144 KB |
Output is correct |
63 |
Correct |
1210 ms |
258992 KB |
Output is correct |
64 |
Correct |
1137 ms |
246856 KB |
Output is correct |
65 |
Correct |
1631 ms |
248916 KB |
Output is correct |
66 |
Correct |
1761 ms |
262144 KB |
Output is correct |
67 |
Correct |
1803 ms |
262144 KB |
Output is correct |
68 |
Correct |
1693 ms |
248948 KB |
Output is correct |
69 |
Correct |
1889 ms |
262144 KB |
Output is correct |
70 |
Correct |
1822 ms |
262144 KB |
Output is correct |
71 |
Correct |
1864 ms |
260732 KB |
Output is correct |
72 |
Correct |
1748 ms |
262144 KB |
Output is correct |
73 |
Correct |
1133 ms |
262144 KB |
Output is correct |
74 |
Correct |
1158 ms |
262144 KB |
Output is correct |
75 |
Correct |
1124 ms |
262144 KB |
Output is correct |
76 |
Correct |
1126 ms |
245308 KB |
Output is correct |
77 |
Correct |
1141 ms |
257348 KB |
Output is correct |
78 |
Correct |
1574 ms |
242620 KB |
Output is correct |
79 |
Correct |
999 ms |
189256 KB |
Output is correct |
80 |
Correct |
1567 ms |
251304 KB |
Output is correct |