# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
798878 | Alkarat | Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) | C++14 | 1459 ms | 66748 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 ll long long
#define f first
#define s second
const int N=1e6+10;
using namespace std;
int n,m,a[N],res[N];
struct query
{
int id,l,r,lim;
bool operator<(const query &x)const
{
return l>x.l;
}
};
int bit[N];
void update(int id,int val)
{
while(id<=n)
{
bit[id]=max(bit[id],val);
id+=id&-id;
}
}
int get(int id)
{
int kq=0;
while(id>0)
{
kq=max(kq,bit[id]);
id-=id&-id;
}
return kq;
}
vector<query>q;
stack<int>st;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
q.resize(m);
for(int i=1; i<=n; i++) cin>>a[i];
for(int i=0; i<=m-1; i++)
{
cin>>q[i].l>>q[i].r>>q[i].lim;
q[i].id=i;
}
sort(q.begin(),q.end());
int now=n+1;
for(auto [id,l,r,lim]:q)
{
while(now>l)
{
now--;
while(st.size()&&a[st.top()]<=a[now])
{
int x=st.top();
update(x,a[now]+a[x]);
st.pop();
}
st.push(now);
}
res[id]=(get(r)<=lim);
}
for(int i=0; i<=m-1; i++) cout<<res[i]<<endl;
}
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... |