#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define f first
#define s second
#define endl '\n'
#define vec vector
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define m_p make_pair
#define sz(x) (int)x.size()
#define pw(x) (1LL<<x)
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
auto rng=bind(uniform_int_distribution<int>(0,1e9),mt19937(time(0)));
template<class T>bool umin(T &a,const T &b) {return (a>b?a=b,1:0);}
template<class T>bool umax(T &a,const T &b) {return (a<b?a=b,1:0);}
template<class T> using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const int N=1e6+1;
struct fenwick{
int t[N];
void init(){
fill(t,t+N,-2e9);
}
void upd(int id,int x){
id=N-id-1;
while(id<N){
umax(t[id],x);
id+=id&-id;
}
}
int get(int id){
int ans=-2e9;
id=N-id-1;
while(id>0){
umax(ans,t[id]);
id-=id&-id;
}
return ans;
}
}T;
int lft[N],rgt[N];
signed main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
// ifstream cin("input.txt");
// ifstream fin("o.txt");
int n,q;
cin>>n>>q;
vec<int>a(n);
T.init();
for(auto &z : a) cin>>z;
vec<pii>vc;vc.pb({2e9,-1});
for(int i=0;i<n;i++){
while(sz(vc) && a[i]>=vc.back().f) vc.pop_back();
lft[i]=vc.back().s;
vc.pb({a[i],i});
}
vc.clear();
vec<vec<int>>qry(n,vec<int>());
vec<int>l(q),r(q),k(q),answ(q);
for(int i=0;i<q;i++){
cin>>l[i]>>r[i]>>k[i];--l[i];--r[i];
qry[r[i]].pb(i);
}
vec<vec<int>>del(n+1,vec<int>());
for(int i=0;i<n;i++){
del[rgt[i]].pb(i);
if(lft[i]!=-1){
T.upd(lft[i],a[lft[i]]+a[i]);
}
/// also i need to update C
for(auto &z : qry[i]){
answ[z]=T.get(l[z]);
// cerr<<T.get(l[z])<<endl;
}
}
for(int i=0;i<q;i++){
cout<<(answ[i]<=k[i])<<endl;
}
return 0;
}
/*
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4172 KB |
Output is correct |
2 |
Correct |
3 ms |
4224 KB |
Output is correct |
3 |
Correct |
3 ms |
4172 KB |
Output is correct |
4 |
Correct |
5 ms |
4204 KB |
Output is correct |
5 |
Correct |
3 ms |
4172 KB |
Output is correct |
6 |
Correct |
4 ms |
4300 KB |
Output is correct |
7 |
Correct |
3 ms |
4300 KB |
Output is correct |
8 |
Correct |
3 ms |
4300 KB |
Output is correct |
9 |
Correct |
3 ms |
4172 KB |
Output is correct |
10 |
Correct |
3 ms |
4300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4172 KB |
Output is correct |
2 |
Correct |
3 ms |
4224 KB |
Output is correct |
3 |
Correct |
3 ms |
4172 KB |
Output is correct |
4 |
Correct |
5 ms |
4204 KB |
Output is correct |
5 |
Correct |
3 ms |
4172 KB |
Output is correct |
6 |
Correct |
4 ms |
4300 KB |
Output is correct |
7 |
Correct |
3 ms |
4300 KB |
Output is correct |
8 |
Correct |
3 ms |
4300 KB |
Output is correct |
9 |
Correct |
3 ms |
4172 KB |
Output is correct |
10 |
Correct |
3 ms |
4300 KB |
Output is correct |
11 |
Correct |
5 ms |
4428 KB |
Output is correct |
12 |
Correct |
6 ms |
4684 KB |
Output is correct |
13 |
Correct |
5 ms |
4684 KB |
Output is correct |
14 |
Correct |
9 ms |
4812 KB |
Output is correct |
15 |
Correct |
7 ms |
4812 KB |
Output is correct |
16 |
Correct |
7 ms |
4812 KB |
Output is correct |
17 |
Correct |
6 ms |
4684 KB |
Output is correct |
18 |
Correct |
7 ms |
4736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1307 ms |
98716 KB |
Output is correct |
2 |
Correct |
1385 ms |
98876 KB |
Output is correct |
3 |
Correct |
1294 ms |
98672 KB |
Output is correct |
4 |
Correct |
1285 ms |
98876 KB |
Output is correct |
5 |
Correct |
1259 ms |
98724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
13632 KB |
Output is correct |
2 |
Correct |
74 ms |
14856 KB |
Output is correct |
3 |
Correct |
76 ms |
15340 KB |
Output is correct |
4 |
Correct |
93 ms |
15448 KB |
Output is correct |
5 |
Correct |
79 ms |
15624 KB |
Output is correct |
6 |
Correct |
63 ms |
14348 KB |
Output is correct |
7 |
Correct |
64 ms |
14352 KB |
Output is correct |
8 |
Correct |
91 ms |
15232 KB |
Output is correct |
9 |
Correct |
46 ms |
7872 KB |
Output is correct |
10 |
Correct |
73 ms |
15292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4172 KB |
Output is correct |
2 |
Correct |
3 ms |
4224 KB |
Output is correct |
3 |
Correct |
3 ms |
4172 KB |
Output is correct |
4 |
Correct |
5 ms |
4204 KB |
Output is correct |
5 |
Correct |
3 ms |
4172 KB |
Output is correct |
6 |
Correct |
4 ms |
4300 KB |
Output is correct |
7 |
Correct |
3 ms |
4300 KB |
Output is correct |
8 |
Correct |
3 ms |
4300 KB |
Output is correct |
9 |
Correct |
3 ms |
4172 KB |
Output is correct |
10 |
Correct |
3 ms |
4300 KB |
Output is correct |
11 |
Correct |
5 ms |
4428 KB |
Output is correct |
12 |
Correct |
6 ms |
4684 KB |
Output is correct |
13 |
Correct |
5 ms |
4684 KB |
Output is correct |
14 |
Correct |
9 ms |
4812 KB |
Output is correct |
15 |
Correct |
7 ms |
4812 KB |
Output is correct |
16 |
Correct |
7 ms |
4812 KB |
Output is correct |
17 |
Correct |
6 ms |
4684 KB |
Output is correct |
18 |
Correct |
7 ms |
4736 KB |
Output is correct |
19 |
Correct |
200 ms |
29436 KB |
Output is correct |
20 |
Correct |
204 ms |
29500 KB |
Output is correct |
21 |
Correct |
175 ms |
27596 KB |
Output is correct |
22 |
Correct |
179 ms |
27576 KB |
Output is correct |
23 |
Correct |
164 ms |
27524 KB |
Output is correct |
24 |
Correct |
165 ms |
27320 KB |
Output is correct |
25 |
Correct |
154 ms |
27340 KB |
Output is correct |
26 |
Correct |
167 ms |
28216 KB |
Output is correct |
27 |
Correct |
242 ms |
28164 KB |
Output is correct |
28 |
Correct |
174 ms |
28496 KB |
Output is correct |
29 |
Correct |
200 ms |
29572 KB |
Output is correct |
30 |
Correct |
192 ms |
29496 KB |
Output is correct |
31 |
Correct |
179 ms |
29324 KB |
Output is correct |
32 |
Correct |
180 ms |
29324 KB |
Output is correct |
33 |
Correct |
184 ms |
29380 KB |
Output is correct |
34 |
Correct |
152 ms |
26916 KB |
Output is correct |
35 |
Correct |
169 ms |
26992 KB |
Output is correct |
36 |
Correct |
150 ms |
26908 KB |
Output is correct |
37 |
Correct |
141 ms |
26808 KB |
Output is correct |
38 |
Correct |
154 ms |
27016 KB |
Output is correct |
39 |
Correct |
190 ms |
27876 KB |
Output is correct |
40 |
Correct |
152 ms |
22656 KB |
Output is correct |
41 |
Correct |
199 ms |
27380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4172 KB |
Output is correct |
2 |
Correct |
3 ms |
4224 KB |
Output is correct |
3 |
Correct |
3 ms |
4172 KB |
Output is correct |
4 |
Correct |
5 ms |
4204 KB |
Output is correct |
5 |
Correct |
3 ms |
4172 KB |
Output is correct |
6 |
Correct |
4 ms |
4300 KB |
Output is correct |
7 |
Correct |
3 ms |
4300 KB |
Output is correct |
8 |
Correct |
3 ms |
4300 KB |
Output is correct |
9 |
Correct |
3 ms |
4172 KB |
Output is correct |
10 |
Correct |
3 ms |
4300 KB |
Output is correct |
11 |
Correct |
5 ms |
4428 KB |
Output is correct |
12 |
Correct |
6 ms |
4684 KB |
Output is correct |
13 |
Correct |
5 ms |
4684 KB |
Output is correct |
14 |
Correct |
9 ms |
4812 KB |
Output is correct |
15 |
Correct |
7 ms |
4812 KB |
Output is correct |
16 |
Correct |
7 ms |
4812 KB |
Output is correct |
17 |
Correct |
6 ms |
4684 KB |
Output is correct |
18 |
Correct |
7 ms |
4736 KB |
Output is correct |
19 |
Correct |
1307 ms |
98716 KB |
Output is correct |
20 |
Correct |
1385 ms |
98876 KB |
Output is correct |
21 |
Correct |
1294 ms |
98672 KB |
Output is correct |
22 |
Correct |
1285 ms |
98876 KB |
Output is correct |
23 |
Correct |
1259 ms |
98724 KB |
Output is correct |
24 |
Correct |
80 ms |
13632 KB |
Output is correct |
25 |
Correct |
74 ms |
14856 KB |
Output is correct |
26 |
Correct |
76 ms |
15340 KB |
Output is correct |
27 |
Correct |
93 ms |
15448 KB |
Output is correct |
28 |
Correct |
79 ms |
15624 KB |
Output is correct |
29 |
Correct |
63 ms |
14348 KB |
Output is correct |
30 |
Correct |
64 ms |
14352 KB |
Output is correct |
31 |
Correct |
91 ms |
15232 KB |
Output is correct |
32 |
Correct |
46 ms |
7872 KB |
Output is correct |
33 |
Correct |
73 ms |
15292 KB |
Output is correct |
34 |
Correct |
200 ms |
29436 KB |
Output is correct |
35 |
Correct |
204 ms |
29500 KB |
Output is correct |
36 |
Correct |
175 ms |
27596 KB |
Output is correct |
37 |
Correct |
179 ms |
27576 KB |
Output is correct |
38 |
Correct |
164 ms |
27524 KB |
Output is correct |
39 |
Correct |
165 ms |
27320 KB |
Output is correct |
40 |
Correct |
154 ms |
27340 KB |
Output is correct |
41 |
Correct |
167 ms |
28216 KB |
Output is correct |
42 |
Correct |
242 ms |
28164 KB |
Output is correct |
43 |
Correct |
174 ms |
28496 KB |
Output is correct |
44 |
Correct |
200 ms |
29572 KB |
Output is correct |
45 |
Correct |
192 ms |
29496 KB |
Output is correct |
46 |
Correct |
179 ms |
29324 KB |
Output is correct |
47 |
Correct |
180 ms |
29324 KB |
Output is correct |
48 |
Correct |
184 ms |
29380 KB |
Output is correct |
49 |
Correct |
152 ms |
26916 KB |
Output is correct |
50 |
Correct |
169 ms |
26992 KB |
Output is correct |
51 |
Correct |
150 ms |
26908 KB |
Output is correct |
52 |
Correct |
141 ms |
26808 KB |
Output is correct |
53 |
Correct |
154 ms |
27016 KB |
Output is correct |
54 |
Correct |
190 ms |
27876 KB |
Output is correct |
55 |
Correct |
152 ms |
22656 KB |
Output is correct |
56 |
Correct |
199 ms |
27380 KB |
Output is correct |
57 |
Correct |
1394 ms |
130472 KB |
Output is correct |
58 |
Correct |
1390 ms |
130444 KB |
Output is correct |
59 |
Correct |
1196 ms |
126220 KB |
Output is correct |
60 |
Correct |
1235 ms |
126252 KB |
Output is correct |
61 |
Correct |
1197 ms |
126316 KB |
Output is correct |
62 |
Correct |
1195 ms |
126272 KB |
Output is correct |
63 |
Correct |
798 ms |
118564 KB |
Output is correct |
64 |
Correct |
808 ms |
118640 KB |
Output is correct |
65 |
Correct |
1113 ms |
125872 KB |
Output is correct |
66 |
Correct |
1160 ms |
125832 KB |
Output is correct |
67 |
Correct |
1113 ms |
126196 KB |
Output is correct |
68 |
Correct |
1233 ms |
130464 KB |
Output is correct |
69 |
Correct |
1292 ms |
130524 KB |
Output is correct |
70 |
Correct |
1228 ms |
129724 KB |
Output is correct |
71 |
Correct |
1239 ms |
129708 KB |
Output is correct |
72 |
Correct |
1244 ms |
129756 KB |
Output is correct |
73 |
Correct |
785 ms |
116592 KB |
Output is correct |
74 |
Correct |
823 ms |
117596 KB |
Output is correct |
75 |
Correct |
756 ms |
116524 KB |
Output is correct |
76 |
Correct |
756 ms |
116680 KB |
Output is correct |
77 |
Correct |
783 ms |
116804 KB |
Output is correct |
78 |
Correct |
1114 ms |
122468 KB |
Output is correct |
79 |
Correct |
807 ms |
87472 KB |
Output is correct |
80 |
Correct |
1116 ms |
120288 KB |
Output is correct |