#include<iostream>
#include<stack>
#define endl '\n'
#include<vector>
using namespace std;
long long maxi[10000000], a[10000000];
stack< pair<long long,long long> >st;
vector< pair< pair<long long,long long>, long long > >mm[10000000];
bool rez[10000000];
void update(long long le,long long ri,long long node,long long ind,long long val)
{
if(le>node || ri<node)return;
if(le==ri)
{
maxi[ind]=max(maxi[ind],val);return;
}
long long mid=(le+ri)/2;
update(le,mid,node,2*ind,val);
update(mid+1,ri,node,2*ind+1,val);
maxi[ind]=max(maxi[2*ind],maxi[2*ind+1]);
}
long long query(long long le,long long ri,long long l,long long r,long long ind)
{
if(le>r || ri<l)return 0;
if(l<=le && ri<=r)
{
return maxi[ind];
}
long long mid=(le+ri)/2;
long long r1,r2;
r1=query(le,mid,l,r,2*ind);
r2=query(mid+1,ri,l,r,2*ind+1);
return max(r1,r2);
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long i,j,n,m,l,r,k,p;
cin>>n>>m;
for(i=1;i<=n;i++)
{
cin>>a[i];
}
//build(1,n,1);
for(i=1;i<=m;i++)
{
cin>>l>>r>>k;
mm[r].push_back({ {l,k}, i});
//long long res=query(1,n,l,r,1);
//if(res<=k)cout<<1<<endl;
//else cout<<0<<endl;
}
for(i=1;i<=n;i++)
{
while(!st.empty() && st.top().first<=a[i])st.pop();
if(st.empty())
{
}
else
{
update(1,n,st.top().second,1,a[i]+st.top().first);
}
//cout<<a[i]<<endl;
for(j=0;j<mm[i].size();j++)
{
long long ll=mm[i][j].first.first,
k=mm[i][j].first.second,
ind=mm[i][j].second;
rez[ind]=max(rez[ind],query(1,n,ll,i,1)<=k);
}
st.push({a[i],i});
}
for(i=1;i<=m;i++)
{
cout<<rez[i]<<endl;
}
}
/*
5 3
3 5 1 8 2
1 3 6
2 5 3
3 5 10
*/
Compilation message
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:82:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<std::pair<long long int, long long int>, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
82 | for(j=0;j<mm[i].size();j++)
| ~^~~~~~~~~~~~~
sortbooks.cpp:47:29: warning: unused variable 'p' [-Wunused-variable]
47 | long long i,j,n,m,l,r,k,p;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
104 ms |
235136 KB |
Output is correct |
2 |
Correct |
108 ms |
235220 KB |
Output is correct |
3 |
Correct |
106 ms |
235104 KB |
Output is correct |
4 |
Correct |
105 ms |
235176 KB |
Output is correct |
5 |
Correct |
114 ms |
235164 KB |
Output is correct |
6 |
Correct |
126 ms |
235192 KB |
Output is correct |
7 |
Correct |
109 ms |
235104 KB |
Output is correct |
8 |
Correct |
106 ms |
235076 KB |
Output is correct |
9 |
Correct |
104 ms |
235084 KB |
Output is correct |
10 |
Correct |
110 ms |
235076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
104 ms |
235136 KB |
Output is correct |
2 |
Correct |
108 ms |
235220 KB |
Output is correct |
3 |
Correct |
106 ms |
235104 KB |
Output is correct |
4 |
Correct |
105 ms |
235176 KB |
Output is correct |
5 |
Correct |
114 ms |
235164 KB |
Output is correct |
6 |
Correct |
126 ms |
235192 KB |
Output is correct |
7 |
Correct |
109 ms |
235104 KB |
Output is correct |
8 |
Correct |
106 ms |
235076 KB |
Output is correct |
9 |
Correct |
104 ms |
235084 KB |
Output is correct |
10 |
Correct |
110 ms |
235076 KB |
Output is correct |
11 |
Correct |
107 ms |
235312 KB |
Output is correct |
12 |
Correct |
120 ms |
235596 KB |
Output is correct |
13 |
Correct |
110 ms |
235452 KB |
Output is correct |
14 |
Correct |
118 ms |
235616 KB |
Output is correct |
15 |
Correct |
110 ms |
235636 KB |
Output is correct |
16 |
Correct |
105 ms |
235596 KB |
Output is correct |
17 |
Correct |
108 ms |
235604 KB |
Output is correct |
18 |
Correct |
106 ms |
235400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
432 ms |
262148 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
222 ms |
241588 KB |
Output is correct |
2 |
Correct |
186 ms |
243612 KB |
Output is correct |
3 |
Correct |
213 ms |
241476 KB |
Output is correct |
4 |
Correct |
190 ms |
241524 KB |
Output is correct |
5 |
Correct |
172 ms |
241432 KB |
Output is correct |
6 |
Correct |
173 ms |
241392 KB |
Output is correct |
7 |
Correct |
173 ms |
241376 KB |
Output is correct |
8 |
Correct |
172 ms |
241192 KB |
Output is correct |
9 |
Correct |
138 ms |
239592 KB |
Output is correct |
10 |
Correct |
206 ms |
241196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
104 ms |
235136 KB |
Output is correct |
2 |
Correct |
108 ms |
235220 KB |
Output is correct |
3 |
Correct |
106 ms |
235104 KB |
Output is correct |
4 |
Correct |
105 ms |
235176 KB |
Output is correct |
5 |
Correct |
114 ms |
235164 KB |
Output is correct |
6 |
Correct |
126 ms |
235192 KB |
Output is correct |
7 |
Correct |
109 ms |
235104 KB |
Output is correct |
8 |
Correct |
106 ms |
235076 KB |
Output is correct |
9 |
Correct |
104 ms |
235084 KB |
Output is correct |
10 |
Correct |
110 ms |
235076 KB |
Output is correct |
11 |
Correct |
107 ms |
235312 KB |
Output is correct |
12 |
Correct |
120 ms |
235596 KB |
Output is correct |
13 |
Correct |
110 ms |
235452 KB |
Output is correct |
14 |
Correct |
118 ms |
235616 KB |
Output is correct |
15 |
Correct |
110 ms |
235636 KB |
Output is correct |
16 |
Correct |
105 ms |
235596 KB |
Output is correct |
17 |
Correct |
108 ms |
235604 KB |
Output is correct |
18 |
Correct |
106 ms |
235400 KB |
Output is correct |
19 |
Correct |
314 ms |
254484 KB |
Output is correct |
20 |
Correct |
311 ms |
254420 KB |
Output is correct |
21 |
Correct |
351 ms |
254900 KB |
Output is correct |
22 |
Correct |
282 ms |
254916 KB |
Output is correct |
23 |
Correct |
323 ms |
254908 KB |
Output is correct |
24 |
Correct |
249 ms |
250820 KB |
Output is correct |
25 |
Correct |
246 ms |
250832 KB |
Output is correct |
26 |
Correct |
282 ms |
250564 KB |
Output is correct |
27 |
Correct |
265 ms |
250616 KB |
Output is correct |
28 |
Correct |
281 ms |
250452 KB |
Output is correct |
29 |
Correct |
282 ms |
250480 KB |
Output is correct |
30 |
Correct |
290 ms |
250432 KB |
Output is correct |
31 |
Correct |
292 ms |
250488 KB |
Output is correct |
32 |
Correct |
300 ms |
250380 KB |
Output is correct |
33 |
Correct |
280 ms |
250400 KB |
Output is correct |
34 |
Correct |
251 ms |
250172 KB |
Output is correct |
35 |
Correct |
262 ms |
250304 KB |
Output is correct |
36 |
Correct |
251 ms |
250020 KB |
Output is correct |
37 |
Correct |
237 ms |
249960 KB |
Output is correct |
38 |
Correct |
245 ms |
250120 KB |
Output is correct |
39 |
Correct |
263 ms |
249916 KB |
Output is correct |
40 |
Correct |
225 ms |
246828 KB |
Output is correct |
41 |
Correct |
274 ms |
248636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
104 ms |
235136 KB |
Output is correct |
2 |
Correct |
108 ms |
235220 KB |
Output is correct |
3 |
Correct |
106 ms |
235104 KB |
Output is correct |
4 |
Correct |
105 ms |
235176 KB |
Output is correct |
5 |
Correct |
114 ms |
235164 KB |
Output is correct |
6 |
Correct |
126 ms |
235192 KB |
Output is correct |
7 |
Correct |
109 ms |
235104 KB |
Output is correct |
8 |
Correct |
106 ms |
235076 KB |
Output is correct |
9 |
Correct |
104 ms |
235084 KB |
Output is correct |
10 |
Correct |
110 ms |
235076 KB |
Output is correct |
11 |
Correct |
107 ms |
235312 KB |
Output is correct |
12 |
Correct |
120 ms |
235596 KB |
Output is correct |
13 |
Correct |
110 ms |
235452 KB |
Output is correct |
14 |
Correct |
118 ms |
235616 KB |
Output is correct |
15 |
Correct |
110 ms |
235636 KB |
Output is correct |
16 |
Correct |
105 ms |
235596 KB |
Output is correct |
17 |
Correct |
108 ms |
235604 KB |
Output is correct |
18 |
Correct |
106 ms |
235400 KB |
Output is correct |
19 |
Runtime error |
432 ms |
262148 KB |
Execution killed with signal 9 |
20 |
Halted |
0 ms |
0 KB |
- |