Submission #868540

# Submission time Handle Problem Language Result Execution time Memory
868540 2023-10-31T17:49:10 Z alexdd Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
592 ms 65452 KB
#include<bits/stdc++.h>
using namespace std;
int n,m;
int a[1000005];
int tole[1000005];
int rez[1000005];
deque<int> dq;
vector<pair<pair<int,int>,int>> qrys[1000005];
int aib[10000005];
int qry(int poz)
{
    int aux=0;
    for(int i=poz;i<=n;i+=(i&(-i)))
        aux=max(aux,aib[i]);
    return aux;
}
void upd(int poz, int newv)
{
    for(int i=poz;i>0;i-=(i&(-i)))
        aib[poz]=max(aib[poz],newv);
}
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        while(!dq.empty() && a[dq.back()]<=a[i])
            dq.pop_back();
        if(dq.empty())
            tole[i]=0;
        else
            tole[i]=dq.back();
        dq.push_back(i);
    }
    int ql,qr,k;
    for(int i=1;i<=m;i++)
    {
        cin>>ql>>qr>>k;
        qrys[qr].push_back({{ql,k},i});
    }
    for(int i=1;i<=n;i++)
    {
        if(tole[i]>0) upd(tole[i],a[i]+tole[i]);
        for(auto x:qrys[i])
        {
            int le=x.first.first;
            int mxm=qry(le);
            /*for(int j=le;j<=i;j++)
                if(tole[j]>=le)
                    mxm=max(mxm, a[j]+a[tole[j]]);*/
            if(mxm<=x.first.second)
                rez[x.second]=1;
            else
                rez[x.second]=0;
        }
    }
    for(int i=1;i<=m;i++)
        cout<<rez[i]<<"\n";
    return 0;
}
/**
tole[i] = prima pozitie din stanga lui i > a[i]
max(a[j] + a[tole[j]]) pt j = le..ri && tole[j] >= le

*/
# Verdict Execution time Memory Grader output
1 Correct 6 ms 31320 KB Output is correct
2 Correct 6 ms 31068 KB Output is correct
3 Incorrect 6 ms 31068 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 31320 KB Output is correct
2 Correct 6 ms 31068 KB Output is correct
3 Incorrect 6 ms 31068 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 592 ms 65452 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 44 ms 34028 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 31320 KB Output is correct
2 Correct 6 ms 31068 KB Output is correct
3 Incorrect 6 ms 31068 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 31320 KB Output is correct
2 Correct 6 ms 31068 KB Output is correct
3 Incorrect 6 ms 31068 KB Output isn't correct
4 Halted 0 ms 0 KB -