Submission #200909

# Submission time Handle Problem Language Result Execution time Memory
200909 2020-02-08T13:41:34 Z gs18115 Sushi (JOI16_sushi) C++14
0 / 100
63 ms 3576 KB
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#define ep emplace
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define semicolon ;
#define ryan bear
using namespace std;
typedef long long ll;
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const int inf=1e9+7;
const ll INF=1e18;
const int sz=2;
int n;
int x[400010+sz];
priority_queue<int,vector<int>,less<int> >pq[sz];
priority_queue<int,vector<int>,greater<int> >rn[sz];
inline void init()
{
    for(int i=0;i<n;i++)
        pq[i/sz].ep(x[i]);
    return;
}
inline void app(int g)
{
    if(rn[g].empty())
        return;
    for(int i=g*sz;i<g*sz+sz;i++)
        if(rn[g].top()<x[i])
            rn[g].ep(x[i]),x[i]=rn[g].top(),rn[g].pop();
    while(!rn[g].empty())
        rn[g].pop();
    return;
}
inline void init(int g)
{
    while(!pq[g].empty())
        pq[g].pop();
    for(int i=g*sz;i<g*sz+sz;i++)
        pq[g].ep(x[i]);
    return;
}
inline int solve(int s,int t,int p)
{
    if(t-s<sz)
    {
        for(int i=s;i<t;i++)
            if(p<x[i])
                swap(p,x[i]);
        return p;
    }
    int l=(s+sz-1)/sz;
    int r=t/sz;
    if(s<l*sz)
    {
        app(l-1);
        for(int i=s;i<l*sz;i++)
            if(p<x[i])
                swap(p,x[i]);
        init(l-1);
    }
    for(int i=l;i<r;i++)
    {
        if(p<pq[i].top())
        {
            int prv=p;
            p=pq[i].top();
            pq[i].pop();
            pq[i].ep(prv);
            rn[i].ep(prv);
        }
    }
    if(r*sz<t)
    {
        app(r);
        for(int i=r*sz;i<t;i++)
            if(p<x[i])
                swap(p,x[i]);
        init(r);
    }
    return p;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int q;
    cin>>n>>q;
    for(int i=0;i<n;i++)
        cin>>x[i];
    while(n%sz!=0)
        x[n++]=-1;
    init();
    while(q-->0)
    {
        int s,t,p;
        cin>>s>>t>>p;
        if(s>t)
            cout<<solve(0,t,solve(s-1,n,p))<<'\n';
        else
            cout<<solve(s-1,t,p)<<'\n';
    }
    cout.flush();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 63 ms 3576 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -