Submission #200912

# Submission time Handle Problem Language Result Execution time Memory
200912 2020-02-08T13:47:15 Z gs18115 Sushi (JOI16_sushi) C++14
100 / 100
5367 ms 80892 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=642;
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(s/sz==t/sz)
    {
        app(s/sz);
        for(int i=s;i<t;i++)
            if(p<x[i])
                swap(p,x[i]);
        init(s/sz);
        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 Correct 205 ms 632 KB Output is correct
2 Correct 211 ms 504 KB Output is correct
3 Correct 211 ms 376 KB Output is correct
4 Correct 204 ms 376 KB Output is correct
5 Correct 207 ms 376 KB Output is correct
6 Correct 223 ms 376 KB Output is correct
7 Correct 79 ms 380 KB Output is correct
8 Correct 79 ms 376 KB Output is correct
9 Correct 207 ms 376 KB Output is correct
10 Correct 203 ms 376 KB Output is correct
11 Correct 199 ms 376 KB Output is correct
12 Correct 204 ms 504 KB Output is correct
13 Correct 209 ms 376 KB Output is correct
14 Correct 226 ms 464 KB Output is correct
15 Correct 220 ms 504 KB Output is correct
16 Correct 137 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 380 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3232 ms 77856 KB Output is correct
2 Correct 3240 ms 78316 KB Output is correct
3 Correct 406 ms 5112 KB Output is correct
4 Correct 3178 ms 78584 KB Output is correct
5 Correct 2899 ms 77620 KB Output is correct
6 Correct 3466 ms 77576 KB Output is correct
7 Correct 3430 ms 77800 KB Output is correct
8 Correct 3470 ms 77652 KB Output is correct
9 Correct 421 ms 5240 KB Output is correct
10 Correct 2789 ms 73488 KB Output is correct
11 Correct 389 ms 4984 KB Output is correct
12 Correct 2751 ms 74360 KB Output is correct
13 Correct 3159 ms 78852 KB Output is correct
14 Correct 3217 ms 78392 KB Output is correct
15 Correct 414 ms 4984 KB Output is correct
16 Correct 3170 ms 78584 KB Output is correct
17 Correct 2880 ms 77692 KB Output is correct
18 Correct 3432 ms 77816 KB Output is correct
19 Correct 3388 ms 77644 KB Output is correct
20 Correct 3402 ms 77528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 205 ms 632 KB Output is correct
2 Correct 211 ms 504 KB Output is correct
3 Correct 211 ms 376 KB Output is correct
4 Correct 204 ms 376 KB Output is correct
5 Correct 207 ms 376 KB Output is correct
6 Correct 223 ms 376 KB Output is correct
7 Correct 79 ms 380 KB Output is correct
8 Correct 79 ms 376 KB Output is correct
9 Correct 207 ms 376 KB Output is correct
10 Correct 203 ms 376 KB Output is correct
11 Correct 199 ms 376 KB Output is correct
12 Correct 204 ms 504 KB Output is correct
13 Correct 209 ms 376 KB Output is correct
14 Correct 226 ms 464 KB Output is correct
15 Correct 220 ms 504 KB Output is correct
16 Correct 137 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 380 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 3232 ms 77856 KB Output is correct
24 Correct 3240 ms 78316 KB Output is correct
25 Correct 406 ms 5112 KB Output is correct
26 Correct 3178 ms 78584 KB Output is correct
27 Correct 2899 ms 77620 KB Output is correct
28 Correct 3466 ms 77576 KB Output is correct
29 Correct 3430 ms 77800 KB Output is correct
30 Correct 3470 ms 77652 KB Output is correct
31 Correct 421 ms 5240 KB Output is correct
32 Correct 2789 ms 73488 KB Output is correct
33 Correct 389 ms 4984 KB Output is correct
34 Correct 2751 ms 74360 KB Output is correct
35 Correct 3159 ms 78852 KB Output is correct
36 Correct 3217 ms 78392 KB Output is correct
37 Correct 414 ms 4984 KB Output is correct
38 Correct 3170 ms 78584 KB Output is correct
39 Correct 2880 ms 77692 KB Output is correct
40 Correct 3432 ms 77816 KB Output is correct
41 Correct 3388 ms 77644 KB Output is correct
42 Correct 3402 ms 77528 KB Output is correct
43 Correct 3189 ms 6432 KB Output is correct
44 Correct 3326 ms 9800 KB Output is correct
45 Correct 1460 ms 5880 KB Output is correct
46 Correct 3140 ms 9976 KB Output is correct
47 Correct 3121 ms 10096 KB Output is correct
48 Correct 4912 ms 11640 KB Output is correct
49 Correct 5208 ms 11568 KB Output is correct
50 Correct 5176 ms 11608 KB Output is correct
51 Correct 5209 ms 11708 KB Output is correct
52 Correct 3194 ms 10676 KB Output is correct
53 Correct 3143 ms 10488 KB Output is correct
54 Correct 4801 ms 14200 KB Output is correct
55 Correct 5128 ms 14104 KB Output is correct
56 Correct 5114 ms 14132 KB Output is correct
57 Correct 5108 ms 13912 KB Output is correct
58 Correct 3600 ms 14312 KB Output is correct
59 Correct 4030 ms 14328 KB Output is correct
60 Correct 4430 ms 80632 KB Output is correct
61 Correct 5331 ms 80884 KB Output is correct
62 Correct 5367 ms 80892 KB Output is correct
63 Correct 5309 ms 80888 KB Output is correct
64 Correct 989 ms 6008 KB Output is correct
65 Correct 3093 ms 42684 KB Output is correct
66 Correct 3104 ms 43268 KB Output is correct
67 Correct 3731 ms 48588 KB Output is correct
68 Correct 4334 ms 48900 KB Output is correct
69 Correct 4365 ms 48892 KB Output is correct
70 Correct 4290 ms 48720 KB Output is correct