#include<iostream>
#include<stack>
#define endl '\n'
#include<vector>
using namespace std;
long long maxi[5000000], a[5000000];
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,long long k)
{
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,k);
if(r1>k)return r1;
r2=query(mid+1,ri,l,r,2*ind+1,k);
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];
}
for(i=1;i<=m;i++)
{
cin>>l>>r>>k;
mm[r].push_back({ {l,k}, i});
}
for(i=1;i<=n;i++)
{
while(!st.empty() && st.top().first<=a[i])st.pop();
if(!st.empty())
{
update(1,n,st.top().second,1,a[i]+st.top().first);
}
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)<=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:71: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]
71 | for(j=0;j<mm[i].size();j++)
| ~^~~~~~~~~~~~~
sortbooks.cpp:48:29: warning: unused variable 'p' [-Wunused-variable]
48 | long long i,j,n,m,l,r,k,p;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
116 ms |
235040 KB |
Output is correct |
2 |
Correct |
112 ms |
235056 KB |
Output is correct |
3 |
Correct |
115 ms |
235152 KB |
Output is correct |
4 |
Correct |
114 ms |
235076 KB |
Output is correct |
5 |
Correct |
123 ms |
235260 KB |
Output is correct |
6 |
Correct |
113 ms |
235184 KB |
Output is correct |
7 |
Correct |
116 ms |
235076 KB |
Output is correct |
8 |
Correct |
117 ms |
235116 KB |
Output is correct |
9 |
Correct |
115 ms |
235080 KB |
Output is correct |
10 |
Correct |
113 ms |
235240 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
116 ms |
235040 KB |
Output is correct |
2 |
Correct |
112 ms |
235056 KB |
Output is correct |
3 |
Correct |
115 ms |
235152 KB |
Output is correct |
4 |
Correct |
114 ms |
235076 KB |
Output is correct |
5 |
Correct |
123 ms |
235260 KB |
Output is correct |
6 |
Correct |
113 ms |
235184 KB |
Output is correct |
7 |
Correct |
116 ms |
235076 KB |
Output is correct |
8 |
Correct |
117 ms |
235116 KB |
Output is correct |
9 |
Correct |
115 ms |
235080 KB |
Output is correct |
10 |
Correct |
113 ms |
235240 KB |
Output is correct |
11 |
Correct |
114 ms |
235332 KB |
Output is correct |
12 |
Correct |
115 ms |
235480 KB |
Output is correct |
13 |
Correct |
117 ms |
235496 KB |
Output is correct |
14 |
Correct |
118 ms |
235612 KB |
Output is correct |
15 |
Correct |
119 ms |
235528 KB |
Output is correct |
16 |
Correct |
126 ms |
235416 KB |
Output is correct |
17 |
Correct |
121 ms |
235388 KB |
Output is correct |
18 |
Correct |
144 ms |
235396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
430 ms |
262148 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
206 ms |
241708 KB |
Output is correct |
2 |
Correct |
195 ms |
242032 KB |
Output is correct |
3 |
Correct |
184 ms |
239684 KB |
Output is correct |
4 |
Correct |
193 ms |
239684 KB |
Output is correct |
5 |
Correct |
193 ms |
239684 KB |
Output is correct |
6 |
Correct |
161 ms |
239712 KB |
Output is correct |
7 |
Correct |
161 ms |
239812 KB |
Output is correct |
8 |
Correct |
169 ms |
239756 KB |
Output is correct |
9 |
Correct |
143 ms |
238544 KB |
Output is correct |
10 |
Correct |
163 ms |
239756 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
116 ms |
235040 KB |
Output is correct |
2 |
Correct |
112 ms |
235056 KB |
Output is correct |
3 |
Correct |
115 ms |
235152 KB |
Output is correct |
4 |
Correct |
114 ms |
235076 KB |
Output is correct |
5 |
Correct |
123 ms |
235260 KB |
Output is correct |
6 |
Correct |
113 ms |
235184 KB |
Output is correct |
7 |
Correct |
116 ms |
235076 KB |
Output is correct |
8 |
Correct |
117 ms |
235116 KB |
Output is correct |
9 |
Correct |
115 ms |
235080 KB |
Output is correct |
10 |
Correct |
113 ms |
235240 KB |
Output is correct |
11 |
Correct |
114 ms |
235332 KB |
Output is correct |
12 |
Correct |
115 ms |
235480 KB |
Output is correct |
13 |
Correct |
117 ms |
235496 KB |
Output is correct |
14 |
Correct |
118 ms |
235612 KB |
Output is correct |
15 |
Correct |
119 ms |
235528 KB |
Output is correct |
16 |
Correct |
126 ms |
235416 KB |
Output is correct |
17 |
Correct |
121 ms |
235388 KB |
Output is correct |
18 |
Correct |
144 ms |
235396 KB |
Output is correct |
19 |
Correct |
295 ms |
248176 KB |
Output is correct |
20 |
Correct |
301 ms |
248116 KB |
Output is correct |
21 |
Correct |
269 ms |
248704 KB |
Output is correct |
22 |
Correct |
286 ms |
248900 KB |
Output is correct |
23 |
Correct |
268 ms |
248736 KB |
Output is correct |
24 |
Correct |
264 ms |
244752 KB |
Output is correct |
25 |
Correct |
249 ms |
244784 KB |
Output is correct |
26 |
Correct |
273 ms |
244352 KB |
Output is correct |
27 |
Correct |
283 ms |
244416 KB |
Output is correct |
28 |
Correct |
268 ms |
244232 KB |
Output is correct |
29 |
Correct |
286 ms |
244004 KB |
Output is correct |
30 |
Correct |
280 ms |
244020 KB |
Output is correct |
31 |
Correct |
295 ms |
244072 KB |
Output is correct |
32 |
Correct |
294 ms |
243984 KB |
Output is correct |
33 |
Correct |
297 ms |
244072 KB |
Output is correct |
34 |
Correct |
234 ms |
244164 KB |
Output is correct |
35 |
Correct |
236 ms |
244280 KB |
Output is correct |
36 |
Correct |
234 ms |
244268 KB |
Output is correct |
37 |
Correct |
240 ms |
244172 KB |
Output is correct |
38 |
Correct |
247 ms |
244228 KB |
Output is correct |
39 |
Correct |
250 ms |
244984 KB |
Output is correct |
40 |
Correct |
256 ms |
242556 KB |
Output is correct |
41 |
Correct |
244 ms |
244272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
116 ms |
235040 KB |
Output is correct |
2 |
Correct |
112 ms |
235056 KB |
Output is correct |
3 |
Correct |
115 ms |
235152 KB |
Output is correct |
4 |
Correct |
114 ms |
235076 KB |
Output is correct |
5 |
Correct |
123 ms |
235260 KB |
Output is correct |
6 |
Correct |
113 ms |
235184 KB |
Output is correct |
7 |
Correct |
116 ms |
235076 KB |
Output is correct |
8 |
Correct |
117 ms |
235116 KB |
Output is correct |
9 |
Correct |
115 ms |
235080 KB |
Output is correct |
10 |
Correct |
113 ms |
235240 KB |
Output is correct |
11 |
Correct |
114 ms |
235332 KB |
Output is correct |
12 |
Correct |
115 ms |
235480 KB |
Output is correct |
13 |
Correct |
117 ms |
235496 KB |
Output is correct |
14 |
Correct |
118 ms |
235612 KB |
Output is correct |
15 |
Correct |
119 ms |
235528 KB |
Output is correct |
16 |
Correct |
126 ms |
235416 KB |
Output is correct |
17 |
Correct |
121 ms |
235388 KB |
Output is correct |
18 |
Correct |
144 ms |
235396 KB |
Output is correct |
19 |
Runtime error |
430 ms |
262148 KB |
Execution killed with signal 9 |
20 |
Halted |
0 ms |
0 KB |
- |