#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 |
1 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 |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 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 |
1 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 |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 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 |
2 ms |
1628 KB |
Output is correct |
13 |
Correct |
3 ms |
1628 KB |
Output is correct |
14 |
Correct |
3 ms |
1628 KB |
Output is correct |
15 |
Correct |
4 ms |
1628 KB |
Output is correct |
16 |
Correct |
3 ms |
1628 KB |
Output is correct |
17 |
Correct |
3 ms |
1260 KB |
Output is correct |
18 |
Correct |
4 ms |
1624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1000 ms |
262144 KB |
Output is correct |
2 |
Correct |
990 ms |
262144 KB |
Output is correct |
3 |
Correct |
1057 ms |
262144 KB |
Output is correct |
4 |
Correct |
1036 ms |
262144 KB |
Output is correct |
5 |
Correct |
1415 ms |
262144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
88 ms |
26964 KB |
Output is correct |
2 |
Correct |
74 ms |
26964 KB |
Output is correct |
3 |
Correct |
80 ms |
26860 KB |
Output is correct |
4 |
Correct |
85 ms |
26832 KB |
Output is correct |
5 |
Correct |
87 ms |
26864 KB |
Output is correct |
6 |
Correct |
52 ms |
26704 KB |
Output is correct |
7 |
Correct |
56 ms |
26828 KB |
Output is correct |
8 |
Correct |
70 ms |
26708 KB |
Output is correct |
9 |
Correct |
24 ms |
1880 KB |
Output is correct |
10 |
Correct |
57 ms |
26704 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 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 |
2 ms |
1628 KB |
Output is correct |
13 |
Correct |
3 ms |
1628 KB |
Output is correct |
14 |
Correct |
3 ms |
1628 KB |
Output is correct |
15 |
Correct |
4 ms |
1628 KB |
Output is correct |
16 |
Correct |
3 ms |
1628 KB |
Output is correct |
17 |
Correct |
3 ms |
1260 KB |
Output is correct |
18 |
Correct |
4 ms |
1624 KB |
Output is correct |
19 |
Correct |
222 ms |
56560 KB |
Output is correct |
20 |
Correct |
207 ms |
56404 KB |
Output is correct |
21 |
Correct |
170 ms |
56584 KB |
Output is correct |
22 |
Correct |
170 ms |
56408 KB |
Output is correct |
23 |
Correct |
178 ms |
56400 KB |
Output is correct |
24 |
Correct |
156 ms |
56304 KB |
Output is correct |
25 |
Correct |
156 ms |
56200 KB |
Output is correct |
26 |
Correct |
180 ms |
56400 KB |
Output is correct |
27 |
Correct |
179 ms |
56404 KB |
Output is correct |
28 |
Correct |
197 ms |
56404 KB |
Output is correct |
29 |
Correct |
213 ms |
56396 KB |
Output is correct |
30 |
Correct |
199 ms |
56404 KB |
Output is correct |
31 |
Correct |
217 ms |
56440 KB |
Output is correct |
32 |
Correct |
197 ms |
56660 KB |
Output is correct |
33 |
Correct |
212 ms |
55568 KB |
Output is correct |
34 |
Correct |
130 ms |
55380 KB |
Output is correct |
35 |
Correct |
147 ms |
55380 KB |
Output is correct |
36 |
Correct |
134 ms |
55116 KB |
Output is correct |
37 |
Correct |
133 ms |
55448 KB |
Output is correct |
38 |
Correct |
146 ms |
55380 KB |
Output is correct |
39 |
Correct |
145 ms |
54756 KB |
Output is correct |
40 |
Correct |
123 ms |
36876 KB |
Output is correct |
41 |
Correct |
141 ms |
54044 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 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 |
2 ms |
1628 KB |
Output is correct |
13 |
Correct |
3 ms |
1628 KB |
Output is correct |
14 |
Correct |
3 ms |
1628 KB |
Output is correct |
15 |
Correct |
4 ms |
1628 KB |
Output is correct |
16 |
Correct |
3 ms |
1628 KB |
Output is correct |
17 |
Correct |
3 ms |
1260 KB |
Output is correct |
18 |
Correct |
4 ms |
1624 KB |
Output is correct |
19 |
Correct |
1000 ms |
262144 KB |
Output is correct |
20 |
Correct |
990 ms |
262144 KB |
Output is correct |
21 |
Correct |
1057 ms |
262144 KB |
Output is correct |
22 |
Correct |
1036 ms |
262144 KB |
Output is correct |
23 |
Correct |
1415 ms |
262144 KB |
Output is correct |
24 |
Correct |
88 ms |
26964 KB |
Output is correct |
25 |
Correct |
74 ms |
26964 KB |
Output is correct |
26 |
Correct |
80 ms |
26860 KB |
Output is correct |
27 |
Correct |
85 ms |
26832 KB |
Output is correct |
28 |
Correct |
87 ms |
26864 KB |
Output is correct |
29 |
Correct |
52 ms |
26704 KB |
Output is correct |
30 |
Correct |
56 ms |
26828 KB |
Output is correct |
31 |
Correct |
70 ms |
26708 KB |
Output is correct |
32 |
Correct |
24 ms |
1880 KB |
Output is correct |
33 |
Correct |
57 ms |
26704 KB |
Output is correct |
34 |
Correct |
222 ms |
56560 KB |
Output is correct |
35 |
Correct |
207 ms |
56404 KB |
Output is correct |
36 |
Correct |
170 ms |
56584 KB |
Output is correct |
37 |
Correct |
170 ms |
56408 KB |
Output is correct |
38 |
Correct |
178 ms |
56400 KB |
Output is correct |
39 |
Correct |
156 ms |
56304 KB |
Output is correct |
40 |
Correct |
156 ms |
56200 KB |
Output is correct |
41 |
Correct |
180 ms |
56400 KB |
Output is correct |
42 |
Correct |
179 ms |
56404 KB |
Output is correct |
43 |
Correct |
197 ms |
56404 KB |
Output is correct |
44 |
Correct |
213 ms |
56396 KB |
Output is correct |
45 |
Correct |
199 ms |
56404 KB |
Output is correct |
46 |
Correct |
217 ms |
56440 KB |
Output is correct |
47 |
Correct |
197 ms |
56660 KB |
Output is correct |
48 |
Correct |
212 ms |
55568 KB |
Output is correct |
49 |
Correct |
130 ms |
55380 KB |
Output is correct |
50 |
Correct |
147 ms |
55380 KB |
Output is correct |
51 |
Correct |
134 ms |
55116 KB |
Output is correct |
52 |
Correct |
133 ms |
55448 KB |
Output is correct |
53 |
Correct |
146 ms |
55380 KB |
Output is correct |
54 |
Correct |
145 ms |
54756 KB |
Output is correct |
55 |
Correct |
123 ms |
36876 KB |
Output is correct |
56 |
Correct |
141 ms |
54044 KB |
Output is correct |
57 |
Correct |
1354 ms |
262144 KB |
Output is correct |
58 |
Correct |
1361 ms |
262144 KB |
Output is correct |
59 |
Correct |
1296 ms |
262144 KB |
Output is correct |
60 |
Correct |
1285 ms |
262144 KB |
Output is correct |
61 |
Correct |
1286 ms |
262144 KB |
Output is correct |
62 |
Correct |
1254 ms |
262144 KB |
Output is correct |
63 |
Correct |
818 ms |
262144 KB |
Output is correct |
64 |
Correct |
790 ms |
262144 KB |
Output is correct |
65 |
Correct |
1343 ms |
262144 KB |
Output is correct |
66 |
Correct |
1309 ms |
262144 KB |
Output is correct |
67 |
Correct |
1265 ms |
262144 KB |
Output is correct |
68 |
Correct |
1409 ms |
262144 KB |
Output is correct |
69 |
Correct |
1356 ms |
262144 KB |
Output is correct |
70 |
Correct |
1402 ms |
262144 KB |
Output is correct |
71 |
Correct |
1408 ms |
262144 KB |
Output is correct |
72 |
Correct |
1430 ms |
262144 KB |
Output is correct |
73 |
Correct |
716 ms |
262144 KB |
Output is correct |
74 |
Correct |
695 ms |
262144 KB |
Output is correct |
75 |
Correct |
700 ms |
262144 KB |
Output is correct |
76 |
Runtime error |
728 ms |
262148 KB |
Memory limit exceeded |
77 |
Halted |
0 ms |
0 KB |
- |