#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())
const int mxN = 1e6 + 10;
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];
}
Node dummy_node;
dummy_node.vec={};
dummy_node.mx=dummy_node.bad_mx=0;
seg.resize((n+10)*4,dummy_node);
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 |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 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 |
1 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 |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 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 |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
676 KB |
Output is correct |
12 |
Correct |
3 ms |
1628 KB |
Output is correct |
13 |
Correct |
3 ms |
1488 KB |
Output is correct |
14 |
Correct |
4 ms |
1628 KB |
Output is correct |
15 |
Correct |
4 ms |
1628 KB |
Output is correct |
16 |
Correct |
4 ms |
1720 KB |
Output is correct |
17 |
Correct |
3 ms |
1372 KB |
Output is correct |
18 |
Correct |
3 ms |
1628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1069 ms |
262144 KB |
Output is correct |
2 |
Correct |
1051 ms |
262144 KB |
Output is correct |
3 |
Correct |
1079 ms |
262144 KB |
Output is correct |
4 |
Correct |
1042 ms |
262144 KB |
Output is correct |
5 |
Correct |
1355 ms |
262144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
79 ms |
26884 KB |
Output is correct |
2 |
Correct |
73 ms |
26964 KB |
Output is correct |
3 |
Correct |
79 ms |
26960 KB |
Output is correct |
4 |
Correct |
80 ms |
26828 KB |
Output is correct |
5 |
Correct |
83 ms |
26920 KB |
Output is correct |
6 |
Correct |
54 ms |
26704 KB |
Output is correct |
7 |
Correct |
54 ms |
26704 KB |
Output is correct |
8 |
Correct |
58 ms |
26604 KB |
Output is correct |
9 |
Correct |
23 ms |
1884 KB |
Output is correct |
10 |
Correct |
63 ms |
26620 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 |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 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 |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
676 KB |
Output is correct |
12 |
Correct |
3 ms |
1628 KB |
Output is correct |
13 |
Correct |
3 ms |
1488 KB |
Output is correct |
14 |
Correct |
4 ms |
1628 KB |
Output is correct |
15 |
Correct |
4 ms |
1628 KB |
Output is correct |
16 |
Correct |
4 ms |
1720 KB |
Output is correct |
17 |
Correct |
3 ms |
1372 KB |
Output is correct |
18 |
Correct |
3 ms |
1628 KB |
Output is correct |
19 |
Correct |
205 ms |
56980 KB |
Output is correct |
20 |
Correct |
211 ms |
56912 KB |
Output is correct |
21 |
Correct |
179 ms |
56916 KB |
Output is correct |
22 |
Correct |
175 ms |
56656 KB |
Output is correct |
23 |
Correct |
179 ms |
56660 KB |
Output is correct |
24 |
Correct |
170 ms |
56752 KB |
Output is correct |
25 |
Correct |
164 ms |
56660 KB |
Output is correct |
26 |
Correct |
205 ms |
56916 KB |
Output is correct |
27 |
Correct |
211 ms |
56804 KB |
Output is correct |
28 |
Correct |
210 ms |
56892 KB |
Output is correct |
29 |
Correct |
216 ms |
56916 KB |
Output is correct |
30 |
Correct |
216 ms |
56916 KB |
Output is correct |
31 |
Correct |
203 ms |
56912 KB |
Output is correct |
32 |
Correct |
195 ms |
57136 KB |
Output is correct |
33 |
Correct |
191 ms |
57012 KB |
Output is correct |
34 |
Correct |
133 ms |
56400 KB |
Output is correct |
35 |
Correct |
132 ms |
56496 KB |
Output is correct |
36 |
Correct |
129 ms |
56272 KB |
Output is correct |
37 |
Correct |
142 ms |
56364 KB |
Output is correct |
38 |
Correct |
130 ms |
56400 KB |
Output is correct |
39 |
Correct |
149 ms |
55472 KB |
Output is correct |
40 |
Correct |
119 ms |
37608 KB |
Output is correct |
41 |
Correct |
141 ms |
55124 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 |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 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 |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
676 KB |
Output is correct |
12 |
Correct |
3 ms |
1628 KB |
Output is correct |
13 |
Correct |
3 ms |
1488 KB |
Output is correct |
14 |
Correct |
4 ms |
1628 KB |
Output is correct |
15 |
Correct |
4 ms |
1628 KB |
Output is correct |
16 |
Correct |
4 ms |
1720 KB |
Output is correct |
17 |
Correct |
3 ms |
1372 KB |
Output is correct |
18 |
Correct |
3 ms |
1628 KB |
Output is correct |
19 |
Correct |
1069 ms |
262144 KB |
Output is correct |
20 |
Correct |
1051 ms |
262144 KB |
Output is correct |
21 |
Correct |
1079 ms |
262144 KB |
Output is correct |
22 |
Correct |
1042 ms |
262144 KB |
Output is correct |
23 |
Correct |
1355 ms |
262144 KB |
Output is correct |
24 |
Correct |
79 ms |
26884 KB |
Output is correct |
25 |
Correct |
73 ms |
26964 KB |
Output is correct |
26 |
Correct |
79 ms |
26960 KB |
Output is correct |
27 |
Correct |
80 ms |
26828 KB |
Output is correct |
28 |
Correct |
83 ms |
26920 KB |
Output is correct |
29 |
Correct |
54 ms |
26704 KB |
Output is correct |
30 |
Correct |
54 ms |
26704 KB |
Output is correct |
31 |
Correct |
58 ms |
26604 KB |
Output is correct |
32 |
Correct |
23 ms |
1884 KB |
Output is correct |
33 |
Correct |
63 ms |
26620 KB |
Output is correct |
34 |
Correct |
205 ms |
56980 KB |
Output is correct |
35 |
Correct |
211 ms |
56912 KB |
Output is correct |
36 |
Correct |
179 ms |
56916 KB |
Output is correct |
37 |
Correct |
175 ms |
56656 KB |
Output is correct |
38 |
Correct |
179 ms |
56660 KB |
Output is correct |
39 |
Correct |
170 ms |
56752 KB |
Output is correct |
40 |
Correct |
164 ms |
56660 KB |
Output is correct |
41 |
Correct |
205 ms |
56916 KB |
Output is correct |
42 |
Correct |
211 ms |
56804 KB |
Output is correct |
43 |
Correct |
210 ms |
56892 KB |
Output is correct |
44 |
Correct |
216 ms |
56916 KB |
Output is correct |
45 |
Correct |
216 ms |
56916 KB |
Output is correct |
46 |
Correct |
203 ms |
56912 KB |
Output is correct |
47 |
Correct |
195 ms |
57136 KB |
Output is correct |
48 |
Correct |
191 ms |
57012 KB |
Output is correct |
49 |
Correct |
133 ms |
56400 KB |
Output is correct |
50 |
Correct |
132 ms |
56496 KB |
Output is correct |
51 |
Correct |
129 ms |
56272 KB |
Output is correct |
52 |
Correct |
142 ms |
56364 KB |
Output is correct |
53 |
Correct |
130 ms |
56400 KB |
Output is correct |
54 |
Correct |
149 ms |
55472 KB |
Output is correct |
55 |
Correct |
119 ms |
37608 KB |
Output is correct |
56 |
Correct |
141 ms |
55124 KB |
Output is correct |
57 |
Correct |
1363 ms |
262144 KB |
Output is correct |
58 |
Correct |
1351 ms |
262144 KB |
Output is correct |
59 |
Correct |
1279 ms |
262144 KB |
Output is correct |
60 |
Correct |
1183 ms |
262144 KB |
Output is correct |
61 |
Runtime error |
1326 ms |
262312 KB |
Memory limit exceeded |
62 |
Halted |
0 ms |
0 KB |
- |