Submission #299552

# Submission time Handle Problem Language Result Execution time Memory
299552 2020-09-15T07:24:15 Z gs18115 Archery (IOI09_archery) C++14
13 / 100
1222 ms 11788 KB
#include<iostream>
#include<vector>
#include<algorithm>
#define ep emplace
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
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 mx=200010;
struct seg
{
    struct node
    {
        int sum;
        int mxl;
        node(int v=0):sum(v),mxl(v){}
        node(int sum,int mxl):sum(sum),mxl(mxl){}
        node operator+(const node&x)
        {
            return node(sum+x.sum,max(mxl,sum+x.mxl));
        }
    }t[mx*4];
    void init(int n,int s,int e,vector<int>&v)
    {
        if(s==e)
        {
            t[n]=node(v[s]);
            return;
        }
        int m=s+(e-s)/2;
        init(n*2,s,m,v);
        init(n*2+1,m+1,e,v);
        t[n]=t[n*2]+t[n*2+1];
        return;
    }
    int query(int n,int s,int e,int S,int E,int lft)
    {
        if(s>E||S>e)
            return 0;
        if(S<=s&&e<=E&&t[n].mxl+lft<0)
            return t[n].sum+lft;
        if(s==e)
            return s;
        int m=s+(e-s)/2;
        int lf=query(n*2,s,m,S,E,lft);
        if(lf>0)
            return lf;
        return query(n*2+1,m+1,e,S,E,lf);
    }
}st;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,r;
    cin>>n>>r;
    r=(r-n*2)%n+n*2;
    int s;
    cin>>s;
    vector<int>v(n*2-1);
    for(int&t:v)
    {
        cin>>t;
        t=t>s?1:0;
    }
    vector<int>memo(n+1,inf);
    auto getpos=[&](int start)->int
    {
        if(s==1)
            return 1;
        if(memo[start]!=inf)
            return memo[start];
        vector<int>cnt(n+1,0);
        for(int i=1;i<start;i++)
            cnt[i]=v[i*2-2]+v[i*2-1]-1;
        vector<int>prfs(1,0);
        for(int i=0;i++<n;)
            prfs.eb(prfs.back()+cnt[i]);
        cnt[start]=v[start*2-2];
        for(int i=start;i++<n;)
            cnt[i]=v[i*2-3]+v[i*2-2]-1;
        vector<int>tm(n+1,inf);
        for(int i=0;i++<n;)
        {
            if(cnt[i]<(i==start?1:2))
            {
                tm[1]=i-1;
                break;
            }
        }
        st.init(1,1,n,cnt);
        for(int i=1;i++<n;)
        {
            int fi=st.query(1,1,n,i,n,0);
            if(fi>0)
                tm[i]=fi-i;
            else
            {
                int se=st.query(1,1,n,1,i-1,fi);
                if(se>0)
                {
                    tm[i]=n-i+se;
                    if(se<=tm[1]&&prfs[se]+fi==0)
                        tm[i]++;
                }
            }
        }
        int cur=start,cc=start;
        for(int t=0;t<r;t++)
        {
            if(t>=tm[cc])
                cur--,cc--;
            if(cc==0)
                cc=n;
        }
        return memo[start]=cur;
    };
    {
        int pos=getpos(n);
        while((pos-1)%n!=0)
            pos--;
        int s=1,e=n;
        while(s<e)
        {
            int m=s+(e-s)/2;
            if(getpos(m)<pos)
                s=m+1;
            else
                e=m;
        }
        pos=getpos(s);
        e=n;
        for(int i=s;i++<n;)
            if(memo[i]!=inf&&memo[i]>pos)
                e=min(e,i-1);
        for(int i=s;i++<n;)
            if(memo[i]==pos)
                s=i;
        while(s<e)
        {
            int m=s+(e-s+1)/2;
            if(getpos(m)==pos)
                s=m;
            else
                e=m-1;
        }
        cout<<s<<endl;
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6528 KB Output is correct
2 Correct 5 ms 6656 KB Output is correct
3 Correct 4 ms 6656 KB Output is correct
4 Incorrect 12 ms 6656 KB Output isn't correct
5 Incorrect 4 ms 6528 KB Output isn't correct
6 Incorrect 5 ms 6528 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 6528 KB Output is correct
2 Incorrect 5 ms 6548 KB Output isn't correct
3 Incorrect 8 ms 6656 KB Output isn't correct
4 Incorrect 47 ms 7012 KB Output isn't correct
5 Correct 618 ms 11032 KB Output is correct
6 Correct 5 ms 6528 KB Output is correct
7 Incorrect 6 ms 6656 KB Output isn't correct
8 Incorrect 39 ms 7000 KB Output isn't correct
9 Correct 71 ms 7200 KB Output is correct
10 Incorrect 6 ms 6656 KB Output isn't correct
11 Incorrect 63 ms 7252 KB Output isn't correct
12 Incorrect 10 ms 6656 KB Output isn't correct
13 Incorrect 468 ms 9596 KB Output isn't correct
14 Incorrect 18 ms 6784 KB Output isn't correct
15 Incorrect 133 ms 7416 KB Output isn't correct
16 Incorrect 5 ms 6528 KB Output isn't correct
17 Incorrect 8 ms 6656 KB Output isn't correct
18 Incorrect 13 ms 6656 KB Output isn't correct
19 Incorrect 18 ms 6656 KB Output isn't correct
20 Correct 15 ms 6784 KB Output is correct
21 Incorrect 95 ms 7168 KB Output isn't correct
22 Incorrect 192 ms 7460 KB Output isn't correct
23 Incorrect 1222 ms 11320 KB Output isn't correct
24 Incorrect 5 ms 6528 KB Output isn't correct
25 Incorrect 6 ms 6656 KB Output isn't correct
26 Incorrect 27 ms 6784 KB Output isn't correct
27 Incorrect 65 ms 7204 KB Output isn't correct
28 Incorrect 577 ms 9716 KB Output isn't correct
29 Incorrect 8 ms 6656 KB Output isn't correct
30 Incorrect 21 ms 6784 KB Output isn't correct
31 Incorrect 71 ms 7176 KB Output isn't correct
32 Incorrect 828 ms 11256 KB Output isn't correct
33 Incorrect 5 ms 6656 KB Output isn't correct
34 Incorrect 5 ms 6528 KB Output isn't correct
35 Incorrect 9 ms 6656 KB Output isn't correct
36 Incorrect 11 ms 6656 KB Output isn't correct
37 Incorrect 67 ms 7124 KB Output isn't correct
38 Incorrect 91 ms 7360 KB Output isn't correct
39 Incorrect 5 ms 6656 KB Output isn't correct
40 Incorrect 6 ms 6656 KB Output isn't correct
41 Incorrect 10 ms 6624 KB Output isn't correct
42 Incorrect 10 ms 6656 KB Output isn't correct
43 Incorrect 17 ms 6784 KB Output isn't correct
44 Incorrect 37 ms 7024 KB Output isn't correct
45 Incorrect 80 ms 7176 KB Output isn't correct
46 Incorrect 71 ms 7356 KB Output isn't correct
47 Incorrect 1014 ms 11788 KB Output isn't correct