Submission #993582

# Submission time Handle Problem Language Result Execution time Memory
993582 2024-06-06T05:27:48 Z vivkostov Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
30 / 100
1089 ms 83108 KB
#include<bits/stdc++.h>
#define endl "\n"
using namespace std;
void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
struct cell
{
    long long int l,r,c,in;
    void read()
    {
        cin>>l>>r>>c;
    }
};
bool cmp(cell a1,cell a2)
{
    return a1.r<a2.r;
}
cell b[1000005];
long long int n,m,a[1000005],l,r,c,p[4000005],otg[1000005];
void update(long long int l,long long int r,long long int ql,long long int qr,long long int h,long long int x)
{
    if(l>qr||r<ql)return;
    if(l>=ql&&r<=qr)
    {
        p[h]=max(x,p[h]);
        return;
    }
    long long int m=(l+r)/2;
    update(l,m,ql,qr,h*2,x);
    update(m+1,r,ql,qr,h*2+1,x);
    p[h]=max(max(p[h*2],p[h*2+1]),p[h]);
}
long long int query(long long int l,long long int r,long long int ql,long long int qr,long long int h)
{
    if(l>qr||r<ql)return 0;
    if(l>=ql&&r<=qr)return p[h];
    long long int m=(l+r)/2;
    return max(query(l,m,ql,qr,h*2),query(m+1,r,ql,qr,h*2+1));
}
stack<long long int>s;
stack<long long int>in;
void read()
{
    cin>>n>>m;
    for(long long int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    for(long long int i=1;i<=m;i++)
    {
        b[i].read();
        b[i].in=i;
    }
    sort(b+1,b+m+1,cmp);
    long long int pos=0;
    for(long long int i=1;i<=m;i++)
    {
        for(long long int j=max(pos,b[i].l);j<=b[i].r;j++)
        {
            while(!s.empty()&&s.top()<=a[j])
            {
                s.pop();
                in.pop();
            }
            if(s.empty())
            {
                s.push(a[j]);
                in.push(j);
            }
            else
            {
                update(1,n,in.top(),in.top(),1,a[j]+s.top());
                s.push(a[j]);
                in.push(j);
            }
        }
        if(b[i].c>=query(1,n,b[i].l,b[i].r,1))otg[b[i].in]=1;
        pos=b[i].r;
    }
    for(long long int i=1;i<=m;i++)
    {
        cout<<otg[i]<<endl;
    }
}
int main()
{
    speed();
    read();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1089 ms 82248 KB Output is correct
2 Correct 1048 ms 83108 KB Output is correct
3 Correct 1071 ms 82672 KB Output is correct
4 Correct 1039 ms 83104 KB Output is correct
5 Correct 752 ms 74376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 87 ms 9044 KB Output is correct
2 Correct 82 ms 9180 KB Output is correct
3 Correct 64 ms 6996 KB Output is correct
4 Correct 70 ms 6960 KB Output is correct
5 Correct 65 ms 6992 KB Output is correct
6 Correct 54 ms 6240 KB Output is correct
7 Correct 54 ms 6228 KB Output is correct
8 Correct 65 ms 6740 KB Output is correct
9 Correct 33 ms 5724 KB Output is correct
10 Correct 65 ms 6736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -