#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pii pair<int,int>
#define pb push_back
const int mn=1e6+5;
const int mod=1e9+7;
int st[4*mn];
int a[mn];
struct query{
int l,k,id;
};
vector<query> q[mn];
void update(int id,int l,int r,int pos,int val){
if (l>pos||r<pos) return;
if (l==r){
st[id]=val;
return;
}
int mid=l+r>>1;
update(id<<1,l,mid,pos,val);
update(id<<1|1,mid+1,r,pos,val);
st[id]=max(st[id<<1],st[id<<1|1]);
}
int get(int id,int l,int r,int u,int v){
if (l>v||r<u) return -1e9;
if (l>=u&&r<=v) return st[id];
int mid=l+r>>1;
return max(get(id<<1,l,mid,u,v),get(id<<1|1,mid+1,r,u,v));
}
int ans[mn];
signed main(){
//freopen("","r",stdin);
//freopen("","w",stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
int n,m;
cin>>n>>m;
for (int i=1;i<=n;i++){
cin>>a[i];
}
memset(st,-0x3f,sizeof(st));
for (int i=1;i<=m;i++){
int l,r,k;
cin>>l>>r>>k;
q[r].pb({l,k,i});
}
stack<pii> s;
for (int i=1;i<=n;i++){
while (!s.empty()&&s.top().fi<a[i]) s.pop();
if (!s.empty()&&a[i]!=s.top().fi) update(1,1,n,s.top().se,a[i]+s.top().fi);
s.push({a[i],i});
for (query x:q[i]) ans[x.id]=(get(1,1,n,x.l,i)<=x.k);
}
for (int i=1;i<=m;i++) cout<<ans[i]<<"\n";
}
Compilation message
sortbooks.cpp: In function 'void update(long long int, long long int, long long int, long long int, long long int)':
sortbooks.cpp:22:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
22 | int mid=l+r>>1;
| ~^~
sortbooks.cpp: In function 'long long int get(long long int, long long int, long long int, long long int, long long int)':
sortbooks.cpp:30:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
30 | int mid=l+r>>1;
| ~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
55128 KB |
Output is correct |
2 |
Correct |
22 ms |
55040 KB |
Output is correct |
3 |
Correct |
22 ms |
55228 KB |
Output is correct |
4 |
Correct |
22 ms |
55076 KB |
Output is correct |
5 |
Correct |
19 ms |
55132 KB |
Output is correct |
6 |
Correct |
20 ms |
55132 KB |
Output is correct |
7 |
Correct |
22 ms |
55132 KB |
Output is correct |
8 |
Correct |
22 ms |
55128 KB |
Output is correct |
9 |
Correct |
24 ms |
55128 KB |
Output is correct |
10 |
Correct |
19 ms |
55268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
55128 KB |
Output is correct |
2 |
Correct |
22 ms |
55040 KB |
Output is correct |
3 |
Correct |
22 ms |
55228 KB |
Output is correct |
4 |
Correct |
22 ms |
55076 KB |
Output is correct |
5 |
Correct |
19 ms |
55132 KB |
Output is correct |
6 |
Correct |
20 ms |
55132 KB |
Output is correct |
7 |
Correct |
22 ms |
55132 KB |
Output is correct |
8 |
Correct |
22 ms |
55128 KB |
Output is correct |
9 |
Correct |
24 ms |
55128 KB |
Output is correct |
10 |
Correct |
19 ms |
55268 KB |
Output is correct |
11 |
Correct |
23 ms |
55380 KB |
Output is correct |
12 |
Correct |
24 ms |
55388 KB |
Output is correct |
13 |
Correct |
23 ms |
55388 KB |
Output is correct |
14 |
Correct |
26 ms |
55452 KB |
Output is correct |
15 |
Correct |
24 ms |
55644 KB |
Output is correct |
16 |
Correct |
24 ms |
55384 KB |
Output is correct |
17 |
Correct |
23 ms |
55388 KB |
Output is correct |
18 |
Correct |
24 ms |
55388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1034 ms |
105300 KB |
Output is correct |
2 |
Correct |
1090 ms |
138320 KB |
Output is correct |
3 |
Correct |
1091 ms |
137996 KB |
Output is correct |
4 |
Correct |
1050 ms |
138064 KB |
Output is correct |
5 |
Correct |
893 ms |
138152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
91 ms |
60240 KB |
Output is correct |
2 |
Correct |
86 ms |
62292 KB |
Output is correct |
3 |
Correct |
81 ms |
62288 KB |
Output is correct |
4 |
Correct |
84 ms |
62288 KB |
Output is correct |
5 |
Correct |
81 ms |
62092 KB |
Output is correct |
6 |
Correct |
68 ms |
62104 KB |
Output is correct |
7 |
Correct |
68 ms |
62036 KB |
Output is correct |
8 |
Correct |
78 ms |
62216 KB |
Output is correct |
9 |
Correct |
46 ms |
60256 KB |
Output is correct |
10 |
Correct |
79 ms |
62260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
55128 KB |
Output is correct |
2 |
Correct |
22 ms |
55040 KB |
Output is correct |
3 |
Correct |
22 ms |
55228 KB |
Output is correct |
4 |
Correct |
22 ms |
55076 KB |
Output is correct |
5 |
Correct |
19 ms |
55132 KB |
Output is correct |
6 |
Correct |
20 ms |
55132 KB |
Output is correct |
7 |
Correct |
22 ms |
55132 KB |
Output is correct |
8 |
Correct |
22 ms |
55128 KB |
Output is correct |
9 |
Correct |
24 ms |
55128 KB |
Output is correct |
10 |
Correct |
19 ms |
55268 KB |
Output is correct |
11 |
Correct |
23 ms |
55380 KB |
Output is correct |
12 |
Correct |
24 ms |
55388 KB |
Output is correct |
13 |
Correct |
23 ms |
55388 KB |
Output is correct |
14 |
Correct |
26 ms |
55452 KB |
Output is correct |
15 |
Correct |
24 ms |
55644 KB |
Output is correct |
16 |
Correct |
24 ms |
55384 KB |
Output is correct |
17 |
Correct |
23 ms |
55388 KB |
Output is correct |
18 |
Correct |
24 ms |
55388 KB |
Output is correct |
19 |
Correct |
189 ms |
71760 KB |
Output is correct |
20 |
Correct |
204 ms |
71856 KB |
Output is correct |
21 |
Correct |
166 ms |
72508 KB |
Output is correct |
22 |
Correct |
166 ms |
72272 KB |
Output is correct |
23 |
Correct |
170 ms |
72116 KB |
Output is correct |
24 |
Correct |
132 ms |
72272 KB |
Output is correct |
25 |
Correct |
132 ms |
72292 KB |
Output is correct |
26 |
Correct |
152 ms |
72020 KB |
Output is correct |
27 |
Correct |
148 ms |
71984 KB |
Output is correct |
28 |
Correct |
136 ms |
71764 KB |
Output is correct |
29 |
Correct |
148 ms |
71760 KB |
Output is correct |
30 |
Correct |
175 ms |
71760 KB |
Output is correct |
31 |
Correct |
157 ms |
71764 KB |
Output is correct |
32 |
Correct |
154 ms |
71824 KB |
Output is correct |
33 |
Correct |
162 ms |
71744 KB |
Output is correct |
34 |
Correct |
124 ms |
71504 KB |
Output is correct |
35 |
Correct |
122 ms |
71508 KB |
Output is correct |
36 |
Correct |
129 ms |
71252 KB |
Output is correct |
37 |
Correct |
132 ms |
71304 KB |
Output is correct |
38 |
Correct |
135 ms |
71524 KB |
Output is correct |
39 |
Correct |
151 ms |
69892 KB |
Output is correct |
40 |
Correct |
119 ms |
68092 KB |
Output is correct |
41 |
Correct |
140 ms |
70396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
55128 KB |
Output is correct |
2 |
Correct |
22 ms |
55040 KB |
Output is correct |
3 |
Correct |
22 ms |
55228 KB |
Output is correct |
4 |
Correct |
22 ms |
55076 KB |
Output is correct |
5 |
Correct |
19 ms |
55132 KB |
Output is correct |
6 |
Correct |
20 ms |
55132 KB |
Output is correct |
7 |
Correct |
22 ms |
55132 KB |
Output is correct |
8 |
Correct |
22 ms |
55128 KB |
Output is correct |
9 |
Correct |
24 ms |
55128 KB |
Output is correct |
10 |
Correct |
19 ms |
55268 KB |
Output is correct |
11 |
Correct |
23 ms |
55380 KB |
Output is correct |
12 |
Correct |
24 ms |
55388 KB |
Output is correct |
13 |
Correct |
23 ms |
55388 KB |
Output is correct |
14 |
Correct |
26 ms |
55452 KB |
Output is correct |
15 |
Correct |
24 ms |
55644 KB |
Output is correct |
16 |
Correct |
24 ms |
55384 KB |
Output is correct |
17 |
Correct |
23 ms |
55388 KB |
Output is correct |
18 |
Correct |
24 ms |
55388 KB |
Output is correct |
19 |
Correct |
1034 ms |
105300 KB |
Output is correct |
20 |
Correct |
1090 ms |
138320 KB |
Output is correct |
21 |
Correct |
1091 ms |
137996 KB |
Output is correct |
22 |
Correct |
1050 ms |
138064 KB |
Output is correct |
23 |
Correct |
893 ms |
138152 KB |
Output is correct |
24 |
Correct |
91 ms |
60240 KB |
Output is correct |
25 |
Correct |
86 ms |
62292 KB |
Output is correct |
26 |
Correct |
81 ms |
62288 KB |
Output is correct |
27 |
Correct |
84 ms |
62288 KB |
Output is correct |
28 |
Correct |
81 ms |
62092 KB |
Output is correct |
29 |
Correct |
68 ms |
62104 KB |
Output is correct |
30 |
Correct |
68 ms |
62036 KB |
Output is correct |
31 |
Correct |
78 ms |
62216 KB |
Output is correct |
32 |
Correct |
46 ms |
60256 KB |
Output is correct |
33 |
Correct |
79 ms |
62260 KB |
Output is correct |
34 |
Correct |
189 ms |
71760 KB |
Output is correct |
35 |
Correct |
204 ms |
71856 KB |
Output is correct |
36 |
Correct |
166 ms |
72508 KB |
Output is correct |
37 |
Correct |
166 ms |
72272 KB |
Output is correct |
38 |
Correct |
170 ms |
72116 KB |
Output is correct |
39 |
Correct |
132 ms |
72272 KB |
Output is correct |
40 |
Correct |
132 ms |
72292 KB |
Output is correct |
41 |
Correct |
152 ms |
72020 KB |
Output is correct |
42 |
Correct |
148 ms |
71984 KB |
Output is correct |
43 |
Correct |
136 ms |
71764 KB |
Output is correct |
44 |
Correct |
148 ms |
71760 KB |
Output is correct |
45 |
Correct |
175 ms |
71760 KB |
Output is correct |
46 |
Correct |
157 ms |
71764 KB |
Output is correct |
47 |
Correct |
154 ms |
71824 KB |
Output is correct |
48 |
Correct |
162 ms |
71744 KB |
Output is correct |
49 |
Correct |
124 ms |
71504 KB |
Output is correct |
50 |
Correct |
122 ms |
71508 KB |
Output is correct |
51 |
Correct |
129 ms |
71252 KB |
Output is correct |
52 |
Correct |
132 ms |
71304 KB |
Output is correct |
53 |
Correct |
135 ms |
71524 KB |
Output is correct |
54 |
Correct |
151 ms |
69892 KB |
Output is correct |
55 |
Correct |
119 ms |
68092 KB |
Output is correct |
56 |
Correct |
140 ms |
70396 KB |
Output is correct |
57 |
Correct |
1097 ms |
139020 KB |
Output is correct |
58 |
Correct |
1050 ms |
138940 KB |
Output is correct |
59 |
Correct |
988 ms |
139784 KB |
Output is correct |
60 |
Correct |
988 ms |
139852 KB |
Output is correct |
61 |
Correct |
940 ms |
139860 KB |
Output is correct |
62 |
Correct |
953 ms |
139848 KB |
Output is correct |
63 |
Correct |
564 ms |
139860 KB |
Output is correct |
64 |
Correct |
577 ms |
139860 KB |
Output is correct |
65 |
Correct |
788 ms |
139860 KB |
Output is correct |
66 |
Correct |
808 ms |
139932 KB |
Output is correct |
67 |
Correct |
807 ms |
139856 KB |
Output is correct |
68 |
Correct |
837 ms |
139148 KB |
Output is correct |
69 |
Correct |
813 ms |
139092 KB |
Output is correct |
70 |
Correct |
913 ms |
139048 KB |
Output is correct |
71 |
Correct |
812 ms |
139068 KB |
Output is correct |
72 |
Correct |
870 ms |
139088 KB |
Output is correct |
73 |
Correct |
568 ms |
133968 KB |
Output is correct |
74 |
Correct |
580 ms |
134660 KB |
Output is correct |
75 |
Correct |
531 ms |
133712 KB |
Output is correct |
76 |
Correct |
556 ms |
134228 KB |
Output is correct |
77 |
Correct |
553 ms |
133968 KB |
Output is correct |
78 |
Correct |
813 ms |
130548 KB |
Output is correct |
79 |
Correct |
583 ms |
119396 KB |
Output is correct |
80 |
Correct |
730 ms |
134812 KB |
Output is correct |