이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |