# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
333701 | vipghn2003 | Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) | C++14 | 1186 ms | 75128 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
using namespace std;
const int N=1e6+5;
int n,m,a[N];
struct Query
{
int l,r,k;
}q[N];
vector<int>event[N];
vector<int>val;
int BIT[N];
void update(int x,int val)
{
for(;x<=n;x+=x&-x) BIT[x]=max(BIT[x],val);
}
int get(int x)
{
int res=0;
for(;x>=1;x-=x&-x) res=max(res,BIT[x]);
return res;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin>>n>>m;
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=m;i++)
{
cin>>q[i].l>>q[i].r>>q[i].k;
event[q[i].r].push_back(i);
}
vector<pii>vec;
stack<int>st;
for(int i=1;i<=n;i++)
{
while(!st.empty()&&a[st.top()]<=a[i]) st.pop();
if(!st.empty()) vec.push_back(mp(i,st.top()));
st.push(i);
}
sort(vec.begin(),vec.end());
int j=0;
vector<int>res(m+1);
for(int i=1;i<=n;i++)
{
while(j<vec.size()&&vec[j].fi<=i)
{
update(vec[j].se,a[vec[j].fi]+a[vec[j].se]);
j++;
}
for(auto&id:event[i])
{
int l=q[id].l;
int r=q[id].r;
int k=q[id].k;
if(get(l)<=k) res[id]=1;
else res[id]=0;
}
}
for(int i=1;i<=m;i++) cout<<res[i]<<'\n';
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |