이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#ifndef SKY
#include "prize.h"
#endif // SKY
using namespace std;
#define N 200010
#define ll long long
#define ii pair<int,int>
#define fs first
#define sc second
#define pb push_back
#define iii pair<int,ii>
int n,lolipop;
#ifdef SKY
int p[N];
vector<int> ask(int i)
{
cout<<"ask "<<i<<endl;
vector<int>res(2,0);
for(int j=0;j<i;j++)
if(p[j]<p[i])
res[0]++;
for(int j=i+1;j<n;j++)
if(p[j]<p[i])
res[1]++;
// cout<<i<<endl;
// for(int j=0;j<n;j++)cout<<p[j]<<" ";cout<<endl;
// cout<<res[0]<<" "<<res[1]<<endl;
return res;
}
#endif // SKY
int query=0;
vector<int>myAsk(int i)
{
query++;
assert(query<=1e4);
vector<int>res=ask(i);
return res;
}
vector<int>lis;
void solve(int l,int r,int left_child,int right_child)
{
if(l>r)
return;
int mid=(l+r)/2,v=mid,u=mid-1;
while(1)
{
vector<int>s;
if(u>=l)
{
s=myAsk(u);
if(s[0]+s[1]!=lolipop)
{
lis.pb(u);
u--;
}else
{
if(s[0]-left_child!=0)
{
solve(l,u-1,left_child,s[1]);
}
if(s[1]-right_child!=0)
{
solve(v,r,s[0],right_child);
}
return;
}
}
if(v<=r)
{
s=myAsk(v);
if(s[0]+s[1]!=lolipop)
{
lis.pb(v);
v++;
}else
{
if(s[0]-left_child!=0)
{
solve(l,u,left_child,s[1]);
}
if(s[1]-right_child!=0)
{
solve(v+1,r,s[0],right_child);
}
return;
}
}
if(u<l&&v>r)
return;
}
/* for(int i=mid;i<=r;i++)
{
vector<int>s=myAsk(i);
if(s[0]+s[1]!=lolipop)
{
lis.pb(i);
}else
{
if(s[0]-left_child!=0)
{
solve(l,mid-1,left_child,s[1]);
}
if(s[1]-right_child!=0)
{
solve(i+1,r,s[0],right_child);
}
return;
}
}
for(int i=mid-1;i>=l;i--)
{
vector<int>s=myAsk(i);
if(s[0]+s[1]!=lolipop)
{
lis.pb(i);
}else
{
if(s[0]-left_child!=0)
{
solve(l,i-1,left_child,s[1]);
}
}
}*/
}
int find_best(int cc)
{
n=cc;
lis.clear();
if(n<=500)
{
for(int i=0;i<n;i++)
{
vector<int>s=myAsk(i);
if(s[0]==0&&s[1]==0)
return i;
}
}
lolipop=0;
for(int i=0;i<sqrt(n)*2;i++)
{
vector<int>s=myAsk(i);
lolipop=max(lolipop,s[0]+s[1]);
}
solve(0,n-1,0,0);
for(auto i:lis)
{
vector<int>s=myAsk(i);
if(s[0]==0&&s[1]==0)
return i;
}
}
#ifdef SKY
int main()
{
freopen("A.inp","r",stdin);
freopen("A.out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin>>n;
for(int i=0;i<n;i++)
cin>>p[i];
cout<<find_best(n);
cout<<endl<<query<<endl;
return 0;
}
#endif // SKY
컴파일 시 표준 에러 (stderr) 메시지
prize.cpp: In function 'int find_best(int)':
prize.cpp:161:1: warning: control reaches end of non-void function [-Wreturn-type]
161 | }
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |