#include <bits/stdc++.h>
#define int long long
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file(s) freopen(s".in", "r", stdin); freopen(s".out", "w", stdout)
const int N=1e6+1;
const int inf=1e18;
const int mod=1e9+7;
using namespace std;
struct edge{
int l,k,id;
};
vector<edge>v1[N];
vector<int>v;
int t[4*N];
void upd(int n,int tl,int tr,int pos,int x){
if(tl==tr){
t[n]=x;
return;
}
int mid=(tl+tr)/2;
if(pos<=mid){
upd(n*2,tl,mid,pos,x);
}else{
upd(n*2+1,mid+1,tr,pos,x);
}
t[n]=max(t[n*2],t[n*2+1]);
}
int get(int n,int tl,int tr,int l,int r){
if(tr<l||r<tl){
return 0;
}
if(l<=tl&&tr<=r){
return t[n];
}
int mid=(tl+tr)/2;
return max(get(n*2,tl,mid,l,r),get(n*2+1,mid+1,tr,l,r));
}
stack<int >st;
int pos[N];
int ans[N];
signed main(){
boost;
int n,m;
cin>>n>>m;
v.push_back(0);
for(int i=1;i<=n;i++){
int x;
cin>>x;
v.push_back(x);
}
for(int i=1;i<=n;i++){
while(st.size()>0&&v[st.top()]<=v[i]){
st.pop();
}
if(st.size()>0){
pos[i]=st.top();
}
st.push(i);
}
for(int i=1;i<=m;i++){
int l,r,k;
cin>>l>>r>>k;
edge x;
x.l=l;
x.k=k;
x.id=i;
v1[r].push_back(x);
}
for(int i=1;i<=n;i++){
if(pos[i]>0){
int y=v[pos[i]];
upd(1,1,n,pos[i],y+v[i]);
}
for(int j=0;j<v1[i].size();j++){
ans[v1[i][j].id]=(get(1,1,n,v1[i][j].l,i)<=v1[i][j].k);
}
st.push(i);
}
for(int i=1;i<=m;i++){
cout<<ans[i]<<"\n";
}
}
Compilation message
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:74:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
74 | for(int j=0;j<v1[i].size();j++){
| ~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
29520 KB |
Output is correct |
2 |
Correct |
5 ms |
27496 KB |
Output is correct |
3 |
Correct |
5 ms |
29520 KB |
Output is correct |
4 |
Correct |
5 ms |
29520 KB |
Output is correct |
5 |
Correct |
5 ms |
29520 KB |
Output is correct |
6 |
Correct |
5 ms |
29520 KB |
Output is correct |
7 |
Correct |
7 ms |
29648 KB |
Output is correct |
8 |
Correct |
6 ms |
29520 KB |
Output is correct |
9 |
Correct |
6 ms |
29696 KB |
Output is correct |
10 |
Correct |
6 ms |
29520 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
29520 KB |
Output is correct |
2 |
Correct |
5 ms |
27496 KB |
Output is correct |
3 |
Correct |
5 ms |
29520 KB |
Output is correct |
4 |
Correct |
5 ms |
29520 KB |
Output is correct |
5 |
Correct |
5 ms |
29520 KB |
Output is correct |
6 |
Correct |
5 ms |
29520 KB |
Output is correct |
7 |
Correct |
7 ms |
29648 KB |
Output is correct |
8 |
Correct |
6 ms |
29520 KB |
Output is correct |
9 |
Correct |
6 ms |
29696 KB |
Output is correct |
10 |
Correct |
6 ms |
29520 KB |
Output is correct |
11 |
Correct |
8 ms |
29776 KB |
Output is correct |
12 |
Correct |
8 ms |
29876 KB |
Output is correct |
13 |
Correct |
8 ms |
29776 KB |
Output is correct |
14 |
Correct |
10 ms |
30032 KB |
Output is correct |
15 |
Correct |
9 ms |
30032 KB |
Output is correct |
16 |
Correct |
8 ms |
29920 KB |
Output is correct |
17 |
Correct |
10 ms |
30032 KB |
Output is correct |
18 |
Correct |
8 ms |
30032 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1072 ms |
141336 KB |
Output is correct |
2 |
Correct |
1063 ms |
141488 KB |
Output is correct |
3 |
Correct |
1061 ms |
142140 KB |
Output is correct |
4 |
Correct |
1059 ms |
142192 KB |
Output is correct |
5 |
Correct |
843 ms |
119348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
73 ms |
43008 KB |
Output is correct |
2 |
Correct |
69 ms |
43116 KB |
Output is correct |
3 |
Correct |
63 ms |
36952 KB |
Output is correct |
4 |
Correct |
64 ms |
36788 KB |
Output is correct |
5 |
Correct |
72 ms |
36724 KB |
Output is correct |
6 |
Correct |
55 ms |
38492 KB |
Output is correct |
7 |
Correct |
56 ms |
38608 KB |
Output is correct |
8 |
Correct |
60 ms |
40384 KB |
Output is correct |
9 |
Correct |
33 ms |
36356 KB |
Output is correct |
10 |
Correct |
61 ms |
40384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
29520 KB |
Output is correct |
2 |
Correct |
5 ms |
27496 KB |
Output is correct |
3 |
Correct |
5 ms |
29520 KB |
Output is correct |
4 |
Correct |
5 ms |
29520 KB |
Output is correct |
5 |
Correct |
5 ms |
29520 KB |
Output is correct |
6 |
Correct |
5 ms |
29520 KB |
Output is correct |
7 |
Correct |
7 ms |
29648 KB |
Output is correct |
8 |
Correct |
6 ms |
29520 KB |
Output is correct |
9 |
Correct |
6 ms |
29696 KB |
Output is correct |
10 |
Correct |
6 ms |
29520 KB |
Output is correct |
11 |
Correct |
8 ms |
29776 KB |
Output is correct |
12 |
Correct |
8 ms |
29876 KB |
Output is correct |
13 |
Correct |
8 ms |
29776 KB |
Output is correct |
14 |
Correct |
10 ms |
30032 KB |
Output is correct |
15 |
Correct |
9 ms |
30032 KB |
Output is correct |
16 |
Correct |
8 ms |
29920 KB |
Output is correct |
17 |
Correct |
10 ms |
30032 KB |
Output is correct |
18 |
Correct |
8 ms |
30032 KB |
Output is correct |
19 |
Correct |
166 ms |
54136 KB |
Output is correct |
20 |
Correct |
164 ms |
54168 KB |
Output is correct |
21 |
Correct |
136 ms |
55676 KB |
Output is correct |
22 |
Correct |
136 ms |
55544 KB |
Output is correct |
23 |
Correct |
136 ms |
55488 KB |
Output is correct |
24 |
Correct |
112 ms |
47296 KB |
Output is correct |
25 |
Correct |
112 ms |
47296 KB |
Output is correct |
26 |
Correct |
125 ms |
47124 KB |
Output is correct |
27 |
Correct |
127 ms |
47304 KB |
Output is correct |
28 |
Correct |
128 ms |
47176 KB |
Output is correct |
29 |
Correct |
132 ms |
46868 KB |
Output is correct |
30 |
Correct |
158 ms |
46964 KB |
Output is correct |
31 |
Correct |
144 ms |
47040 KB |
Output is correct |
32 |
Correct |
131 ms |
47048 KB |
Output is correct |
33 |
Correct |
132 ms |
47040 KB |
Output is correct |
34 |
Correct |
107 ms |
50384 KB |
Output is correct |
35 |
Correct |
105 ms |
50368 KB |
Output is correct |
36 |
Correct |
114 ms |
50116 KB |
Output is correct |
37 |
Correct |
124 ms |
50128 KB |
Output is correct |
38 |
Correct |
117 ms |
50196 KB |
Output is correct |
39 |
Correct |
135 ms |
51832 KB |
Output is correct |
40 |
Correct |
96 ms |
47292 KB |
Output is correct |
41 |
Correct |
151 ms |
47044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
29520 KB |
Output is correct |
2 |
Correct |
5 ms |
27496 KB |
Output is correct |
3 |
Correct |
5 ms |
29520 KB |
Output is correct |
4 |
Correct |
5 ms |
29520 KB |
Output is correct |
5 |
Correct |
5 ms |
29520 KB |
Output is correct |
6 |
Correct |
5 ms |
29520 KB |
Output is correct |
7 |
Correct |
7 ms |
29648 KB |
Output is correct |
8 |
Correct |
6 ms |
29520 KB |
Output is correct |
9 |
Correct |
6 ms |
29696 KB |
Output is correct |
10 |
Correct |
6 ms |
29520 KB |
Output is correct |
11 |
Correct |
8 ms |
29776 KB |
Output is correct |
12 |
Correct |
8 ms |
29876 KB |
Output is correct |
13 |
Correct |
8 ms |
29776 KB |
Output is correct |
14 |
Correct |
10 ms |
30032 KB |
Output is correct |
15 |
Correct |
9 ms |
30032 KB |
Output is correct |
16 |
Correct |
8 ms |
29920 KB |
Output is correct |
17 |
Correct |
10 ms |
30032 KB |
Output is correct |
18 |
Correct |
8 ms |
30032 KB |
Output is correct |
19 |
Correct |
1072 ms |
141336 KB |
Output is correct |
20 |
Correct |
1063 ms |
141488 KB |
Output is correct |
21 |
Correct |
1061 ms |
142140 KB |
Output is correct |
22 |
Correct |
1059 ms |
142192 KB |
Output is correct |
23 |
Correct |
843 ms |
119348 KB |
Output is correct |
24 |
Correct |
73 ms |
43008 KB |
Output is correct |
25 |
Correct |
69 ms |
43116 KB |
Output is correct |
26 |
Correct |
63 ms |
36952 KB |
Output is correct |
27 |
Correct |
64 ms |
36788 KB |
Output is correct |
28 |
Correct |
72 ms |
36724 KB |
Output is correct |
29 |
Correct |
55 ms |
38492 KB |
Output is correct |
30 |
Correct |
56 ms |
38608 KB |
Output is correct |
31 |
Correct |
60 ms |
40384 KB |
Output is correct |
32 |
Correct |
33 ms |
36356 KB |
Output is correct |
33 |
Correct |
61 ms |
40384 KB |
Output is correct |
34 |
Correct |
166 ms |
54136 KB |
Output is correct |
35 |
Correct |
164 ms |
54168 KB |
Output is correct |
36 |
Correct |
136 ms |
55676 KB |
Output is correct |
37 |
Correct |
136 ms |
55544 KB |
Output is correct |
38 |
Correct |
136 ms |
55488 KB |
Output is correct |
39 |
Correct |
112 ms |
47296 KB |
Output is correct |
40 |
Correct |
112 ms |
47296 KB |
Output is correct |
41 |
Correct |
125 ms |
47124 KB |
Output is correct |
42 |
Correct |
127 ms |
47304 KB |
Output is correct |
43 |
Correct |
128 ms |
47176 KB |
Output is correct |
44 |
Correct |
132 ms |
46868 KB |
Output is correct |
45 |
Correct |
158 ms |
46964 KB |
Output is correct |
46 |
Correct |
144 ms |
47040 KB |
Output is correct |
47 |
Correct |
131 ms |
47048 KB |
Output is correct |
48 |
Correct |
132 ms |
47040 KB |
Output is correct |
49 |
Correct |
107 ms |
50384 KB |
Output is correct |
50 |
Correct |
105 ms |
50368 KB |
Output is correct |
51 |
Correct |
114 ms |
50116 KB |
Output is correct |
52 |
Correct |
124 ms |
50128 KB |
Output is correct |
53 |
Correct |
117 ms |
50196 KB |
Output is correct |
54 |
Correct |
135 ms |
51832 KB |
Output is correct |
55 |
Correct |
96 ms |
47292 KB |
Output is correct |
56 |
Correct |
151 ms |
47044 KB |
Output is correct |
57 |
Correct |
1062 ms |
142176 KB |
Output is correct |
58 |
Correct |
1027 ms |
142332 KB |
Output is correct |
59 |
Correct |
953 ms |
143044 KB |
Output is correct |
60 |
Correct |
1008 ms |
143108 KB |
Output is correct |
61 |
Correct |
930 ms |
143020 KB |
Output is correct |
62 |
Correct |
873 ms |
142880 KB |
Output is correct |
63 |
Correct |
560 ms |
119152 KB |
Output is correct |
64 |
Correct |
607 ms |
119144 KB |
Output is correct |
65 |
Correct |
837 ms |
121032 KB |
Output is correct |
66 |
Correct |
796 ms |
120908 KB |
Output is correct |
67 |
Correct |
822 ms |
120752 KB |
Output is correct |
68 |
Correct |
853 ms |
119988 KB |
Output is correct |
69 |
Correct |
884 ms |
120036 KB |
Output is correct |
70 |
Correct |
894 ms |
120184 KB |
Output is correct |
71 |
Correct |
896 ms |
120152 KB |
Output is correct |
72 |
Correct |
837 ms |
120128 KB |
Output is correct |
73 |
Correct |
533 ms |
118448 KB |
Output is correct |
74 |
Correct |
561 ms |
119476 KB |
Output is correct |
75 |
Correct |
580 ms |
118520 KB |
Output is correct |
76 |
Correct |
564 ms |
118704 KB |
Output is correct |
77 |
Correct |
565 ms |
118200 KB |
Output is correct |
78 |
Correct |
769 ms |
121008 KB |
Output is correct |
79 |
Correct |
538 ms |
102884 KB |
Output is correct |
80 |
Correct |
780 ms |
114204 KB |
Output is correct |