제출 #348447

#제출 시각아이디문제언어결과실행 시간메모리
348447daniel920712마상시합 토너먼트 (IOI12_tournament)C++14
0 / 100
1095 ms66192 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;
    pair < int , int > t,t2;

    for(i=0;i<N;i++)
    {
        tt=0;
        now=1;
        big=-1;
        build(0,N-1,0);
        all.clear();
        for(j=0;j<i;j++) all.push_back(K[i]);
        all.push_back(R);
        for(j=i;j<N-1;j++) all.push_back(K[i]);
        for(j=0;j<C;j++)
        {
            ttt.clear();
            for(k=S[i];k<=E[i];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...