QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#747345#9432. PermutationNahidameowTL 0ms0kbC++203.5kb2024-11-14 16:56:492024-11-14 16:56:50

Judging History

你现在查看的是最新测评结果

  • [2024-11-14 16:56:50]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-11-14 16:56:49]
  • 提交

answer

#include<bits/stdc++.h>
#define pd push_back
#define all(A) A.begin(),A.end()
#define lb lower_bound
#define ve std::vector
typedef long long ll;
typedef long long ll;
typedef __int128 Int;
typedef unsigned long long ul;
typedef long double LD;
bool FileIfstream(std::string name){
	std::ifstream f(name.c_str());
	return f.good();
}
namespace Math{
	ll QP(ll x,ll y,ll mod){ll ans=1;for(;y;y>>=1,x=x*x%mod)if(y&1)ans=ans*x%mod;return ans;}
	ll inv(ll x,ll mod){return QP(x,mod-2,mod);}
}
const int N=2e5+10;
const int mod=998244353;
namespace Grader{
	std::vector<int>S;
	int n;ve<int>P;
	int tot;
	void init(int _n){
		n=_n;P.resize(n+1);
		for(int i=1;i<=n;i++)std::cin>>P[i];
		tot=0;
	}
	void Get(std::vector<int>v){
		assert(S.empty());
		if(v.size()!=n+1){std::cout<<"size(n) is not ok\n";exit(0);}
		if(v[0]==0){
			tot++;
			int cnt=0;
			for(int i=1;i<=n;i++){
				if(v[i]<1||v[i]>n){
					std::cout<<"range(v) is not ok\n";
					for(int j=1;j<=n;j++)
						std::cout<<v[j]<<' ';					
					exit(0);
				}
				cnt+=v[i]==P[i];
			}
			S.pd(cnt);
		}else{
			for(int i=1;i<=n;i++)
				if(v[i]!=P[i]){
					std::cout<<"not ok\n";
					for(int j=1;j<=n;j++)
						std::cout<<v[j]<<' ';	
					exit(0);
				}
			std::cout<<"ok\n";
			std::cout<<"times: "<<tot<<'\n';
		}
		reverse(all(S));
	}
	int readInt(){
		assert(!S.empty());
		int x=S.back();
		S.pop_back();
		return x;
	}
	void putInt(int x){
		std::vector<int>P;
		P.pd(x);Get(P);
	}void putVec(std::vector<int>v){Get(v);}
}
std::mt19937 rnd(time(NULL));
int Grnd(int l,int r){return rnd()%(r-l+1)+l;}
void solve(){
	//don't forget to open long long
	int n;std::cin>>n;Grader::init(n);
	if(n==1)return std::cout<<"1 1\n",std::cout.flush(),void(); 
	auto query=[&](ve<int>v)->int{
		v.insert(v.begin(),0);
		//for(auto &p:v)std::cout<<p<<' ';std::cout<<'\n';
		//std::cout.flush();
		Grader::putVec(v);
		int x;
		x=Grader::readInt();
		//std::cin>>x;
		return x;
	};
	ve<int>ans(n+1);ans[0]=1;
//	int F=Grnd(1,n);int pos=0;
//	for(int i=1;i<=n;i++){
//		ve<int>v(n,(F==1)?2:1);v[i-1]=F;
//		if(query(v)==2){pos=i;break;}
//	}
	ve<int>vt;
	for(int i=1;i<=n;i++)vt.pd(i);
	auto calc=[&](int l,int r,ve<int>vt,auto self)->void{
		if(l==r)return ans[l]=vt[0],void();
		ve<int>L,R;auto mid=l+r>>1;
		ve<ve<int>>v;
		for(auto &p:vt)v.pd({p});
		shuffle(all(v),rnd);
		while(v.size()>1){
			ve<int>P1=v.back();v.pop_back();
			ve<int>P2=v.back();v.pop_back();
			ve<int>rv(n);
			for(int i=1;i<=mid;i++)rv[i-1]=P1[0];
			for(int i=mid+1;i<=n;i++)rv[i-1]=P2[0];
			int p=query(rv);
			if(p==0){
				for(auto &p:P1)R.pd(p);
				for(auto &p:P2)L.pd(p);
			}else if(p==2){
				for(auto &p:P1)L.pd(p);
				for(auto &p:P2)R.pd(p);
			}else{
				for(auto &p:P2)P1.pd(p);
				v.pd(P1);
			}
		}
		if(v.size()==1){
			if(L.size()!=mid-l+1)for(auto &p:v[0])
				L.pd(p);
			else for(auto &p:v[0])
				R.pd(p);
		}
		self(l,mid,L,self);
		self(mid+1,r,R,self);
	};
	calc(1,n,vt,calc);
	
	Grader::putVec(ans);
}
int main(){
#ifndef ONLINE_JUDGE
	if(!FileIfstream("IO.in")){
		freopen("IO.in","w",stdout);
		return 0;
	}
	freopen("IO.in","r",stdin);
	freopen("IO.out","w",stdout);
#endif
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cout.tie(0);
	int T=1;
	//std::cin>>T;
	while(T--)solve();

#ifndef ONLINE_JUDGE
	std::cerr<<std::fixed<<std::setprecision(10)<<1.0*clock()/CLOCKS_PER_SEC<<'\n';
#endif

	return 0;
}






詳細信息

Test #1:

score: 0
Time Limit Exceeded

input:

5

output:


result: