Submission #73708

# Submission time Handle Problem Language Result Execution time Memory
73708 2018-08-28T17:53:41 Z MKopchev Ancient Books (IOI17_books) C++14
50 / 100
1537 ms 36964 KB
#include<bits/stdc++.h>
using namespace std;
const int nmax=1e6+42;
int in[nmax],out[nmax];
int tree_in[nmax*4],tree_out[nmax*4];
void update_in(int node)
{
    tree_in[node*2]+=tree_in[node];
    tree_in[node*2+1]+=tree_in[node];
    tree_in[node]=0;
}
void update_in(int node,int l,int r,int lq,int rq)
{
    //cout<<l<<" "<<r<<" "<<lq<<" "<<rq<<endl;
    if(l==lq&&r==rq)
    {
        tree_in[node]++;
        return;
    }
    update_in(node);
    int av=(l+r)/2;
    if(lq<=av)update_in(node*2,l,av,lq,min(av,rq));
    if(av<rq)update_in(node*2+1,av+1,r,max(av+1,lq),rq);
}
void go_in(int node,int l,int r)
{
    if(l==r)
    {
        in[l]=tree_in[node];
        return;
    }
    update_in(node);
    int av=(l+r)/2;
    go_in(node*2,l,av);
    go_in(node*2+1,av+1,r);
}



void update_out(int node)
{
    tree_out[node*2]+=tree_out[node];
    tree_out[node*2+1]+=tree_out[node];
    tree_out[node]=0;
}
void update_out(int node,int l,int r,int lq,int rq)
{
    //cout<<l<<" "<<r<<" "<<lq<<" "<<rq<<endl;
    if(l==lq&&r==rq)
    {
        tree_out[node]++;
        return;
    }
    update_out(node);
    int av=(l+r)/2;
    if(lq<=av)update_out(node*2,l,av,lq,min(av,rq));
    if(av<rq)update_out(node*2+1,av+1,r,max(av+1,lq),rq);
}
void go_out(int node,int l,int r)
{
    if(l==r)
    {
        out[l]=tree_out[node];
        return;
    }
    update_out(node);
    int av=(l+r)/2;
    go_out(node*2,l,av);
    go_out(node*2+1,av+1,r);
}

long long minimum_walk(vector<int> p, int s)
{
    int n=p.size();
    while(n-1>s&&p[n-1]==n-1){p.pop_back();n--;}
    vector<int> help={};
    int where=0;
    for(where=0;where<s;where++)
    {
        if(p[where]!=where)break;
    }
    for(int i=where;i<n;i++)
        help.push_back(p[i]-where);
    p=help;
    n=p.size();

    if(n==0)return 0;

    /*
    help=p;
    sort(help.begin(),help.end());
    for(int i=0;i<n;i++)
        assert(help[i]==i);
    */
    for(int i=0;i<n;i++)
        if(i!=p[i])
        {
            if(i<p[i])
            {
            update_in(1,0,n-1,i+1,p[i]);
            update_out(1,0,n-1,i,p[i]-1);
            /*
            for(int j=i;j<p[i];j++)
                out[j]++,in[j+1]++;
            */
            }
            else
            {
            update_in(1,0,n-1,p[i],i-1);
            update_out(1,0,n-1,p[i]+1,i);
            /*
            for(int j=i;j>p[i];j--)
                out[j]++,in[j-1]++;
            */
            }
        }
    go_in(1,0,n-1);
    go_out(1,0,n-1);
    /*
    for(int i=0;i<n;i++)
        cout<<in[i]<<" "<<out[i]<<endl;
    */
      int maxi=0;
      for(int i=0;i<n;i++)
      {
            maxi=max(maxi,p[i]);
            if(i==maxi)
            {
                if(i!=n-1)
                {
                    in[i]++;
                    out[i]++;
                    in[i+1]++;
                    out[i+1]++;
                }
                maxi=0;
            }
      }
      for(int i=1;i<n;i++)
      {
            if(in[i-1]<out[i-1])
            {
                assert(0==1);
                out[i]+=out[i-1]-in[i-1];
                in[i-1]=out[i-1];
            }
            else if(in[i-1]>out[i-1])
            {
                assert(0==1);
                in[i]+=in[i-1]-out[i-1];
                out[i-1]=in[i-1];
            }
      }
      assert(in[n-1]==out[n-1]);
      long long ans=0;
      for(int i=0;i<n;i++)
      {
            ans=ans+in[i]+out[i];
      }
      return ans/2;
}
/*
int main()
{
//cout<<minimum_walk({0,2,1,3},2)<<endl;
//cout<<minimum_walk({0, 2, 3, 1}, 0)<<endl;
cout<<minimum_walk({1,0,3,2}, 0)<<endl;
//cout<<minimum_walk({2,3,0,1}, 0)<<endl;
return 0;
}
*/
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 444 KB Output is correct
3 Correct 3 ms 624 KB Output is correct
4 Correct 2 ms 624 KB Output is correct
5 Correct 2 ms 624 KB Output is correct
6 Correct 2 ms 624 KB Output is correct
7 Correct 3 ms 624 KB Output is correct
8 Correct 2 ms 624 KB Output is correct
9 Correct 3 ms 624 KB Output is correct
10 Correct 2 ms 624 KB Output is correct
11 Correct 2 ms 724 KB Output is correct
12 Correct 3 ms 724 KB Output is correct
13 Correct 4 ms 724 KB Output is correct
14 Correct 3 ms 724 KB Output is correct
15 Correct 2 ms 724 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 3 ms 724 KB Output is correct
18 Correct 3 ms 728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 444 KB Output is correct
3 Correct 3 ms 624 KB Output is correct
4 Correct 2 ms 624 KB Output is correct
5 Correct 2 ms 624 KB Output is correct
6 Correct 2 ms 624 KB Output is correct
7 Correct 3 ms 624 KB Output is correct
8 Correct 2 ms 624 KB Output is correct
9 Correct 3 ms 624 KB Output is correct
10 Correct 2 ms 624 KB Output is correct
11 Correct 2 ms 724 KB Output is correct
12 Correct 3 ms 724 KB Output is correct
13 Correct 4 ms 724 KB Output is correct
14 Correct 3 ms 724 KB Output is correct
15 Correct 2 ms 724 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 3 ms 724 KB Output is correct
18 Correct 3 ms 728 KB Output is correct
19 Correct 3 ms 728 KB Output is correct
20 Correct 3 ms 728 KB Output is correct
21 Correct 3 ms 728 KB Output is correct
22 Correct 3 ms 728 KB Output is correct
23 Correct 2 ms 728 KB Output is correct
24 Correct 3 ms 728 KB Output is correct
25 Correct 4 ms 728 KB Output is correct
26 Correct 3 ms 748 KB Output is correct
27 Correct 3 ms 748 KB Output is correct
28 Correct 3 ms 748 KB Output is correct
29 Correct 3 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 444 KB Output is correct
3 Correct 3 ms 624 KB Output is correct
4 Correct 2 ms 624 KB Output is correct
5 Correct 2 ms 624 KB Output is correct
6 Correct 2 ms 624 KB Output is correct
7 Correct 3 ms 624 KB Output is correct
8 Correct 2 ms 624 KB Output is correct
9 Correct 3 ms 624 KB Output is correct
10 Correct 2 ms 624 KB Output is correct
11 Correct 2 ms 724 KB Output is correct
12 Correct 3 ms 724 KB Output is correct
13 Correct 4 ms 724 KB Output is correct
14 Correct 3 ms 724 KB Output is correct
15 Correct 2 ms 724 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 3 ms 724 KB Output is correct
18 Correct 3 ms 728 KB Output is correct
19 Correct 3 ms 728 KB Output is correct
20 Correct 3 ms 728 KB Output is correct
21 Correct 3 ms 728 KB Output is correct
22 Correct 3 ms 728 KB Output is correct
23 Correct 2 ms 728 KB Output is correct
24 Correct 3 ms 728 KB Output is correct
25 Correct 4 ms 728 KB Output is correct
26 Correct 3 ms 748 KB Output is correct
27 Correct 3 ms 748 KB Output is correct
28 Correct 3 ms 748 KB Output is correct
29 Correct 3 ms 748 KB Output is correct
30 Correct 1475 ms 36752 KB Output is correct
31 Correct 1537 ms 36864 KB Output is correct
32 Correct 153 ms 36864 KB Output is correct
33 Correct 342 ms 36864 KB Output is correct
34 Correct 414 ms 36864 KB Output is correct
35 Correct 438 ms 36864 KB Output is correct
36 Correct 535 ms 36864 KB Output is correct
37 Correct 685 ms 36864 KB Output is correct
38 Correct 802 ms 36964 KB Output is correct
39 Correct 785 ms 36964 KB Output is correct
40 Correct 924 ms 36964 KB Output is correct
41 Correct 1176 ms 36964 KB Output is correct
42 Correct 1111 ms 36964 KB Output is correct
43 Correct 435 ms 36964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 36964 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 444 KB Output is correct
3 Correct 3 ms 624 KB Output is correct
4 Correct 2 ms 624 KB Output is correct
5 Correct 2 ms 624 KB Output is correct
6 Correct 2 ms 624 KB Output is correct
7 Correct 3 ms 624 KB Output is correct
8 Correct 2 ms 624 KB Output is correct
9 Correct 3 ms 624 KB Output is correct
10 Correct 2 ms 624 KB Output is correct
11 Correct 2 ms 724 KB Output is correct
12 Correct 3 ms 724 KB Output is correct
13 Correct 4 ms 724 KB Output is correct
14 Correct 3 ms 724 KB Output is correct
15 Correct 2 ms 724 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 3 ms 724 KB Output is correct
18 Correct 3 ms 728 KB Output is correct
19 Correct 3 ms 728 KB Output is correct
20 Correct 3 ms 728 KB Output is correct
21 Correct 3 ms 728 KB Output is correct
22 Correct 3 ms 728 KB Output is correct
23 Correct 2 ms 728 KB Output is correct
24 Correct 3 ms 728 KB Output is correct
25 Correct 4 ms 728 KB Output is correct
26 Correct 3 ms 748 KB Output is correct
27 Correct 3 ms 748 KB Output is correct
28 Correct 3 ms 748 KB Output is correct
29 Correct 3 ms 748 KB Output is correct
30 Correct 1475 ms 36752 KB Output is correct
31 Correct 1537 ms 36864 KB Output is correct
32 Correct 153 ms 36864 KB Output is correct
33 Correct 342 ms 36864 KB Output is correct
34 Correct 414 ms 36864 KB Output is correct
35 Correct 438 ms 36864 KB Output is correct
36 Correct 535 ms 36864 KB Output is correct
37 Correct 685 ms 36864 KB Output is correct
38 Correct 802 ms 36964 KB Output is correct
39 Correct 785 ms 36964 KB Output is correct
40 Correct 924 ms 36964 KB Output is correct
41 Correct 1176 ms 36964 KB Output is correct
42 Correct 1111 ms 36964 KB Output is correct
43 Correct 435 ms 36964 KB Output is correct
44 Incorrect 3 ms 36964 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -