#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
using namespace std;
int t[4000001];
int n,m;
int a[1000001];
stack<int> st;
int ans[1000001];
vector<pair<pair<int,int>,pair<int,int> > >vec1;
int get(int v,int tl,int tr,int l,int r){
if(l==tl&&r==tr){
return t[v];
}
int m=(tl+tr)/2;
if(r<=m)
return get(2*v,tl,m,l,r);
else{
if(l>m)
return get(2*v+1,m+1,tr,l,r);
else
return max(get(2*v,tl,m,l,m),get(2*v+1,m+1,tr,m+1,r));
}
}
void update(int v,int tl,int tr,int x,int p){
if(tl==tr){
t[v]=x;
}
else{
int m=(tl+tr)/2;
if(p<=m)
update(2*v,tl,m,x,p);
else
update(2*v+1,m+1,tr,x,p);
t[v]=max(t[2*v],t[2*v+1]);
}
}
int main(){
cin>>n>>m;
for(int k=1;k<=n;k++){
cin>>a[k];
}
vector<vector<int> > vec(n+1);
for(int i=1;i<=n;i++){
while(!st.empty()){
int v=st.top();
if(a[v]<=a[i])
st.pop();
else
break;
}
if(!st.empty()){
int x=st.top();
vec[x].push_back(i);
}
st.push(i);
}
for(int i=1;i<=m;i++){
int l,r,x;
cin>>l>>r>>x;
vec1.push_back({{-l,r},{x,i}});
}
sort(vec1.begin(),vec1.end());
int ind=0;
for(int k=n;k>=1;k--){
for(int pos:vec[k]){
update(1,1,n,a[pos]+a[k],pos);
}
while(ind<m){
int l=-vec1[ind].ff.ff;
if(l!=k)
break;
int r=vec1[ind].ff.ss;
int pir=vec1[ind].ss.ff;
int meo=vec1[ind].ss.ss;
int x=get(1,1,n,l,r);
if(x>pir)
ans[meo]=0;
else
ans[meo]=1;
ind++;
}
}
for(int k=1;k<=m;k++){
cout<<ans[k]<<"\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
352 KB |
Output is correct |
9 |
Correct |
1 ms |
320 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
352 KB |
Output is correct |
9 |
Correct |
1 ms |
320 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
4 ms |
588 KB |
Output is correct |
12 |
Correct |
6 ms |
716 KB |
Output is correct |
13 |
Correct |
6 ms |
716 KB |
Output is correct |
14 |
Correct |
9 ms |
972 KB |
Output is correct |
15 |
Correct |
8 ms |
972 KB |
Output is correct |
16 |
Correct |
6 ms |
800 KB |
Output is correct |
17 |
Correct |
6 ms |
692 KB |
Output is correct |
18 |
Correct |
6 ms |
752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2040 ms |
87556 KB |
Output is correct |
2 |
Correct |
2303 ms |
78764 KB |
Output is correct |
3 |
Correct |
2522 ms |
78312 KB |
Output is correct |
4 |
Correct |
2742 ms |
78332 KB |
Output is correct |
5 |
Correct |
2650 ms |
54004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
152 ms |
9912 KB |
Output is correct |
2 |
Correct |
144 ms |
9844 KB |
Output is correct |
3 |
Correct |
168 ms |
7324 KB |
Output is correct |
4 |
Correct |
150 ms |
7272 KB |
Output is correct |
5 |
Correct |
131 ms |
7332 KB |
Output is correct |
6 |
Correct |
153 ms |
7272 KB |
Output is correct |
7 |
Correct |
121 ms |
7244 KB |
Output is correct |
8 |
Correct |
118 ms |
8076 KB |
Output is correct |
9 |
Correct |
83 ms |
3876 KB |
Output is correct |
10 |
Correct |
166 ms |
7860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
352 KB |
Output is correct |
9 |
Correct |
1 ms |
320 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
4 ms |
588 KB |
Output is correct |
12 |
Correct |
6 ms |
716 KB |
Output is correct |
13 |
Correct |
6 ms |
716 KB |
Output is correct |
14 |
Correct |
9 ms |
972 KB |
Output is correct |
15 |
Correct |
8 ms |
972 KB |
Output is correct |
16 |
Correct |
6 ms |
800 KB |
Output is correct |
17 |
Correct |
6 ms |
692 KB |
Output is correct |
18 |
Correct |
6 ms |
752 KB |
Output is correct |
19 |
Correct |
381 ms |
22060 KB |
Output is correct |
20 |
Correct |
421 ms |
22044 KB |
Output is correct |
21 |
Correct |
405 ms |
21940 KB |
Output is correct |
22 |
Correct |
422 ms |
21936 KB |
Output is correct |
23 |
Correct |
374 ms |
21960 KB |
Output is correct |
24 |
Correct |
371 ms |
16532 KB |
Output is correct |
25 |
Correct |
382 ms |
16544 KB |
Output is correct |
26 |
Correct |
401 ms |
16724 KB |
Output is correct |
27 |
Correct |
373 ms |
16724 KB |
Output is correct |
28 |
Correct |
361 ms |
16708 KB |
Output is correct |
29 |
Correct |
349 ms |
16800 KB |
Output is correct |
30 |
Correct |
387 ms |
16776 KB |
Output is correct |
31 |
Correct |
357 ms |
16796 KB |
Output is correct |
32 |
Correct |
424 ms |
16784 KB |
Output is correct |
33 |
Correct |
371 ms |
16820 KB |
Output is correct |
34 |
Correct |
358 ms |
16472 KB |
Output is correct |
35 |
Correct |
384 ms |
16400 KB |
Output is correct |
36 |
Correct |
367 ms |
16296 KB |
Output is correct |
37 |
Correct |
336 ms |
16220 KB |
Output is correct |
38 |
Correct |
387 ms |
16460 KB |
Output is correct |
39 |
Correct |
337 ms |
17116 KB |
Output is correct |
40 |
Correct |
268 ms |
13224 KB |
Output is correct |
41 |
Correct |
283 ms |
16980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
352 KB |
Output is correct |
9 |
Correct |
1 ms |
320 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
4 ms |
588 KB |
Output is correct |
12 |
Correct |
6 ms |
716 KB |
Output is correct |
13 |
Correct |
6 ms |
716 KB |
Output is correct |
14 |
Correct |
9 ms |
972 KB |
Output is correct |
15 |
Correct |
8 ms |
972 KB |
Output is correct |
16 |
Correct |
6 ms |
800 KB |
Output is correct |
17 |
Correct |
6 ms |
692 KB |
Output is correct |
18 |
Correct |
6 ms |
752 KB |
Output is correct |
19 |
Correct |
2040 ms |
87556 KB |
Output is correct |
20 |
Correct |
2303 ms |
78764 KB |
Output is correct |
21 |
Correct |
2522 ms |
78312 KB |
Output is correct |
22 |
Correct |
2742 ms |
78332 KB |
Output is correct |
23 |
Correct |
2650 ms |
54004 KB |
Output is correct |
24 |
Correct |
152 ms |
9912 KB |
Output is correct |
25 |
Correct |
144 ms |
9844 KB |
Output is correct |
26 |
Correct |
168 ms |
7324 KB |
Output is correct |
27 |
Correct |
150 ms |
7272 KB |
Output is correct |
28 |
Correct |
131 ms |
7332 KB |
Output is correct |
29 |
Correct |
153 ms |
7272 KB |
Output is correct |
30 |
Correct |
121 ms |
7244 KB |
Output is correct |
31 |
Correct |
118 ms |
8076 KB |
Output is correct |
32 |
Correct |
83 ms |
3876 KB |
Output is correct |
33 |
Correct |
166 ms |
7860 KB |
Output is correct |
34 |
Correct |
381 ms |
22060 KB |
Output is correct |
35 |
Correct |
421 ms |
22044 KB |
Output is correct |
36 |
Correct |
405 ms |
21940 KB |
Output is correct |
37 |
Correct |
422 ms |
21936 KB |
Output is correct |
38 |
Correct |
374 ms |
21960 KB |
Output is correct |
39 |
Correct |
371 ms |
16532 KB |
Output is correct |
40 |
Correct |
382 ms |
16544 KB |
Output is correct |
41 |
Correct |
401 ms |
16724 KB |
Output is correct |
42 |
Correct |
373 ms |
16724 KB |
Output is correct |
43 |
Correct |
361 ms |
16708 KB |
Output is correct |
44 |
Correct |
349 ms |
16800 KB |
Output is correct |
45 |
Correct |
387 ms |
16776 KB |
Output is correct |
46 |
Correct |
357 ms |
16796 KB |
Output is correct |
47 |
Correct |
424 ms |
16784 KB |
Output is correct |
48 |
Correct |
371 ms |
16820 KB |
Output is correct |
49 |
Correct |
358 ms |
16472 KB |
Output is correct |
50 |
Correct |
384 ms |
16400 KB |
Output is correct |
51 |
Correct |
367 ms |
16296 KB |
Output is correct |
52 |
Correct |
336 ms |
16220 KB |
Output is correct |
53 |
Correct |
387 ms |
16460 KB |
Output is correct |
54 |
Correct |
337 ms |
17116 KB |
Output is correct |
55 |
Correct |
268 ms |
13224 KB |
Output is correct |
56 |
Correct |
283 ms |
16980 KB |
Output is correct |
57 |
Correct |
2167 ms |
107336 KB |
Output is correct |
58 |
Correct |
2224 ms |
107276 KB |
Output is correct |
59 |
Correct |
2043 ms |
107176 KB |
Output is correct |
60 |
Correct |
2140 ms |
107228 KB |
Output is correct |
61 |
Correct |
1964 ms |
107280 KB |
Output is correct |
62 |
Correct |
2036 ms |
107148 KB |
Output is correct |
63 |
Correct |
1624 ms |
80968 KB |
Output is correct |
64 |
Correct |
1651 ms |
81128 KB |
Output is correct |
65 |
Correct |
1779 ms |
82748 KB |
Output is correct |
66 |
Correct |
1720 ms |
82964 KB |
Output is correct |
67 |
Correct |
1701 ms |
82932 KB |
Output is correct |
68 |
Correct |
1725 ms |
82964 KB |
Output is correct |
69 |
Correct |
1704 ms |
83032 KB |
Output is correct |
70 |
Correct |
1695 ms |
82900 KB |
Output is correct |
71 |
Correct |
1742 ms |
82908 KB |
Output is correct |
72 |
Correct |
2039 ms |
82788 KB |
Output is correct |
73 |
Correct |
1604 ms |
79420 KB |
Output is correct |
74 |
Correct |
1622 ms |
80292 KB |
Output is correct |
75 |
Correct |
1574 ms |
79428 KB |
Output is correct |
76 |
Correct |
1601 ms |
79372 KB |
Output is correct |
77 |
Correct |
1620 ms |
79452 KB |
Output is correct |
78 |
Correct |
1575 ms |
84788 KB |
Output is correct |
79 |
Correct |
1223 ms |
60584 KB |
Output is correct |
80 |
Correct |
1474 ms |
84552 KB |
Output is correct |