#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define pb push_back
#define all(a) a.begin(),a.end()
#define int long long
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int>pii;
typedef pair<ll,ll>pll;
typedef vector<ll>vll;
typedef vector<int>vi;
typedef vector<bool>vb;
typedef vector<vi>vvi;
typedef vector<vll>vvll;
typedef vector<pii>vpii;
typedef vector<pll>vpll;
const int N=1e6+99;
int w[N],k[N],a[N],t[N*4],ans[N];
vi cur[N];
vpii v[N];
void build(int v,int l,int r){
if(l==r){
t[v]=a[l];
return;
}
int V=v<<1LL,mid=(l+r)>>1LL;
build(V,l,mid);
build(V+1,mid+1,r);
t[v]=max(t[V],t[V+1]);
}
void upd(int v,int l,int r,int pos,int val){
if(l==r){
t[v]=val;
return;
}
int V=v<<1LL,mid=(l+r)>>1LL;
if(pos<=mid){
upd(V,l,mid,pos,val);
}
else{
upd(V+1,mid+1,r,pos,val);
}
t[v]=max(t[V],t[V+1]);
}
int get(int v,int l,int r,int L,int R){
if(l==L&&r==R){
return t[v];
}
int V=v<<1LL,mid=(l+r)>>1LL;
if(R<=mid){
return get(V,l,mid,L,R);
}
if(L>mid){
return get(V+1,mid+1,r,L,R);
}
return max(get(V,l,mid,L,mid),get(V+1,mid+1,r,mid+1,R));
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,m;
cin>>n>>m;
for(int i=1;i<=n;++i){
cin>>w[i];
}
vpii st;
st.pb({w[1],1});
a[1]=-1;
for(int i=2;i<=n;++i){
while(!st.empty()&&st.back().x<=w[i]){
st.pop_back();
}
if(!st.size()){
a[i]=-1;
}
else{
a[i]=st.back().x+w[i];
cur[st.back().y].pb(i);
}
st.pb({w[i],i});
}
build(1,1,n);
for(int i=1;i<=m;++i){
int l,r;
cin>>l>>r>>k[i];
v[l].pb({r,i});
}
for(int l=1;l<=n;++l){
for(auto [r,i]:v[l]){
if(get(1,1,n,l,r)<=k[i]){
ans[i]=1;
}
}
for(int pos:cur[l]){
upd(1,1,n,pos,-1);
}
}
for(int i=1;i<=m;++i){
cout<<ans[i]<<"\n";
}
}
/**
17 1
11 7 5 6 8 17 11 9 5 7 5 4 3 21 17 5 16
1 17 37
**/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
47300 KB |
Output is correct |
2 |
Correct |
23 ms |
47276 KB |
Output is correct |
3 |
Correct |
23 ms |
47308 KB |
Output is correct |
4 |
Correct |
24 ms |
47280 KB |
Output is correct |
5 |
Correct |
22 ms |
47308 KB |
Output is correct |
6 |
Correct |
22 ms |
47308 KB |
Output is correct |
7 |
Correct |
22 ms |
47276 KB |
Output is correct |
8 |
Correct |
25 ms |
47288 KB |
Output is correct |
9 |
Correct |
25 ms |
47344 KB |
Output is correct |
10 |
Correct |
22 ms |
47308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
47300 KB |
Output is correct |
2 |
Correct |
23 ms |
47276 KB |
Output is correct |
3 |
Correct |
23 ms |
47308 KB |
Output is correct |
4 |
Correct |
24 ms |
47280 KB |
Output is correct |
5 |
Correct |
22 ms |
47308 KB |
Output is correct |
6 |
Correct |
22 ms |
47308 KB |
Output is correct |
7 |
Correct |
22 ms |
47276 KB |
Output is correct |
8 |
Correct |
25 ms |
47288 KB |
Output is correct |
9 |
Correct |
25 ms |
47344 KB |
Output is correct |
10 |
Correct |
22 ms |
47308 KB |
Output is correct |
11 |
Correct |
23 ms |
47568 KB |
Output is correct |
12 |
Correct |
24 ms |
47756 KB |
Output is correct |
13 |
Correct |
24 ms |
47744 KB |
Output is correct |
14 |
Correct |
26 ms |
47920 KB |
Output is correct |
15 |
Correct |
26 ms |
47936 KB |
Output is correct |
16 |
Correct |
25 ms |
47884 KB |
Output is correct |
17 |
Correct |
26 ms |
47728 KB |
Output is correct |
18 |
Correct |
24 ms |
47848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1311 ms |
142224 KB |
Output is correct |
2 |
Correct |
1299 ms |
145736 KB |
Output is correct |
3 |
Correct |
1310 ms |
148588 KB |
Output is correct |
4 |
Correct |
1330 ms |
145968 KB |
Output is correct |
5 |
Correct |
1166 ms |
139152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
116 ms |
59156 KB |
Output is correct |
2 |
Correct |
107 ms |
59048 KB |
Output is correct |
3 |
Correct |
105 ms |
57360 KB |
Output is correct |
4 |
Correct |
100 ms |
57332 KB |
Output is correct |
5 |
Correct |
94 ms |
57272 KB |
Output is correct |
6 |
Correct |
83 ms |
56092 KB |
Output is correct |
7 |
Correct |
114 ms |
56100 KB |
Output is correct |
8 |
Correct |
90 ms |
57152 KB |
Output is correct |
9 |
Correct |
61 ms |
52424 KB |
Output is correct |
10 |
Correct |
92 ms |
57088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
47300 KB |
Output is correct |
2 |
Correct |
23 ms |
47276 KB |
Output is correct |
3 |
Correct |
23 ms |
47308 KB |
Output is correct |
4 |
Correct |
24 ms |
47280 KB |
Output is correct |
5 |
Correct |
22 ms |
47308 KB |
Output is correct |
6 |
Correct |
22 ms |
47308 KB |
Output is correct |
7 |
Correct |
22 ms |
47276 KB |
Output is correct |
8 |
Correct |
25 ms |
47288 KB |
Output is correct |
9 |
Correct |
25 ms |
47344 KB |
Output is correct |
10 |
Correct |
22 ms |
47308 KB |
Output is correct |
11 |
Correct |
23 ms |
47568 KB |
Output is correct |
12 |
Correct |
24 ms |
47756 KB |
Output is correct |
13 |
Correct |
24 ms |
47744 KB |
Output is correct |
14 |
Correct |
26 ms |
47920 KB |
Output is correct |
15 |
Correct |
26 ms |
47936 KB |
Output is correct |
16 |
Correct |
25 ms |
47884 KB |
Output is correct |
17 |
Correct |
26 ms |
47728 KB |
Output is correct |
18 |
Correct |
24 ms |
47848 KB |
Output is correct |
19 |
Correct |
252 ms |
73856 KB |
Output is correct |
20 |
Correct |
253 ms |
73764 KB |
Output is correct |
21 |
Correct |
208 ms |
73408 KB |
Output is correct |
22 |
Correct |
215 ms |
73404 KB |
Output is correct |
23 |
Correct |
215 ms |
73320 KB |
Output is correct |
24 |
Correct |
170 ms |
69632 KB |
Output is correct |
25 |
Correct |
175 ms |
69520 KB |
Output is correct |
26 |
Correct |
197 ms |
69736 KB |
Output is correct |
27 |
Correct |
197 ms |
69904 KB |
Output is correct |
28 |
Correct |
197 ms |
69828 KB |
Output is correct |
29 |
Correct |
207 ms |
70084 KB |
Output is correct |
30 |
Correct |
214 ms |
69912 KB |
Output is correct |
31 |
Correct |
211 ms |
69892 KB |
Output is correct |
32 |
Correct |
212 ms |
69956 KB |
Output is correct |
33 |
Correct |
205 ms |
70000 KB |
Output is correct |
34 |
Correct |
167 ms |
68620 KB |
Output is correct |
35 |
Correct |
170 ms |
68660 KB |
Output is correct |
36 |
Correct |
175 ms |
68524 KB |
Output is correct |
37 |
Correct |
165 ms |
68536 KB |
Output is correct |
38 |
Correct |
184 ms |
68764 KB |
Output is correct |
39 |
Correct |
191 ms |
69036 KB |
Output is correct |
40 |
Correct |
137 ms |
63836 KB |
Output is correct |
41 |
Correct |
178 ms |
68152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
47300 KB |
Output is correct |
2 |
Correct |
23 ms |
47276 KB |
Output is correct |
3 |
Correct |
23 ms |
47308 KB |
Output is correct |
4 |
Correct |
24 ms |
47280 KB |
Output is correct |
5 |
Correct |
22 ms |
47308 KB |
Output is correct |
6 |
Correct |
22 ms |
47308 KB |
Output is correct |
7 |
Correct |
22 ms |
47276 KB |
Output is correct |
8 |
Correct |
25 ms |
47288 KB |
Output is correct |
9 |
Correct |
25 ms |
47344 KB |
Output is correct |
10 |
Correct |
22 ms |
47308 KB |
Output is correct |
11 |
Correct |
23 ms |
47568 KB |
Output is correct |
12 |
Correct |
24 ms |
47756 KB |
Output is correct |
13 |
Correct |
24 ms |
47744 KB |
Output is correct |
14 |
Correct |
26 ms |
47920 KB |
Output is correct |
15 |
Correct |
26 ms |
47936 KB |
Output is correct |
16 |
Correct |
25 ms |
47884 KB |
Output is correct |
17 |
Correct |
26 ms |
47728 KB |
Output is correct |
18 |
Correct |
24 ms |
47848 KB |
Output is correct |
19 |
Correct |
1311 ms |
142224 KB |
Output is correct |
20 |
Correct |
1299 ms |
145736 KB |
Output is correct |
21 |
Correct |
1310 ms |
148588 KB |
Output is correct |
22 |
Correct |
1330 ms |
145968 KB |
Output is correct |
23 |
Correct |
1166 ms |
139152 KB |
Output is correct |
24 |
Correct |
116 ms |
59156 KB |
Output is correct |
25 |
Correct |
107 ms |
59048 KB |
Output is correct |
26 |
Correct |
105 ms |
57360 KB |
Output is correct |
27 |
Correct |
100 ms |
57332 KB |
Output is correct |
28 |
Correct |
94 ms |
57272 KB |
Output is correct |
29 |
Correct |
83 ms |
56092 KB |
Output is correct |
30 |
Correct |
114 ms |
56100 KB |
Output is correct |
31 |
Correct |
90 ms |
57152 KB |
Output is correct |
32 |
Correct |
61 ms |
52424 KB |
Output is correct |
33 |
Correct |
92 ms |
57088 KB |
Output is correct |
34 |
Correct |
252 ms |
73856 KB |
Output is correct |
35 |
Correct |
253 ms |
73764 KB |
Output is correct |
36 |
Correct |
208 ms |
73408 KB |
Output is correct |
37 |
Correct |
215 ms |
73404 KB |
Output is correct |
38 |
Correct |
215 ms |
73320 KB |
Output is correct |
39 |
Correct |
170 ms |
69632 KB |
Output is correct |
40 |
Correct |
175 ms |
69520 KB |
Output is correct |
41 |
Correct |
197 ms |
69736 KB |
Output is correct |
42 |
Correct |
197 ms |
69904 KB |
Output is correct |
43 |
Correct |
197 ms |
69828 KB |
Output is correct |
44 |
Correct |
207 ms |
70084 KB |
Output is correct |
45 |
Correct |
214 ms |
69912 KB |
Output is correct |
46 |
Correct |
211 ms |
69892 KB |
Output is correct |
47 |
Correct |
212 ms |
69956 KB |
Output is correct |
48 |
Correct |
205 ms |
70000 KB |
Output is correct |
49 |
Correct |
167 ms |
68620 KB |
Output is correct |
50 |
Correct |
170 ms |
68660 KB |
Output is correct |
51 |
Correct |
175 ms |
68524 KB |
Output is correct |
52 |
Correct |
165 ms |
68536 KB |
Output is correct |
53 |
Correct |
184 ms |
68764 KB |
Output is correct |
54 |
Correct |
191 ms |
69036 KB |
Output is correct |
55 |
Correct |
137 ms |
63836 KB |
Output is correct |
56 |
Correct |
178 ms |
68152 KB |
Output is correct |
57 |
Correct |
1347 ms |
169036 KB |
Output is correct |
58 |
Correct |
1360 ms |
156428 KB |
Output is correct |
59 |
Correct |
1296 ms |
155808 KB |
Output is correct |
60 |
Correct |
1281 ms |
155848 KB |
Output is correct |
61 |
Correct |
1292 ms |
155904 KB |
Output is correct |
62 |
Correct |
1304 ms |
155900 KB |
Output is correct |
63 |
Correct |
880 ms |
132548 KB |
Output is correct |
64 |
Correct |
864 ms |
132508 KB |
Output is correct |
65 |
Correct |
1090 ms |
137156 KB |
Output is correct |
66 |
Correct |
1146 ms |
154804 KB |
Output is correct |
67 |
Correct |
1093 ms |
129708 KB |
Output is correct |
68 |
Correct |
1142 ms |
157144 KB |
Output is correct |
69 |
Correct |
1140 ms |
139884 KB |
Output is correct |
70 |
Correct |
1147 ms |
143700 KB |
Output is correct |
71 |
Correct |
1150 ms |
150076 KB |
Output is correct |
72 |
Correct |
1153 ms |
138760 KB |
Output is correct |
73 |
Correct |
836 ms |
141980 KB |
Output is correct |
74 |
Correct |
858 ms |
127312 KB |
Output is correct |
75 |
Correct |
805 ms |
126580 KB |
Output is correct |
76 |
Correct |
814 ms |
122588 KB |
Output is correct |
77 |
Correct |
801 ms |
124388 KB |
Output is correct |
78 |
Correct |
1008 ms |
154004 KB |
Output is correct |
79 |
Correct |
700 ms |
114268 KB |
Output is correct |
80 |
Correct |
999 ms |
149692 KB |
Output is correct |