Submission #299536

# Submission time Handle Problem Language Result Execution time Memory
299536 2020-09-15T07:03:07 Z gs18115 Archery (IOI09_archery) C++14
94 / 100
1685 ms 12652 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;
    }
    auto getpos=[&](int start)->int
    {
        if(s==1)
            return 1;
        vector<int>cnt(n+1,0);
        for(int i=1;i<start;i++)
            cnt[i]=v[i*2-2]+v[i*2-1]-1;
        cnt[start]=v[start*2-2]-1;
        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;
                continue;
            }
            int se=st.query(1,1,n,1,i-1,fi+1);
            if(se>0)
            {
                tm[i]=n-i+se;
                if(se<=tm[1])
                    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 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;
        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 5 ms 6528 KB Output is correct
2 Correct 6 ms 6656 KB Output is correct
3 Correct 5 ms 6528 KB Output is correct
4 Correct 13 ms 6656 KB Output is correct
5 Correct 5 ms 6656 KB Output is correct
6 Correct 5 ms 6656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6656 KB Output is correct
2 Correct 5 ms 6656 KB Output is correct
3 Correct 8 ms 6656 KB Output is correct
4 Correct 76 ms 7160 KB Output is correct
5 Correct 1218 ms 11600 KB Output is correct
6 Correct 5 ms 6560 KB Output is correct
7 Incorrect 7 ms 6656 KB Output isn't correct
8 Incorrect 66 ms 7180 KB Output isn't correct
9 Correct 117 ms 7212 KB Output is correct
10 Incorrect 7 ms 6656 KB Output isn't correct
11 Correct 104 ms 7484 KB Output is correct
12 Correct 15 ms 6656 KB Output is correct
13 Correct 862 ms 10184 KB Output is correct
14 Correct 21 ms 6656 KB Output is correct
15 Correct 173 ms 7632 KB Output is correct
16 Correct 5 ms 6528 KB Output is correct
17 Correct 8 ms 6656 KB Output is correct
18 Correct 12 ms 6656 KB Output is correct
19 Correct 18 ms 6656 KB Output is correct
20 Correct 23 ms 6656 KB Output is correct
21 Correct 105 ms 7480 KB Output is correct
22 Correct 199 ms 7620 KB Output is correct
23 Correct 1312 ms 12024 KB Output is correct
24 Correct 5 ms 6656 KB Output is correct
25 Correct 8 ms 6656 KB Output is correct
26 Correct 30 ms 6656 KB Output is correct
27 Correct 126 ms 7412 KB Output is correct
28 Correct 975 ms 10464 KB Output is correct
29 Correct 10 ms 6784 KB Output is correct
30 Correct 33 ms 6656 KB Output is correct
31 Correct 119 ms 7192 KB Output is correct
32 Correct 1509 ms 11832 KB Output is correct
33 Correct 6 ms 6656 KB Output is correct
34 Correct 5 ms 6656 KB Output is correct
35 Correct 13 ms 6656 KB Output is correct
36 Correct 15 ms 6656 KB Output is correct
37 Correct 104 ms 7116 KB Output is correct
38 Correct 141 ms 7356 KB Output is correct
39 Correct 5 ms 6528 KB Output is correct
40 Correct 8 ms 6656 KB Output is correct
41 Correct 12 ms 6656 KB Output is correct
42 Correct 14 ms 6656 KB Output is correct
43 Correct 26 ms 6656 KB Output is correct
44 Correct 59 ms 6912 KB Output is correct
45 Correct 172 ms 7184 KB Output is correct
46 Correct 108 ms 7240 KB Output is correct
47 Correct 1685 ms 12652 KB Output is correct