#include <bits/stdc++.h>
using namespace std;
#define getar(ar,n) for(int i=0;i<n;++i) cin>>ar[i]
#define show(n) cout<<n<<'\n'
#define all(v) v.begin(), v.end()
#define br cout<<"\n"
#define pb push_back
#define nl '\n'
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define ret return
#define ld long double
#define sza(x) ((int)x.size())
struct Node{
vector<int> vec;
int mx=0,bad_mx=0;
};
vector<int> ar;
vector<Node> seg;
int mx=0;
void build(int node,int start,int end){
if(start==end){
seg[node].vec={ar[start]};
seg[node].mx=ar[start];
seg[node].bad_mx=0;
return;
}
int mid=start+(end-start)/2;
build(node*2+1,start,mid);
build(node*2+2,mid+1,end);
seg[node].vec.assign(seg[node*2+1].vec.size()+seg[node*2+2].vec.size(),0);
merge(all(seg[node*2+1].vec),all(seg[node*2+2].vec),seg[node].vec.begin());
seg[node].mx=max(seg[node*2+1].mx,seg[node*2+2].mx);
int mxx=0;
for(int i=start;i<=end;++i){
if(mxx>ar[i]){
seg[node].bad_mx=max(seg[node].bad_mx,mxx+ar[i]);
}else{
mxx=ar[i];
}
}
}
bool qry(int nd,int start,int end,int l,int r,int k){
if(start>r||end<l) return 1;
if(start>=l&&end<=r){
bool f=(max(seg[nd].bad_mx,(mx>seg[nd].vec[0]?mx+*--lower_bound(all(seg[nd].vec),mx):0))<=k);
mx=max(mx,seg[nd].mx);
return f;
}
int mid=start+(end-start)/2;
return ((!qry(nd*2+1,start,mid,l,r,k)||!qry(nd*2+2,mid+1,end,l,r,k))?0:1);
}
void solve(){
int n,l,r,w,q;cin>>n>>q;
ar.resize(n+1);
for(int i=0;i<n;++i){
cin>>ar[i];
}
seg.resize(n<<2);
build(0,0,n-1);
while(q--){
cin>>l>>r>>w;
mx=0;
cout<<(qry(0,0,n-1,l-1,r-1,w))<<nl;
}
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
472 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
472 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
856 KB |
Output is correct |
12 |
Correct |
3 ms |
1488 KB |
Output is correct |
13 |
Correct |
3 ms |
1624 KB |
Output is correct |
14 |
Correct |
4 ms |
1628 KB |
Output is correct |
15 |
Correct |
3 ms |
1628 KB |
Output is correct |
16 |
Correct |
3 ms |
1628 KB |
Output is correct |
17 |
Correct |
2 ms |
1372 KB |
Output is correct |
18 |
Correct |
3 ms |
1624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
986 ms |
262144 KB |
Output is correct |
2 |
Correct |
976 ms |
262144 KB |
Output is correct |
3 |
Correct |
1067 ms |
262144 KB |
Output is correct |
4 |
Correct |
1092 ms |
262144 KB |
Output is correct |
5 |
Correct |
1383 ms |
262144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
26148 KB |
Output is correct |
2 |
Correct |
72 ms |
26192 KB |
Output is correct |
3 |
Correct |
77 ms |
26192 KB |
Output is correct |
4 |
Correct |
82 ms |
26452 KB |
Output is correct |
5 |
Correct |
75 ms |
26192 KB |
Output is correct |
6 |
Correct |
54 ms |
26196 KB |
Output is correct |
7 |
Correct |
53 ms |
26284 KB |
Output is correct |
8 |
Correct |
67 ms |
25936 KB |
Output is correct |
9 |
Correct |
25 ms |
1616 KB |
Output is correct |
10 |
Correct |
66 ms |
25936 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
472 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
856 KB |
Output is correct |
12 |
Correct |
3 ms |
1488 KB |
Output is correct |
13 |
Correct |
3 ms |
1624 KB |
Output is correct |
14 |
Correct |
4 ms |
1628 KB |
Output is correct |
15 |
Correct |
3 ms |
1628 KB |
Output is correct |
16 |
Correct |
3 ms |
1628 KB |
Output is correct |
17 |
Correct |
2 ms |
1372 KB |
Output is correct |
18 |
Correct |
3 ms |
1624 KB |
Output is correct |
19 |
Correct |
201 ms |
53840 KB |
Output is correct |
20 |
Correct |
202 ms |
53844 KB |
Output is correct |
21 |
Correct |
172 ms |
53840 KB |
Output is correct |
22 |
Correct |
169 ms |
53808 KB |
Output is correct |
23 |
Correct |
164 ms |
53836 KB |
Output is correct |
24 |
Correct |
148 ms |
53840 KB |
Output is correct |
25 |
Correct |
159 ms |
53636 KB |
Output is correct |
26 |
Correct |
175 ms |
53924 KB |
Output is correct |
27 |
Correct |
176 ms |
53800 KB |
Output is correct |
28 |
Correct |
185 ms |
53840 KB |
Output is correct |
29 |
Correct |
195 ms |
53848 KB |
Output is correct |
30 |
Correct |
225 ms |
55568 KB |
Output is correct |
31 |
Correct |
198 ms |
55636 KB |
Output is correct |
32 |
Correct |
218 ms |
55744 KB |
Output is correct |
33 |
Correct |
213 ms |
55632 KB |
Output is correct |
34 |
Correct |
133 ms |
55380 KB |
Output is correct |
35 |
Correct |
138 ms |
55524 KB |
Output is correct |
36 |
Correct |
129 ms |
55204 KB |
Output is correct |
37 |
Correct |
129 ms |
55156 KB |
Output is correct |
38 |
Correct |
136 ms |
55364 KB |
Output is correct |
39 |
Correct |
148 ms |
54772 KB |
Output is correct |
40 |
Correct |
117 ms |
36868 KB |
Output is correct |
41 |
Correct |
131 ms |
54076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
472 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
856 KB |
Output is correct |
12 |
Correct |
3 ms |
1488 KB |
Output is correct |
13 |
Correct |
3 ms |
1624 KB |
Output is correct |
14 |
Correct |
4 ms |
1628 KB |
Output is correct |
15 |
Correct |
3 ms |
1628 KB |
Output is correct |
16 |
Correct |
3 ms |
1628 KB |
Output is correct |
17 |
Correct |
2 ms |
1372 KB |
Output is correct |
18 |
Correct |
3 ms |
1624 KB |
Output is correct |
19 |
Correct |
986 ms |
262144 KB |
Output is correct |
20 |
Correct |
976 ms |
262144 KB |
Output is correct |
21 |
Correct |
1067 ms |
262144 KB |
Output is correct |
22 |
Correct |
1092 ms |
262144 KB |
Output is correct |
23 |
Correct |
1383 ms |
262144 KB |
Output is correct |
24 |
Correct |
80 ms |
26148 KB |
Output is correct |
25 |
Correct |
72 ms |
26192 KB |
Output is correct |
26 |
Correct |
77 ms |
26192 KB |
Output is correct |
27 |
Correct |
82 ms |
26452 KB |
Output is correct |
28 |
Correct |
75 ms |
26192 KB |
Output is correct |
29 |
Correct |
54 ms |
26196 KB |
Output is correct |
30 |
Correct |
53 ms |
26284 KB |
Output is correct |
31 |
Correct |
67 ms |
25936 KB |
Output is correct |
32 |
Correct |
25 ms |
1616 KB |
Output is correct |
33 |
Correct |
66 ms |
25936 KB |
Output is correct |
34 |
Correct |
201 ms |
53840 KB |
Output is correct |
35 |
Correct |
202 ms |
53844 KB |
Output is correct |
36 |
Correct |
172 ms |
53840 KB |
Output is correct |
37 |
Correct |
169 ms |
53808 KB |
Output is correct |
38 |
Correct |
164 ms |
53836 KB |
Output is correct |
39 |
Correct |
148 ms |
53840 KB |
Output is correct |
40 |
Correct |
159 ms |
53636 KB |
Output is correct |
41 |
Correct |
175 ms |
53924 KB |
Output is correct |
42 |
Correct |
176 ms |
53800 KB |
Output is correct |
43 |
Correct |
185 ms |
53840 KB |
Output is correct |
44 |
Correct |
195 ms |
53848 KB |
Output is correct |
45 |
Correct |
225 ms |
55568 KB |
Output is correct |
46 |
Correct |
198 ms |
55636 KB |
Output is correct |
47 |
Correct |
218 ms |
55744 KB |
Output is correct |
48 |
Correct |
213 ms |
55632 KB |
Output is correct |
49 |
Correct |
133 ms |
55380 KB |
Output is correct |
50 |
Correct |
138 ms |
55524 KB |
Output is correct |
51 |
Correct |
129 ms |
55204 KB |
Output is correct |
52 |
Correct |
129 ms |
55156 KB |
Output is correct |
53 |
Correct |
136 ms |
55364 KB |
Output is correct |
54 |
Correct |
148 ms |
54772 KB |
Output is correct |
55 |
Correct |
117 ms |
36868 KB |
Output is correct |
56 |
Correct |
131 ms |
54076 KB |
Output is correct |
57 |
Correct |
1291 ms |
262144 KB |
Output is correct |
58 |
Correct |
1345 ms |
262144 KB |
Output is correct |
59 |
Correct |
1334 ms |
262144 KB |
Output is correct |
60 |
Correct |
1341 ms |
262144 KB |
Output is correct |
61 |
Correct |
1271 ms |
262144 KB |
Output is correct |
62 |
Correct |
1183 ms |
262144 KB |
Output is correct |
63 |
Correct |
787 ms |
262144 KB |
Output is correct |
64 |
Correct |
845 ms |
262144 KB |
Output is correct |
65 |
Correct |
1406 ms |
262144 KB |
Output is correct |
66 |
Correct |
1408 ms |
262144 KB |
Output is correct |
67 |
Runtime error |
1477 ms |
262176 KB |
Memory limit exceeded |
68 |
Halted |
0 ms |
0 KB |
- |