#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define MAXN 1000006
typedef long long ll;
using namespace std;
int n,m;
vector<int> s;
vector<pair<pair<int,int>,int> > query[MAXN];
vector<int> gube[MAXN];
int niz[MAXN],res[MAXN];
int tr[MAXN];
int seg[4*MAXN];
void dodaj(int l,int d,int p,int k,int x){
if(l==d){
seg[k]=x;
return;
}
int mid=(l+d)/2;
if(p<=mid)dodaj(l,mid,p,k+k,x);
else dodaj(mid+1,d,p,k+k+1,x);
seg[k]=max(seg[k+k],seg[k+k+1]);
}
int dobij(int l,int d,int tl,int td,int k){
if(l>td || d<tl)return 0;
if(l>=tl && d<=td)return seg[k];
int mid=(l+d)/2;
return max(dobij(l,mid,tl,td,k+k),
dobij(mid+1,d,tl,td,k+k+1));
}
void izgradi(int l,int d,int k){
if(l==d){
seg[k]=tr[l];
return;
}
int mid=(l+d)/2;
izgradi(l,mid,k+k);
izgradi(mid+1,d,k+k+1);
seg[k]=max(seg[k+k],seg[k+k+1]);
}
int main()
{
scanf("%d %d", &n, &m);
for(int i=1;i<=n;i++){
scanf("%d",niz+i);
while(!s.empty() && niz[s.back()] <= niz[i])s.pop_back();
if(s.empty())s.pb(i);
else{
int o=s.back();
gube[o].pb(i);
tr[i]=niz[i]+niz[o];
s.push_back(i);
}
}
izgradi(1,n,1);
for(int i=1;i<=m;i++){
int t1,t2,t3;
scanf("%d %d %d", &t1, &t2, &t3);
query[t1].pb(mp(mp(t2,t3), i));
}
for(int i=1;i<=m;i++){
for(auto x:query[i]){
res[x.S]=(dobij(1,n,i,x.F.F,1)<=x.F.S);
}
for(auto x:gube[i])
dodaj(1,n,x,1,0);
}
for(int i=1;i<=m;i++)printf("%d\n",res[i]);
return 0;
}
Compilation message
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:54:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &n, &m);
~~~~~^~~~~~~~~~~~~~~~~
sortbooks.cpp:56:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",niz+i);
~~~~~^~~~~~~~~~~~
sortbooks.cpp:69:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d", &t1, &t2, &t3);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
47352 KB |
Output is correct |
2 |
Correct |
49 ms |
47352 KB |
Output is correct |
3 |
Correct |
48 ms |
47436 KB |
Output is correct |
4 |
Correct |
48 ms |
47352 KB |
Output is correct |
5 |
Incorrect |
51 ms |
47352 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
47352 KB |
Output is correct |
2 |
Correct |
49 ms |
47352 KB |
Output is correct |
3 |
Correct |
48 ms |
47436 KB |
Output is correct |
4 |
Correct |
48 ms |
47352 KB |
Output is correct |
5 |
Incorrect |
51 ms |
47352 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2136 ms |
114352 KB |
Output is correct |
2 |
Correct |
2115 ms |
110832 KB |
Output is correct |
3 |
Correct |
2164 ms |
140116 KB |
Output is correct |
4 |
Correct |
2157 ms |
139980 KB |
Output is correct |
5 |
Correct |
1910 ms |
120136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
210 ms |
55544 KB |
Output is correct |
2 |
Correct |
185 ms |
55300 KB |
Output is correct |
3 |
Correct |
166 ms |
53368 KB |
Output is correct |
4 |
Correct |
174 ms |
53576 KB |
Output is correct |
5 |
Correct |
177 ms |
53592 KB |
Output is correct |
6 |
Correct |
134 ms |
52856 KB |
Output is correct |
7 |
Correct |
134 ms |
52984 KB |
Output is correct |
8 |
Correct |
155 ms |
53468 KB |
Output is correct |
9 |
Correct |
101 ms |
50864 KB |
Output is correct |
10 |
Correct |
157 ms |
53356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
47352 KB |
Output is correct |
2 |
Correct |
49 ms |
47352 KB |
Output is correct |
3 |
Correct |
48 ms |
47436 KB |
Output is correct |
4 |
Correct |
48 ms |
47352 KB |
Output is correct |
5 |
Incorrect |
51 ms |
47352 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
47352 KB |
Output is correct |
2 |
Correct |
49 ms |
47352 KB |
Output is correct |
3 |
Correct |
48 ms |
47436 KB |
Output is correct |
4 |
Correct |
48 ms |
47352 KB |
Output is correct |
5 |
Incorrect |
51 ms |
47352 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |