Submission #1113483

# Submission time Handle Problem Language Result Execution time Memory
1113483 2024-11-16T16:21:18 Z I_FloPPed21 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
1490 ms 195880 KB
#include <iostream>
#include <vector>
#include <stack>
using namespace std;
int n,q;
const int N=1e6+5;
long long v[N];
long long sum[4*N],lazy[4*N],seg[4*N],adaug[4*N],best[4*N],right_bound[N];
struct hedgehog
{
    long long i,r,k;
};
vector<hedgehog>query[N];
void find_bound()
{
    stack<long long>st;
    for(int i=1; i<=n; i++)
    {
        while(!st.empty()&&v[st.top()]<v[i])
        {
            right_bound[st.top()]=i;
            st.pop();
        }
        st.push(i);
    }
    while(!st.empty())
    {
        right_bound[st.top()]=n+1;
        st.pop();
    }
}
void propaga(int nod)
{
    if(lazy[nod]==0)
        return;

    adaug[nod*2]=lazy[nod];
    adaug[nod*2+1]=lazy[nod];
    lazy[nod*2]=lazy[nod];
    lazy[nod*2+1]=lazy[nod];
    best[nod*2]=(seg[nod*2]+lazy[nod]);
    best[nod*2+1]=(seg[nod*2+1]+lazy[nod]);
    lazy[nod]=0;
}
void update(int nod,int st,int dr,int l,int r,int val)
{
    sum[nod]=seg[nod]+adaug[nod];
    if(l<=st&&dr<=r)
    {
        lazy[nod]=val;
        adaug[nod]=val;
        sum[nod]=seg[nod]+adaug[nod];
        best[nod]=sum[nod];
    }
    else if(l>dr||st>r)
        return;
    else
    {
        int mij=(st+dr)/2;
        propaga(nod);
        update(nod*2,st,mij,l,r,val);
        update(nod*2+1,mij+1,dr,l,r,val);
        best[nod]=max(best[nod*2],best[nod*2+1]);
    }
}
void build(int nod,int st,int dr)
{
    if(st==dr)
    {
        seg[nod]=v[st];
    }
    else
    {
        int mij=(st+dr)/2;
        build(nod*2,st,mij);
        build(nod*2+1,mij+1,dr);
        seg[nod]=max(seg[nod*2],seg[nod*2+1]);
    }
}
int answer(int nod,int st,int dr,int l,int r)
{
    if(st>dr)
        return 0;
    if(l<=st&&dr<=r)
    {
        return best[nod];
    }
    else if(l>dr||st>r)
        return -1;
    else
    {
        propaga(nod);
        int mij=(st+dr)/2;
        return max(answer(nod*2,st,mij,l,r),answer(nod*2+1,mij+1,dr,l,r));
    }
}
void citeste()
{
    cin>>n>>q;
    for(int i=1; i<=n; i++)
        cin>>v[i];
    for(int i=1; i<=q; i++)
    {
        int l,r,k;
        cin>>l>>r>>k;
        query[l].push_back({i,r,k});
    }
}
int afis[N];
void rezolva()
{
    for(int i=n; i>=1; i--)
    {
        int dr=right_bound[i]-1;
        if(i+1<=dr)
        update(1,1,n,i+1,dr,v[i]);
        for (auto [x,y,z]:query[i])
        {
            afis[x]=(answer(1,1,n,i+1,y)<=z);

        }
    }
    for(int i=1; i<=q; i++)
        cout<<afis[i]<<'\n';
}

int main()
{

    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    citeste();
    build(1,1,n);
    find_bound();
    rezolva();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 35152 KB Output is correct
2 Correct 5 ms 31160 KB Output is correct
3 Correct 6 ms 35152 KB Output is correct
4 Correct 6 ms 35284 KB Output is correct
5 Correct 7 ms 35152 KB Output is correct
6 Correct 7 ms 35408 KB Output is correct
7 Correct 7 ms 35408 KB Output is correct
8 Correct 7 ms 33360 KB Output is correct
9 Correct 6 ms 33360 KB Output is correct
10 Incorrect 6 ms 35408 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 35152 KB Output is correct
2 Correct 5 ms 31160 KB Output is correct
3 Correct 6 ms 35152 KB Output is correct
4 Correct 6 ms 35284 KB Output is correct
5 Correct 7 ms 35152 KB Output is correct
6 Correct 7 ms 35408 KB Output is correct
7 Correct 7 ms 35408 KB Output is correct
8 Correct 7 ms 33360 KB Output is correct
9 Correct 6 ms 33360 KB Output is correct
10 Incorrect 6 ms 35408 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1450 ms 162856 KB Output is correct
2 Correct 1405 ms 195564 KB Output is correct
3 Correct 1490 ms 195880 KB Output is correct
4 Correct 1456 ms 195584 KB Output is correct
5 Incorrect 1095 ms 184184 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 105 ms 49224 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 35152 KB Output is correct
2 Correct 5 ms 31160 KB Output is correct
3 Correct 6 ms 35152 KB Output is correct
4 Correct 6 ms 35284 KB Output is correct
5 Correct 7 ms 35152 KB Output is correct
6 Correct 7 ms 35408 KB Output is correct
7 Correct 7 ms 35408 KB Output is correct
8 Correct 7 ms 33360 KB Output is correct
9 Correct 6 ms 33360 KB Output is correct
10 Incorrect 6 ms 35408 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 35152 KB Output is correct
2 Correct 5 ms 31160 KB Output is correct
3 Correct 6 ms 35152 KB Output is correct
4 Correct 6 ms 35284 KB Output is correct
5 Correct 7 ms 35152 KB Output is correct
6 Correct 7 ms 35408 KB Output is correct
7 Correct 7 ms 35408 KB Output is correct
8 Correct 7 ms 33360 KB Output is correct
9 Correct 6 ms 33360 KB Output is correct
10 Incorrect 6 ms 35408 KB Output isn't correct
11 Halted 0 ms 0 KB -