/*
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░▒░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░▒▒░░▄░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░█░▀░░░░░▌░░░░░░░░░░░░░░▄░░░░░░░░░░░░░░░░░░█░░░░░▌░░░░█░░░░░░░░░░░░░░░░
░░░░░░░░░▌░░░░░░░▐░░░░░░░░▌░░░░██░▀▌░░░░░░░░▐▌░░░░░██░░░░▐░░░░░█░░░░░░░░░░░░░░░░
░░░░░░░░█░░░░░░░░█░░░░░░░█▌░░░░█░░░▌░░░░░░░░█░░░░░█░▐░░░░▐░░░░░▌░░░░░░░░░░░░░░░░
░░░░░░░░█░░░░░░░░█░░░░░░█░▌░░░░█░░░▄░░░░░░░▐▄░███▀░░▐░░░░█░░░░██░░░░░░░░░░░░░░░░
░░░░░░░░░█░░░░░░▐█░░░░░█░▐░░░░▐▌░░░▐░░░░░░█▀░▌░░▀▌░░▐░░░░░█▄░█░░▌░░░░░░░░░░░░░░░
░░░░░░░░░░█▄░░░█░░█░░░█░░█░░░▄█▌░░░░█▄░░▄█░░░█░░░▌░░░█░▄█░░░▀░░░█▄░░░░░░░░░░░░░░
░░░░░░░░░░░░▀▀▀░░░░▀█▀░░░▌▄▄█░█░░░░░░░▀▀░░░░░░██▀░░░░░▀░░░░░░░░░░░▀▀░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░▄██▀░░░░█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░▄▄█▀░█░░░░░▐█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░▌░░░░█░░░░░░▐▌░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░█░░▄█░░░░░░░▐▌░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░▀▀░░░░░░░░░▐▌░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
*/
#include<bits/stdc++.h>
// #include "stress.cpp"
#define IOS ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie()
#define ll long long
#define ull unsigned long long
#define pb push_back
// #define endl "\n"
#define int ll
#define F first
#define S second
#define db long double
#define ld long double
#define short unsigned short
#define pii pair<int,int>
#define all(x) x.begin(),x.enad();
using namespace std;
const ll inf = 1e18,MOD=1e9+7,N=1e6+10,MN=1e9+7,lim=100;
const db Pie=acos(-1);
int binpow(int a,int p);
int lcgayletiar(int a,int b);
//...and justice for all
struct surymgay{
int l,r,k;
};
int v[N],p[N];
int t[N*4];
vector<int>q[N];
void upd(int i,int v,int x,int lx,int rx){
if(lx==rx){
t[x]=v;
return ;
}
int m=(lx+rx)/2;
if(i<=m){
upd(i,v,x*2,lx,m);
}
else{
upd(i,v,x*2+1,m+1,rx);
}
t[x]=max(t[x*2],t[x*2+1]);
}
int get(int l,int r,int x,int lx,int rx){
if(l<=lx&&rx<=r){
return t[x];
}
if(r<lx||rx<l){
return 0;
}
int m=(lx+rx)/2;
return max(get(l,r,x*2,lx,m),get(l,r,x*2+1,m+1,rx));
}
const void solve(){
int n,m;
cin>>n>>m;
stack<int>s;
for(int i=1;i<=n;i++){
cin>>v[i];
}
for(int i=1;i<=n;i++){
while(s.size()&&v[s.top()]<=v[i]){
s.pop();
}
if(s.size()){
p[i]=s.top();
}
s.push(i);
}
vector<surymgay>qu(m+1);
for(int i=1;i<=m;i++){
cin>>qu[i].l>>qu[i].r>>qu[i].k;
q[qu[i].r].pb(i);
}
vector<int>ans(m+1);
for(int i=1;i<=n;i++){
if(p[i])upd(p[i],v[i]+v[p[i]],1,1,n);
for(auto j:q[i]){
ans[j]=get(qu[j].l,qu[j].r,1,1,n)<=qu[j].k;
}
}
for(int i=1;i<=m;i++){
cout<<ans[i]<<endl;
}
}
signed main() {
srand(time(NULL));
IOS;
// freopen("sequence.in", "r", stdin);
// freopen("sequence.out", "w", stdout);
int pantyandstocking=1;
// cin>>pantyandstocking;
for(int i=1;i<=pantyandstocking;i++) {
// cout<<"Test "<<i<<": "<<endl;
solve();
// cout<<endl;
}
// cout<<fixed<<setprecision(10);
// cerr<<"Time:"<<1000*((double)clock())/(double) CLOCKS_PER_SEC<<"ms\n";
}
int lcgayletiar(int a,int b){return (a*b)/(int)__gcd(a,b);}
int binpow(int a,int p){if(p==0)return 1;if(p%2){return ((binpow(a,p-1)*a)%MOD);}int res=binpow(a,p/2)%MOD; return (res*res)%MOD;}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
23900 KB |
Output is correct |
2 |
Correct |
10 ms |
23836 KB |
Output is correct |
3 |
Correct |
14 ms |
23900 KB |
Output is correct |
4 |
Correct |
10 ms |
23900 KB |
Output is correct |
5 |
Correct |
9 ms |
23896 KB |
Output is correct |
6 |
Correct |
11 ms |
23900 KB |
Output is correct |
7 |
Correct |
10 ms |
23900 KB |
Output is correct |
8 |
Correct |
11 ms |
23900 KB |
Output is correct |
9 |
Correct |
10 ms |
23772 KB |
Output is correct |
10 |
Correct |
10 ms |
23900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
23900 KB |
Output is correct |
2 |
Correct |
10 ms |
23836 KB |
Output is correct |
3 |
Correct |
14 ms |
23900 KB |
Output is correct |
4 |
Correct |
10 ms |
23900 KB |
Output is correct |
5 |
Correct |
9 ms |
23896 KB |
Output is correct |
6 |
Correct |
11 ms |
23900 KB |
Output is correct |
7 |
Correct |
10 ms |
23900 KB |
Output is correct |
8 |
Correct |
11 ms |
23900 KB |
Output is correct |
9 |
Correct |
10 ms |
23772 KB |
Output is correct |
10 |
Correct |
10 ms |
23900 KB |
Output is correct |
11 |
Correct |
14 ms |
24156 KB |
Output is correct |
12 |
Correct |
14 ms |
24412 KB |
Output is correct |
13 |
Correct |
14 ms |
24216 KB |
Output is correct |
14 |
Correct |
17 ms |
24408 KB |
Output is correct |
15 |
Correct |
17 ms |
24408 KB |
Output is correct |
16 |
Correct |
16 ms |
24412 KB |
Output is correct |
17 |
Correct |
16 ms |
24340 KB |
Output is correct |
18 |
Correct |
19 ms |
24152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2032 ms |
140804 KB |
Output is correct |
2 |
Correct |
2116 ms |
141824 KB |
Output is correct |
3 |
Correct |
2119 ms |
141648 KB |
Output is correct |
4 |
Correct |
2052 ms |
141676 KB |
Output is correct |
5 |
Correct |
1812 ms |
117840 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
169 ms |
34632 KB |
Output is correct |
2 |
Correct |
164 ms |
34132 KB |
Output is correct |
3 |
Correct |
164 ms |
31828 KB |
Output is correct |
4 |
Correct |
157 ms |
31636 KB |
Output is correct |
5 |
Correct |
161 ms |
31728 KB |
Output is correct |
6 |
Correct |
153 ms |
30988 KB |
Output is correct |
7 |
Correct |
143 ms |
31056 KB |
Output is correct |
8 |
Correct |
162 ms |
32068 KB |
Output is correct |
9 |
Correct |
133 ms |
29384 KB |
Output is correct |
10 |
Correct |
160 ms |
31796 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
23900 KB |
Output is correct |
2 |
Correct |
10 ms |
23836 KB |
Output is correct |
3 |
Correct |
14 ms |
23900 KB |
Output is correct |
4 |
Correct |
10 ms |
23900 KB |
Output is correct |
5 |
Correct |
9 ms |
23896 KB |
Output is correct |
6 |
Correct |
11 ms |
23900 KB |
Output is correct |
7 |
Correct |
10 ms |
23900 KB |
Output is correct |
8 |
Correct |
11 ms |
23900 KB |
Output is correct |
9 |
Correct |
10 ms |
23772 KB |
Output is correct |
10 |
Correct |
10 ms |
23900 KB |
Output is correct |
11 |
Correct |
14 ms |
24156 KB |
Output is correct |
12 |
Correct |
14 ms |
24412 KB |
Output is correct |
13 |
Correct |
14 ms |
24216 KB |
Output is correct |
14 |
Correct |
17 ms |
24408 KB |
Output is correct |
15 |
Correct |
17 ms |
24408 KB |
Output is correct |
16 |
Correct |
16 ms |
24412 KB |
Output is correct |
17 |
Correct |
16 ms |
24340 KB |
Output is correct |
18 |
Correct |
19 ms |
24152 KB |
Output is correct |
19 |
Correct |
342 ms |
48172 KB |
Output is correct |
20 |
Correct |
359 ms |
47952 KB |
Output is correct |
21 |
Correct |
336 ms |
46676 KB |
Output is correct |
22 |
Correct |
329 ms |
46912 KB |
Output is correct |
23 |
Correct |
339 ms |
46676 KB |
Output is correct |
24 |
Correct |
304 ms |
41140 KB |
Output is correct |
25 |
Correct |
298 ms |
41056 KB |
Output is correct |
26 |
Correct |
319 ms |
41556 KB |
Output is correct |
27 |
Correct |
308 ms |
41556 KB |
Output is correct |
28 |
Correct |
313 ms |
41808 KB |
Output is correct |
29 |
Correct |
332 ms |
42360 KB |
Output is correct |
30 |
Correct |
334 ms |
42320 KB |
Output is correct |
31 |
Correct |
328 ms |
42320 KB |
Output is correct |
32 |
Correct |
329 ms |
42320 KB |
Output is correct |
33 |
Correct |
338 ms |
42420 KB |
Output is correct |
34 |
Correct |
304 ms |
40528 KB |
Output is correct |
35 |
Correct |
302 ms |
40700 KB |
Output is correct |
36 |
Correct |
300 ms |
40572 KB |
Output is correct |
37 |
Correct |
312 ms |
40380 KB |
Output is correct |
38 |
Correct |
300 ms |
40532 KB |
Output is correct |
39 |
Correct |
329 ms |
42440 KB |
Output is correct |
40 |
Correct |
299 ms |
39364 KB |
Output is correct |
41 |
Correct |
319 ms |
41156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
23900 KB |
Output is correct |
2 |
Correct |
10 ms |
23836 KB |
Output is correct |
3 |
Correct |
14 ms |
23900 KB |
Output is correct |
4 |
Correct |
10 ms |
23900 KB |
Output is correct |
5 |
Correct |
9 ms |
23896 KB |
Output is correct |
6 |
Correct |
11 ms |
23900 KB |
Output is correct |
7 |
Correct |
10 ms |
23900 KB |
Output is correct |
8 |
Correct |
11 ms |
23900 KB |
Output is correct |
9 |
Correct |
10 ms |
23772 KB |
Output is correct |
10 |
Correct |
10 ms |
23900 KB |
Output is correct |
11 |
Correct |
14 ms |
24156 KB |
Output is correct |
12 |
Correct |
14 ms |
24412 KB |
Output is correct |
13 |
Correct |
14 ms |
24216 KB |
Output is correct |
14 |
Correct |
17 ms |
24408 KB |
Output is correct |
15 |
Correct |
17 ms |
24408 KB |
Output is correct |
16 |
Correct |
16 ms |
24412 KB |
Output is correct |
17 |
Correct |
16 ms |
24340 KB |
Output is correct |
18 |
Correct |
19 ms |
24152 KB |
Output is correct |
19 |
Correct |
2032 ms |
140804 KB |
Output is correct |
20 |
Correct |
2116 ms |
141824 KB |
Output is correct |
21 |
Correct |
2119 ms |
141648 KB |
Output is correct |
22 |
Correct |
2052 ms |
141676 KB |
Output is correct |
23 |
Correct |
1812 ms |
117840 KB |
Output is correct |
24 |
Correct |
169 ms |
34632 KB |
Output is correct |
25 |
Correct |
164 ms |
34132 KB |
Output is correct |
26 |
Correct |
164 ms |
31828 KB |
Output is correct |
27 |
Correct |
157 ms |
31636 KB |
Output is correct |
28 |
Correct |
161 ms |
31728 KB |
Output is correct |
29 |
Correct |
153 ms |
30988 KB |
Output is correct |
30 |
Correct |
143 ms |
31056 KB |
Output is correct |
31 |
Correct |
162 ms |
32068 KB |
Output is correct |
32 |
Correct |
133 ms |
29384 KB |
Output is correct |
33 |
Correct |
160 ms |
31796 KB |
Output is correct |
34 |
Correct |
342 ms |
48172 KB |
Output is correct |
35 |
Correct |
359 ms |
47952 KB |
Output is correct |
36 |
Correct |
336 ms |
46676 KB |
Output is correct |
37 |
Correct |
329 ms |
46912 KB |
Output is correct |
38 |
Correct |
339 ms |
46676 KB |
Output is correct |
39 |
Correct |
304 ms |
41140 KB |
Output is correct |
40 |
Correct |
298 ms |
41056 KB |
Output is correct |
41 |
Correct |
319 ms |
41556 KB |
Output is correct |
42 |
Correct |
308 ms |
41556 KB |
Output is correct |
43 |
Correct |
313 ms |
41808 KB |
Output is correct |
44 |
Correct |
332 ms |
42360 KB |
Output is correct |
45 |
Correct |
334 ms |
42320 KB |
Output is correct |
46 |
Correct |
328 ms |
42320 KB |
Output is correct |
47 |
Correct |
329 ms |
42320 KB |
Output is correct |
48 |
Correct |
338 ms |
42420 KB |
Output is correct |
49 |
Correct |
304 ms |
40528 KB |
Output is correct |
50 |
Correct |
302 ms |
40700 KB |
Output is correct |
51 |
Correct |
300 ms |
40572 KB |
Output is correct |
52 |
Correct |
312 ms |
40380 KB |
Output is correct |
53 |
Correct |
300 ms |
40532 KB |
Output is correct |
54 |
Correct |
329 ms |
42440 KB |
Output is correct |
55 |
Correct |
299 ms |
39364 KB |
Output is correct |
56 |
Correct |
319 ms |
41156 KB |
Output is correct |
57 |
Correct |
1923 ms |
141496 KB |
Output is correct |
58 |
Correct |
1998 ms |
141396 KB |
Output is correct |
59 |
Correct |
2089 ms |
138580 KB |
Output is correct |
60 |
Correct |
1998 ms |
138600 KB |
Output is correct |
61 |
Correct |
1877 ms |
138580 KB |
Output is correct |
62 |
Correct |
1921 ms |
138576 KB |
Output is correct |
63 |
Correct |
1580 ms |
109044 KB |
Output is correct |
64 |
Correct |
1627 ms |
108980 KB |
Output is correct |
65 |
Correct |
1772 ms |
114256 KB |
Output is correct |
66 |
Correct |
1702 ms |
114256 KB |
Output is correct |
67 |
Correct |
1799 ms |
114260 KB |
Output is correct |
68 |
Correct |
1908 ms |
117328 KB |
Output is correct |
69 |
Correct |
1923 ms |
117208 KB |
Output is correct |
70 |
Correct |
1827 ms |
116820 KB |
Output is correct |
71 |
Correct |
1760 ms |
116624 KB |
Output is correct |
72 |
Correct |
1847 ms |
116648 KB |
Output is correct |
73 |
Correct |
1543 ms |
105812 KB |
Output is correct |
74 |
Correct |
1589 ms |
107036 KB |
Output is correct |
75 |
Correct |
1537 ms |
105996 KB |
Output is correct |
76 |
Correct |
1529 ms |
106064 KB |
Output is correct |
77 |
Correct |
1479 ms |
105808 KB |
Output is correct |
78 |
Correct |
1670 ms |
117440 KB |
Output is correct |
79 |
Correct |
1466 ms |
99672 KB |
Output is correct |
80 |
Correct |
1656 ms |
112472 KB |
Output is correct |