#include"bits/stdc++.h"
using namespace std;
#define ll long long
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false)
#define inf LLONG_MAX
const int lmt=1e6+10;
vector<int>adj[5*lmt];
int a[lmt],mx,tree[5*lmt];
void build(int at,int L,int R){
if(L==R){
adj[at].push_back(a[L]);
return;
}
int mid=(L+R)>>1;
build(at*2,L,mid);
build(at*2+1,mid+1,R);
int res=adj[at*2].back();
int lo=0,hi=adj[at*2+1].size()-1;
while(hi-lo>1){
mid=(lo+hi)>>1;
if(adj[at*2+1][mid]<res) lo=mid;
else hi=mid;
}
tree[at]=max(tree[at*2],tree[at*2+1]);
if(adj[at*2+1][hi]<res) tree[at]=max(tree[at],res+adj[at*2+1][hi]);
else if(adj[at*2+1][lo]<res) tree[at]=max(tree[at],res+adj[at*2+1][lo]);
adj[at]=adj[at*2];
adj[at].insert(adj[at].end(),adj[at*2+1].begin(),adj[at*2+1].end());
sort(adj[at].begin(),adj[at].end());
}
int query(int at,int L,int R,int l,int r){
if(r<L || R<l || r<l) return 0;
if(l<=L && R<=r){
if(L==l){
mx=max(mx,adj[at].back());
return tree[at];
}else if(adj[at][0]>=mx){
mx=max(mx,adj[at].back());
return tree[at];
}else{
int lo=0,hi=adj[at].size()-1;
while(hi-lo>1){
int mid=(lo+hi)>>1;
if(adj[at][mid]<mx) lo=mid;
else hi=mid;
}
int res=tree[at];
if(adj[at][hi]<mx){
res=max(res,mx+adj[at][hi]);
}else if(adj[at][lo]<mx){
res=max(res,mx+adj[at][lo]);
}
mx=max(mx,adj[at].back());
return res;
}
}
int mid=(L+R)>>1;
int x=query(at*2,L,mid,l,r),y=query(at*2+1,mid+1,R,l,r);
return max(x,y);
}
int main(){
fastio;
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>a[i];
}
build(1,1,n);
for(int i=1;i<=m;i++){
int l,r,k;
cin>>l>>r>>k;
int res=query(1,1,n,l,r);
bool ans=(k>=res);
cout<<ans<<endl;
mx=0;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
53 ms |
117680 KB |
Output is correct |
2 |
Correct |
51 ms |
117700 KB |
Output is correct |
3 |
Correct |
53 ms |
117704 KB |
Output is correct |
4 |
Correct |
52 ms |
117672 KB |
Output is correct |
5 |
Correct |
56 ms |
117716 KB |
Output is correct |
6 |
Correct |
53 ms |
117700 KB |
Output is correct |
7 |
Correct |
53 ms |
117668 KB |
Output is correct |
8 |
Correct |
54 ms |
117728 KB |
Output is correct |
9 |
Correct |
53 ms |
117632 KB |
Output is correct |
10 |
Correct |
57 ms |
117656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
53 ms |
117680 KB |
Output is correct |
2 |
Correct |
51 ms |
117700 KB |
Output is correct |
3 |
Correct |
53 ms |
117704 KB |
Output is correct |
4 |
Correct |
52 ms |
117672 KB |
Output is correct |
5 |
Correct |
56 ms |
117716 KB |
Output is correct |
6 |
Correct |
53 ms |
117700 KB |
Output is correct |
7 |
Correct |
53 ms |
117668 KB |
Output is correct |
8 |
Correct |
54 ms |
117728 KB |
Output is correct |
9 |
Correct |
53 ms |
117632 KB |
Output is correct |
10 |
Correct |
57 ms |
117656 KB |
Output is correct |
11 |
Correct |
58 ms |
117800 KB |
Output is correct |
12 |
Correct |
63 ms |
118256 KB |
Output is correct |
13 |
Correct |
61 ms |
118272 KB |
Output is correct |
14 |
Correct |
65 ms |
118212 KB |
Output is correct |
15 |
Correct |
65 ms |
118292 KB |
Output is correct |
16 |
Correct |
65 ms |
118236 KB |
Output is correct |
17 |
Correct |
63 ms |
118164 KB |
Output is correct |
18 |
Correct |
75 ms |
118248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3084 ms |
258844 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
445 ms |
130468 KB |
Output is correct |
2 |
Correct |
420 ms |
130484 KB |
Output is correct |
3 |
Correct |
306 ms |
130520 KB |
Output is correct |
4 |
Correct |
313 ms |
130500 KB |
Output is correct |
5 |
Correct |
319 ms |
130476 KB |
Output is correct |
6 |
Correct |
279 ms |
130500 KB |
Output is correct |
7 |
Correct |
277 ms |
130476 KB |
Output is correct |
8 |
Correct |
308 ms |
130512 KB |
Output is correct |
9 |
Correct |
202 ms |
117856 KB |
Output is correct |
10 |
Correct |
305 ms |
130500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
53 ms |
117680 KB |
Output is correct |
2 |
Correct |
51 ms |
117700 KB |
Output is correct |
3 |
Correct |
53 ms |
117704 KB |
Output is correct |
4 |
Correct |
52 ms |
117672 KB |
Output is correct |
5 |
Correct |
56 ms |
117716 KB |
Output is correct |
6 |
Correct |
53 ms |
117700 KB |
Output is correct |
7 |
Correct |
53 ms |
117668 KB |
Output is correct |
8 |
Correct |
54 ms |
117728 KB |
Output is correct |
9 |
Correct |
53 ms |
117632 KB |
Output is correct |
10 |
Correct |
57 ms |
117656 KB |
Output is correct |
11 |
Correct |
58 ms |
117800 KB |
Output is correct |
12 |
Correct |
63 ms |
118256 KB |
Output is correct |
13 |
Correct |
61 ms |
118272 KB |
Output is correct |
14 |
Correct |
65 ms |
118212 KB |
Output is correct |
15 |
Correct |
65 ms |
118292 KB |
Output is correct |
16 |
Correct |
65 ms |
118236 KB |
Output is correct |
17 |
Correct |
63 ms |
118164 KB |
Output is correct |
18 |
Correct |
75 ms |
118248 KB |
Output is correct |
19 |
Correct |
994 ms |
144128 KB |
Output is correct |
20 |
Correct |
988 ms |
144108 KB |
Output is correct |
21 |
Correct |
889 ms |
144116 KB |
Output is correct |
22 |
Correct |
899 ms |
144192 KB |
Output is correct |
23 |
Correct |
882 ms |
144172 KB |
Output is correct |
24 |
Correct |
526 ms |
144000 KB |
Output is correct |
25 |
Correct |
561 ms |
144104 KB |
Output is correct |
26 |
Correct |
605 ms |
144200 KB |
Output is correct |
27 |
Correct |
590 ms |
144096 KB |
Output is correct |
28 |
Correct |
629 ms |
144068 KB |
Output is correct |
29 |
Correct |
628 ms |
144000 KB |
Output is correct |
30 |
Correct |
611 ms |
144000 KB |
Output is correct |
31 |
Correct |
655 ms |
144000 KB |
Output is correct |
32 |
Correct |
634 ms |
144076 KB |
Output is correct |
33 |
Correct |
643 ms |
144244 KB |
Output is correct |
34 |
Correct |
534 ms |
144128 KB |
Output is correct |
35 |
Correct |
524 ms |
144000 KB |
Output is correct |
36 |
Correct |
528 ms |
144108 KB |
Output is correct |
37 |
Correct |
534 ms |
144096 KB |
Output is correct |
38 |
Correct |
530 ms |
143996 KB |
Output is correct |
39 |
Correct |
647 ms |
144028 KB |
Output is correct |
40 |
Correct |
497 ms |
134808 KB |
Output is correct |
41 |
Correct |
638 ms |
144336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
53 ms |
117680 KB |
Output is correct |
2 |
Correct |
51 ms |
117700 KB |
Output is correct |
3 |
Correct |
53 ms |
117704 KB |
Output is correct |
4 |
Correct |
52 ms |
117672 KB |
Output is correct |
5 |
Correct |
56 ms |
117716 KB |
Output is correct |
6 |
Correct |
53 ms |
117700 KB |
Output is correct |
7 |
Correct |
53 ms |
117668 KB |
Output is correct |
8 |
Correct |
54 ms |
117728 KB |
Output is correct |
9 |
Correct |
53 ms |
117632 KB |
Output is correct |
10 |
Correct |
57 ms |
117656 KB |
Output is correct |
11 |
Correct |
58 ms |
117800 KB |
Output is correct |
12 |
Correct |
63 ms |
118256 KB |
Output is correct |
13 |
Correct |
61 ms |
118272 KB |
Output is correct |
14 |
Correct |
65 ms |
118212 KB |
Output is correct |
15 |
Correct |
65 ms |
118292 KB |
Output is correct |
16 |
Correct |
65 ms |
118236 KB |
Output is correct |
17 |
Correct |
63 ms |
118164 KB |
Output is correct |
18 |
Correct |
75 ms |
118248 KB |
Output is correct |
19 |
Execution timed out |
3084 ms |
258844 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |