#include"bits/stdc++.h"
using namespace std;
#define ll long long
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false)
#define inf LLONG_MAX
const int lmt=1e6+10;
struct id{
int l=0,k=0,idx=0;
};
vector<id>adj[lmt];
int a[lmt],lft[lmt],tree[3*lmt],ans[lmt];
void update(int at,int L,int R,int pos,int val){
if(L==R){
tree[at]=val;
return;
}
int mid=(L+R)>>1;
if(pos<=mid) update(at*2,L,mid,pos,val);
else update(at*2+1,mid+1,R,pos,val);
tree[at]=max(tree[at*2],tree[at*2+1]);
}
int query(int at,int L,int R,int l,int r){
if(r<L || R<l || r<l) return 0;
if(l<=L && R<=r){
return tree[at];
}
int mid=(L+R)>>1;
int x=query(at*2,L,mid,l,r),y=query(at*2+1,mid+1,R,l,r);
return max(x,y);
}
int main(){
fastio;
int n,m;
cin>>n>>m;
vector<array<int,4>>q;
for(int i=1;i<=n;i++){
cin>>a[i];
}
stack<int>s;
for(int i=1;i<=n;i++){
lft[i]=i;
while(!s.empty() && a[s.top()]<=a[i]){
lft[i]=lft[s.top()];
s.pop();
}
s.push(i);
}
for(int i=1;i<=m;i++){
int l,r,k;
cin>>l>>r>>k;
adj[r].push_back({l,k,i});
}
for(int i=1;i<=n;i++){
if(lft[i]-1>0) update(1,1,n,lft[i]-1,a[i]+a[lft[i]-1]);
for(auto x:adj[i]){
ans[x.idx]=(x.k>=query(1,1,n,x.l,i));
}
}
for(int i=1;i<=m;i++) cout<<ans[i]<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23756 KB |
Output is correct |
2 |
Correct |
13 ms |
23744 KB |
Output is correct |
3 |
Correct |
12 ms |
23808 KB |
Output is correct |
4 |
Correct |
13 ms |
23756 KB |
Output is correct |
5 |
Correct |
12 ms |
23828 KB |
Output is correct |
6 |
Correct |
13 ms |
23788 KB |
Output is correct |
7 |
Correct |
12 ms |
23756 KB |
Output is correct |
8 |
Correct |
12 ms |
23848 KB |
Output is correct |
9 |
Correct |
11 ms |
23756 KB |
Output is correct |
10 |
Correct |
12 ms |
23756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23756 KB |
Output is correct |
2 |
Correct |
13 ms |
23744 KB |
Output is correct |
3 |
Correct |
12 ms |
23808 KB |
Output is correct |
4 |
Correct |
13 ms |
23756 KB |
Output is correct |
5 |
Correct |
12 ms |
23828 KB |
Output is correct |
6 |
Correct |
13 ms |
23788 KB |
Output is correct |
7 |
Correct |
12 ms |
23756 KB |
Output is correct |
8 |
Correct |
12 ms |
23848 KB |
Output is correct |
9 |
Correct |
11 ms |
23756 KB |
Output is correct |
10 |
Correct |
12 ms |
23756 KB |
Output is correct |
11 |
Correct |
13 ms |
23920 KB |
Output is correct |
12 |
Correct |
14 ms |
24012 KB |
Output is correct |
13 |
Correct |
14 ms |
24012 KB |
Output is correct |
14 |
Correct |
15 ms |
24012 KB |
Output is correct |
15 |
Correct |
16 ms |
24032 KB |
Output is correct |
16 |
Correct |
14 ms |
24016 KB |
Output is correct |
17 |
Correct |
14 ms |
24012 KB |
Output is correct |
18 |
Correct |
15 ms |
24012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1273 ms |
74780 KB |
Output is correct |
2 |
Correct |
1310 ms |
100216 KB |
Output is correct |
3 |
Correct |
1263 ms |
100216 KB |
Output is correct |
4 |
Correct |
1316 ms |
100448 KB |
Output is correct |
5 |
Correct |
1062 ms |
92180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
107 ms |
28272 KB |
Output is correct |
2 |
Correct |
94 ms |
28016 KB |
Output is correct |
3 |
Correct |
82 ms |
27204 KB |
Output is correct |
4 |
Correct |
94 ms |
27204 KB |
Output is correct |
5 |
Correct |
84 ms |
27280 KB |
Output is correct |
6 |
Correct |
71 ms |
26860 KB |
Output is correct |
7 |
Correct |
71 ms |
26824 KB |
Output is correct |
8 |
Correct |
80 ms |
27132 KB |
Output is correct |
9 |
Correct |
46 ms |
25812 KB |
Output is correct |
10 |
Correct |
75 ms |
27196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23756 KB |
Output is correct |
2 |
Correct |
13 ms |
23744 KB |
Output is correct |
3 |
Correct |
12 ms |
23808 KB |
Output is correct |
4 |
Correct |
13 ms |
23756 KB |
Output is correct |
5 |
Correct |
12 ms |
23828 KB |
Output is correct |
6 |
Correct |
13 ms |
23788 KB |
Output is correct |
7 |
Correct |
12 ms |
23756 KB |
Output is correct |
8 |
Correct |
12 ms |
23848 KB |
Output is correct |
9 |
Correct |
11 ms |
23756 KB |
Output is correct |
10 |
Correct |
12 ms |
23756 KB |
Output is correct |
11 |
Correct |
13 ms |
23920 KB |
Output is correct |
12 |
Correct |
14 ms |
24012 KB |
Output is correct |
13 |
Correct |
14 ms |
24012 KB |
Output is correct |
14 |
Correct |
15 ms |
24012 KB |
Output is correct |
15 |
Correct |
16 ms |
24032 KB |
Output is correct |
16 |
Correct |
14 ms |
24016 KB |
Output is correct |
17 |
Correct |
14 ms |
24012 KB |
Output is correct |
18 |
Correct |
15 ms |
24012 KB |
Output is correct |
19 |
Correct |
207 ms |
32800 KB |
Output is correct |
20 |
Correct |
210 ms |
32836 KB |
Output is correct |
21 |
Correct |
188 ms |
32264 KB |
Output is correct |
22 |
Correct |
183 ms |
32348 KB |
Output is correct |
23 |
Correct |
188 ms |
32312 KB |
Output is correct |
24 |
Correct |
163 ms |
30268 KB |
Output is correct |
25 |
Correct |
158 ms |
30220 KB |
Output is correct |
26 |
Correct |
170 ms |
30404 KB |
Output is correct |
27 |
Correct |
169 ms |
30404 KB |
Output is correct |
28 |
Correct |
172 ms |
30392 KB |
Output is correct |
29 |
Correct |
185 ms |
30788 KB |
Output is correct |
30 |
Correct |
178 ms |
30772 KB |
Output is correct |
31 |
Correct |
203 ms |
30716 KB |
Output is correct |
32 |
Correct |
180 ms |
30756 KB |
Output is correct |
33 |
Correct |
181 ms |
30760 KB |
Output is correct |
34 |
Correct |
156 ms |
30012 KB |
Output is correct |
35 |
Correct |
150 ms |
29820 KB |
Output is correct |
36 |
Correct |
146 ms |
29964 KB |
Output is correct |
37 |
Correct |
144 ms |
29892 KB |
Output is correct |
38 |
Correct |
154 ms |
29900 KB |
Output is correct |
39 |
Correct |
164 ms |
31072 KB |
Output is correct |
40 |
Correct |
131 ms |
29600 KB |
Output is correct |
41 |
Correct |
166 ms |
30472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23756 KB |
Output is correct |
2 |
Correct |
13 ms |
23744 KB |
Output is correct |
3 |
Correct |
12 ms |
23808 KB |
Output is correct |
4 |
Correct |
13 ms |
23756 KB |
Output is correct |
5 |
Correct |
12 ms |
23828 KB |
Output is correct |
6 |
Correct |
13 ms |
23788 KB |
Output is correct |
7 |
Correct |
12 ms |
23756 KB |
Output is correct |
8 |
Correct |
12 ms |
23848 KB |
Output is correct |
9 |
Correct |
11 ms |
23756 KB |
Output is correct |
10 |
Correct |
12 ms |
23756 KB |
Output is correct |
11 |
Correct |
13 ms |
23920 KB |
Output is correct |
12 |
Correct |
14 ms |
24012 KB |
Output is correct |
13 |
Correct |
14 ms |
24012 KB |
Output is correct |
14 |
Correct |
15 ms |
24012 KB |
Output is correct |
15 |
Correct |
16 ms |
24032 KB |
Output is correct |
16 |
Correct |
14 ms |
24016 KB |
Output is correct |
17 |
Correct |
14 ms |
24012 KB |
Output is correct |
18 |
Correct |
15 ms |
24012 KB |
Output is correct |
19 |
Correct |
1273 ms |
74780 KB |
Output is correct |
20 |
Correct |
1310 ms |
100216 KB |
Output is correct |
21 |
Correct |
1263 ms |
100216 KB |
Output is correct |
22 |
Correct |
1316 ms |
100448 KB |
Output is correct |
23 |
Correct |
1062 ms |
92180 KB |
Output is correct |
24 |
Correct |
107 ms |
28272 KB |
Output is correct |
25 |
Correct |
94 ms |
28016 KB |
Output is correct |
26 |
Correct |
82 ms |
27204 KB |
Output is correct |
27 |
Correct |
94 ms |
27204 KB |
Output is correct |
28 |
Correct |
84 ms |
27280 KB |
Output is correct |
29 |
Correct |
71 ms |
26860 KB |
Output is correct |
30 |
Correct |
71 ms |
26824 KB |
Output is correct |
31 |
Correct |
80 ms |
27132 KB |
Output is correct |
32 |
Correct |
46 ms |
25812 KB |
Output is correct |
33 |
Correct |
75 ms |
27196 KB |
Output is correct |
34 |
Correct |
207 ms |
32800 KB |
Output is correct |
35 |
Correct |
210 ms |
32836 KB |
Output is correct |
36 |
Correct |
188 ms |
32264 KB |
Output is correct |
37 |
Correct |
183 ms |
32348 KB |
Output is correct |
38 |
Correct |
188 ms |
32312 KB |
Output is correct |
39 |
Correct |
163 ms |
30268 KB |
Output is correct |
40 |
Correct |
158 ms |
30220 KB |
Output is correct |
41 |
Correct |
170 ms |
30404 KB |
Output is correct |
42 |
Correct |
169 ms |
30404 KB |
Output is correct |
43 |
Correct |
172 ms |
30392 KB |
Output is correct |
44 |
Correct |
185 ms |
30788 KB |
Output is correct |
45 |
Correct |
178 ms |
30772 KB |
Output is correct |
46 |
Correct |
203 ms |
30716 KB |
Output is correct |
47 |
Correct |
180 ms |
30756 KB |
Output is correct |
48 |
Correct |
181 ms |
30760 KB |
Output is correct |
49 |
Correct |
156 ms |
30012 KB |
Output is correct |
50 |
Correct |
150 ms |
29820 KB |
Output is correct |
51 |
Correct |
146 ms |
29964 KB |
Output is correct |
52 |
Correct |
144 ms |
29892 KB |
Output is correct |
53 |
Correct |
154 ms |
29900 KB |
Output is correct |
54 |
Correct |
164 ms |
31072 KB |
Output is correct |
55 |
Correct |
131 ms |
29600 KB |
Output is correct |
56 |
Correct |
166 ms |
30472 KB |
Output is correct |
57 |
Correct |
1350 ms |
100464 KB |
Output is correct |
58 |
Correct |
1311 ms |
100536 KB |
Output is correct |
59 |
Correct |
1196 ms |
98980 KB |
Output is correct |
60 |
Correct |
1204 ms |
98896 KB |
Output is correct |
61 |
Correct |
1233 ms |
98860 KB |
Output is correct |
62 |
Correct |
1229 ms |
98740 KB |
Output is correct |
63 |
Correct |
797 ms |
87112 KB |
Output is correct |
64 |
Correct |
794 ms |
86920 KB |
Output is correct |
65 |
Correct |
1057 ms |
89860 KB |
Output is correct |
66 |
Correct |
1028 ms |
89896 KB |
Output is correct |
67 |
Correct |
1049 ms |
90056 KB |
Output is correct |
68 |
Correct |
1092 ms |
91560 KB |
Output is correct |
69 |
Correct |
1085 ms |
91744 KB |
Output is correct |
70 |
Correct |
1110 ms |
91288 KB |
Output is correct |
71 |
Correct |
1092 ms |
91288 KB |
Output is correct |
72 |
Correct |
1085 ms |
91448 KB |
Output is correct |
73 |
Correct |
747 ms |
83100 KB |
Output is correct |
74 |
Correct |
782 ms |
84052 KB |
Output is correct |
75 |
Correct |
742 ms |
83228 KB |
Output is correct |
76 |
Correct |
757 ms |
83388 KB |
Output is correct |
77 |
Correct |
761 ms |
82812 KB |
Output is correct |
78 |
Correct |
985 ms |
86604 KB |
Output is correct |
79 |
Correct |
686 ms |
73388 KB |
Output is correct |
80 |
Correct |
947 ms |
81404 KB |
Output is correct |