#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 |
51 ms |
47352 KB |
Output is correct |
2 |
Correct |
51 ms |
47352 KB |
Output is correct |
3 |
Correct |
49 ms |
47352 KB |
Output is correct |
4 |
Correct |
48 ms |
47352 KB |
Output is correct |
5 |
Incorrect |
49 ms |
47268 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
51 ms |
47352 KB |
Output is correct |
2 |
Correct |
51 ms |
47352 KB |
Output is correct |
3 |
Correct |
49 ms |
47352 KB |
Output is correct |
4 |
Correct |
48 ms |
47352 KB |
Output is correct |
5 |
Incorrect |
49 ms |
47268 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2131 ms |
107116 KB |
Output is correct |
2 |
Correct |
2153 ms |
107412 KB |
Output is correct |
3 |
Correct |
2170 ms |
107212 KB |
Output is correct |
4 |
Correct |
2151 ms |
107276 KB |
Output is correct |
5 |
Correct |
1819 ms |
87008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
202 ms |
53624 KB |
Output is correct |
2 |
Correct |
181 ms |
53496 KB |
Output is correct |
3 |
Correct |
166 ms |
51456 KB |
Output is correct |
4 |
Correct |
171 ms |
51476 KB |
Output is correct |
5 |
Correct |
171 ms |
51576 KB |
Output is correct |
6 |
Correct |
140 ms |
51192 KB |
Output is correct |
7 |
Correct |
137 ms |
51192 KB |
Output is correct |
8 |
Correct |
157 ms |
51780 KB |
Output is correct |
9 |
Correct |
99 ms |
49332 KB |
Output is correct |
10 |
Correct |
156 ms |
51620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
51 ms |
47352 KB |
Output is correct |
2 |
Correct |
51 ms |
47352 KB |
Output is correct |
3 |
Correct |
49 ms |
47352 KB |
Output is correct |
4 |
Correct |
48 ms |
47352 KB |
Output is correct |
5 |
Incorrect |
49 ms |
47268 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
51 ms |
47352 KB |
Output is correct |
2 |
Correct |
51 ms |
47352 KB |
Output is correct |
3 |
Correct |
49 ms |
47352 KB |
Output is correct |
4 |
Correct |
48 ms |
47352 KB |
Output is correct |
5 |
Incorrect |
49 ms |
47268 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |