// Muallif: Mansuraliyev Husanboy Murotali o'g'li >> NamPS
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const double PI=3.1415926535897932384626433832795;
// 0-9 >> 48-57; A-Z>>65-90 and a-z>>97-122 respectively;
const int N=1e6+5;
int tree[4*N];
void update(int x,int l,int r, int pos, int val){
if(l==r){
tree[x]=max(tree[x],val);
return;
}
int m=(l+r)/2;
if(pos<=m){
update(2*x,l,m,pos,val);
}else
update(2*x+1,m+1,r,pos,val);
tree[x]=max(tree[x*2],tree[x*2+1]);
return;
}
int get(int x,int l,int r, int ll, int rr){
if(r<ll||l>rr){
return 0;
}
if(r<=rr&&l>=ll){
return tree[x];
}
int m=(l+r)/2;
return max(get(x*2,l,m,ll,rr),get(2*x+1,m+1,r,ll,rr));
}
vector<pair<int,pair<int,int>>> v[N];
int main(){
ios;
int n,q; cin>>n>>q;
int a[n+1];for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=q;i++){
int l,r,k; cin>>l>>r>>k;
v[r].push_back({l,make_pair(i,k)});
}
vector<int> ans(::N,0); stack<int> s;
a[0]=2e9;
s.push(0);
for(int i=1;i<=n;i++){
while(a[s.top()]<=a[i]) s.pop();
int j=s.top();
if(j!=0){
update(1,1,n,j,a[j]+a[i]);
}
for(auto u:v[i]){
ans[u.second.first]=(get(1,1,n,u.first,i)<=u.second.second?1:0);
}
s.push(i);
}
for(int i=1;i<=q;i++){
cout<<ans[i]<<"\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
27660 KB |
Output is correct |
2 |
Correct |
14 ms |
27724 KB |
Output is correct |
3 |
Correct |
17 ms |
27660 KB |
Output is correct |
4 |
Correct |
15 ms |
27620 KB |
Output is correct |
5 |
Correct |
16 ms |
27616 KB |
Output is correct |
6 |
Correct |
17 ms |
27704 KB |
Output is correct |
7 |
Correct |
14 ms |
27648 KB |
Output is correct |
8 |
Correct |
16 ms |
27724 KB |
Output is correct |
9 |
Correct |
14 ms |
27652 KB |
Output is correct |
10 |
Correct |
14 ms |
27724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
27660 KB |
Output is correct |
2 |
Correct |
14 ms |
27724 KB |
Output is correct |
3 |
Correct |
17 ms |
27660 KB |
Output is correct |
4 |
Correct |
15 ms |
27620 KB |
Output is correct |
5 |
Correct |
16 ms |
27616 KB |
Output is correct |
6 |
Correct |
17 ms |
27704 KB |
Output is correct |
7 |
Correct |
14 ms |
27648 KB |
Output is correct |
8 |
Correct |
16 ms |
27724 KB |
Output is correct |
9 |
Correct |
14 ms |
27652 KB |
Output is correct |
10 |
Correct |
14 ms |
27724 KB |
Output is correct |
11 |
Correct |
15 ms |
27848 KB |
Output is correct |
12 |
Correct |
16 ms |
27820 KB |
Output is correct |
13 |
Correct |
16 ms |
27856 KB |
Output is correct |
14 |
Correct |
18 ms |
27884 KB |
Output is correct |
15 |
Correct |
18 ms |
27992 KB |
Output is correct |
16 |
Correct |
19 ms |
27900 KB |
Output is correct |
17 |
Correct |
19 ms |
27872 KB |
Output is correct |
18 |
Correct |
17 ms |
27864 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1405 ms |
63896 KB |
Output is correct |
2 |
Correct |
1384 ms |
76324 KB |
Output is correct |
3 |
Correct |
1341 ms |
76436 KB |
Output is correct |
4 |
Correct |
1303 ms |
76232 KB |
Output is correct |
5 |
Correct |
1065 ms |
68524 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
100 ms |
31512 KB |
Output is correct |
2 |
Correct |
89 ms |
31304 KB |
Output is correct |
3 |
Correct |
86 ms |
30408 KB |
Output is correct |
4 |
Correct |
84 ms |
30428 KB |
Output is correct |
5 |
Correct |
83 ms |
30416 KB |
Output is correct |
6 |
Correct |
80 ms |
30072 KB |
Output is correct |
7 |
Correct |
73 ms |
30152 KB |
Output is correct |
8 |
Correct |
74 ms |
30360 KB |
Output is correct |
9 |
Correct |
47 ms |
29436 KB |
Output is correct |
10 |
Correct |
79 ms |
30324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
27660 KB |
Output is correct |
2 |
Correct |
14 ms |
27724 KB |
Output is correct |
3 |
Correct |
17 ms |
27660 KB |
Output is correct |
4 |
Correct |
15 ms |
27620 KB |
Output is correct |
5 |
Correct |
16 ms |
27616 KB |
Output is correct |
6 |
Correct |
17 ms |
27704 KB |
Output is correct |
7 |
Correct |
14 ms |
27648 KB |
Output is correct |
8 |
Correct |
16 ms |
27724 KB |
Output is correct |
9 |
Correct |
14 ms |
27652 KB |
Output is correct |
10 |
Correct |
14 ms |
27724 KB |
Output is correct |
11 |
Correct |
15 ms |
27848 KB |
Output is correct |
12 |
Correct |
16 ms |
27820 KB |
Output is correct |
13 |
Correct |
16 ms |
27856 KB |
Output is correct |
14 |
Correct |
18 ms |
27884 KB |
Output is correct |
15 |
Correct |
18 ms |
27992 KB |
Output is correct |
16 |
Correct |
19 ms |
27900 KB |
Output is correct |
17 |
Correct |
19 ms |
27872 KB |
Output is correct |
18 |
Correct |
17 ms |
27864 KB |
Output is correct |
19 |
Correct |
254 ms |
35204 KB |
Output is correct |
20 |
Correct |
199 ms |
35180 KB |
Output is correct |
21 |
Correct |
206 ms |
34788 KB |
Output is correct |
22 |
Correct |
183 ms |
34832 KB |
Output is correct |
23 |
Correct |
186 ms |
34812 KB |
Output is correct |
24 |
Correct |
162 ms |
32776 KB |
Output is correct |
25 |
Correct |
151 ms |
32808 KB |
Output is correct |
26 |
Correct |
175 ms |
32864 KB |
Output is correct |
27 |
Correct |
169 ms |
32912 KB |
Output is correct |
28 |
Correct |
202 ms |
33036 KB |
Output is correct |
29 |
Correct |
190 ms |
33300 KB |
Output is correct |
30 |
Correct |
230 ms |
33336 KB |
Output is correct |
31 |
Correct |
181 ms |
33204 KB |
Output is correct |
32 |
Correct |
186 ms |
33376 KB |
Output is correct |
33 |
Correct |
196 ms |
33260 KB |
Output is correct |
34 |
Correct |
161 ms |
32428 KB |
Output is correct |
35 |
Correct |
161 ms |
32480 KB |
Output is correct |
36 |
Correct |
151 ms |
32512 KB |
Output is correct |
37 |
Correct |
143 ms |
32400 KB |
Output is correct |
38 |
Correct |
161 ms |
32392 KB |
Output is correct |
39 |
Correct |
187 ms |
33516 KB |
Output is correct |
40 |
Correct |
137 ms |
32292 KB |
Output is correct |
41 |
Correct |
166 ms |
32836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
27660 KB |
Output is correct |
2 |
Correct |
14 ms |
27724 KB |
Output is correct |
3 |
Correct |
17 ms |
27660 KB |
Output is correct |
4 |
Correct |
15 ms |
27620 KB |
Output is correct |
5 |
Correct |
16 ms |
27616 KB |
Output is correct |
6 |
Correct |
17 ms |
27704 KB |
Output is correct |
7 |
Correct |
14 ms |
27648 KB |
Output is correct |
8 |
Correct |
16 ms |
27724 KB |
Output is correct |
9 |
Correct |
14 ms |
27652 KB |
Output is correct |
10 |
Correct |
14 ms |
27724 KB |
Output is correct |
11 |
Correct |
15 ms |
27848 KB |
Output is correct |
12 |
Correct |
16 ms |
27820 KB |
Output is correct |
13 |
Correct |
16 ms |
27856 KB |
Output is correct |
14 |
Correct |
18 ms |
27884 KB |
Output is correct |
15 |
Correct |
18 ms |
27992 KB |
Output is correct |
16 |
Correct |
19 ms |
27900 KB |
Output is correct |
17 |
Correct |
19 ms |
27872 KB |
Output is correct |
18 |
Correct |
17 ms |
27864 KB |
Output is correct |
19 |
Correct |
1405 ms |
63896 KB |
Output is correct |
20 |
Correct |
1384 ms |
76324 KB |
Output is correct |
21 |
Correct |
1341 ms |
76436 KB |
Output is correct |
22 |
Correct |
1303 ms |
76232 KB |
Output is correct |
23 |
Correct |
1065 ms |
68524 KB |
Output is correct |
24 |
Correct |
100 ms |
31512 KB |
Output is correct |
25 |
Correct |
89 ms |
31304 KB |
Output is correct |
26 |
Correct |
86 ms |
30408 KB |
Output is correct |
27 |
Correct |
84 ms |
30428 KB |
Output is correct |
28 |
Correct |
83 ms |
30416 KB |
Output is correct |
29 |
Correct |
80 ms |
30072 KB |
Output is correct |
30 |
Correct |
73 ms |
30152 KB |
Output is correct |
31 |
Correct |
74 ms |
30360 KB |
Output is correct |
32 |
Correct |
47 ms |
29436 KB |
Output is correct |
33 |
Correct |
79 ms |
30324 KB |
Output is correct |
34 |
Correct |
254 ms |
35204 KB |
Output is correct |
35 |
Correct |
199 ms |
35180 KB |
Output is correct |
36 |
Correct |
206 ms |
34788 KB |
Output is correct |
37 |
Correct |
183 ms |
34832 KB |
Output is correct |
38 |
Correct |
186 ms |
34812 KB |
Output is correct |
39 |
Correct |
162 ms |
32776 KB |
Output is correct |
40 |
Correct |
151 ms |
32808 KB |
Output is correct |
41 |
Correct |
175 ms |
32864 KB |
Output is correct |
42 |
Correct |
169 ms |
32912 KB |
Output is correct |
43 |
Correct |
202 ms |
33036 KB |
Output is correct |
44 |
Correct |
190 ms |
33300 KB |
Output is correct |
45 |
Correct |
230 ms |
33336 KB |
Output is correct |
46 |
Correct |
181 ms |
33204 KB |
Output is correct |
47 |
Correct |
186 ms |
33376 KB |
Output is correct |
48 |
Correct |
196 ms |
33260 KB |
Output is correct |
49 |
Correct |
161 ms |
32428 KB |
Output is correct |
50 |
Correct |
161 ms |
32480 KB |
Output is correct |
51 |
Correct |
151 ms |
32512 KB |
Output is correct |
52 |
Correct |
143 ms |
32400 KB |
Output is correct |
53 |
Correct |
161 ms |
32392 KB |
Output is correct |
54 |
Correct |
187 ms |
33516 KB |
Output is correct |
55 |
Correct |
137 ms |
32292 KB |
Output is correct |
56 |
Correct |
166 ms |
32836 KB |
Output is correct |
57 |
Correct |
1346 ms |
69100 KB |
Output is correct |
58 |
Correct |
1261 ms |
69352 KB |
Output is correct |
59 |
Correct |
1267 ms |
67748 KB |
Output is correct |
60 |
Correct |
1237 ms |
67768 KB |
Output is correct |
61 |
Correct |
1348 ms |
67816 KB |
Output is correct |
62 |
Correct |
1319 ms |
67816 KB |
Output is correct |
63 |
Correct |
785 ms |
57844 KB |
Output is correct |
64 |
Correct |
805 ms |
57776 KB |
Output is correct |
65 |
Correct |
1055 ms |
59664 KB |
Output is correct |
66 |
Correct |
1074 ms |
59976 KB |
Output is correct |
67 |
Correct |
1077 ms |
54272 KB |
Output is correct |
68 |
Correct |
1084 ms |
61592 KB |
Output is correct |
69 |
Correct |
1050 ms |
61444 KB |
Output is correct |
70 |
Correct |
1074 ms |
62020 KB |
Output is correct |
71 |
Correct |
1066 ms |
62148 KB |
Output is correct |
72 |
Correct |
1026 ms |
61156 KB |
Output is correct |
73 |
Correct |
748 ms |
56352 KB |
Output is correct |
74 |
Correct |
822 ms |
59700 KB |
Output is correct |
75 |
Correct |
740 ms |
59452 KB |
Output is correct |
76 |
Correct |
720 ms |
58584 KB |
Output is correct |
77 |
Correct |
734 ms |
57976 KB |
Output is correct |
78 |
Correct |
1027 ms |
61568 KB |
Output is correct |
79 |
Correct |
716 ms |
55596 KB |
Output is correct |
80 |
Correct |
920 ms |
59592 KB |
Output is correct |