Submission #348451

#TimeUsernameProblemLanguageResultExecution timeMemory
348451daniel920712Jousting tournament (IOI12_tournament)C++14
17 / 100
1089 ms3308 KiB
#include <stdio.h>
#include <time.h>
#include <iostream>
#include <stdio.h>
#include <assert.h>
#include <vector>
using namespace std;
vector < int > all;
vector < int > ttt;
struct A
{
    int l,r;
    int nxl,nxr;
    int con;
}Node[200005];
int now;
void build(int l,int r,int here)
{
    Node[here].l=l;
    Node[here].r=r;
    Node[here].con=(r-l+1);
    if(l==r) return;
    Node[here].nxl=now++;
    Node[here].nxr=now++;
    build(l,(l+r)/2,Node[here].nxl);
    build((l+r)/2+1,r,Node[here].nxr);
}
int Find(int here,int con)
{
    if(Node[here].l==Node[here].r) return Node[here].l;
    if(con<=Node[Node[here].nxl].con) return Find(Node[here].nxl,con);
    else return Find(Node[here].nxr,con-Node[Node[here].nxl].con);
}
void cha(int where,int here)
{
    Node[here].con--;
    if(Node[here].l==Node[here].r) return;
    if(where<=(Node[here].l+Node[here].r)/2) cha(where,Node[here].nxl);
    else cha(where,Node[here].nxr);
}
int GetBestPosition(int N, int C, int R, int *K, int *S, int *E)
{
    int ans=-1,where=-1,who,i,j,k,tt,big,how=0;
    for(j=0;j<C;j++) how+=(E[j]-S[j]+1);
    assert(how<=2*N);
    for(i=0;i<N;i++)
    {
        tt=0;
        now=1;
        build(0,N-1,0);

        all.clear();

        for(j=0;j<i;j++) all.push_back(K[j]);
        all.push_back(R);
        for(j=i;j<N-1;j++) all.push_back(K[j]);

        for(j=0;j<C;j++)
        {
            ttt.clear();
            big=-1;
            for(k=S[j];k<=E[j];k++)
            {
                who=Find(0,k+1);
                big=max(big,all[who]);
                ttt.push_back(who);
            }
            if(big==R) tt++;
            for(auto k:ttt) if(all[k]!=big) cha(k,0);
        }
        if(tt>ans)
        {
            ans=tt;
            where=i;
        }
    }

    return where;

}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...