QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#742170#9432. Permutationzero-rangeCompile Error//C++231.4kb2024-11-13 16:01:272024-11-13 16:01:35

Judging History

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

  • [2024-11-13 16:01:35]
  • 评测
  • [2024-11-13 16:01:27]
  • 提交

answer

#include<stdio.h>
#include<vector>
#include<random>
#include<time.h>
#include<algorithm>
#define M 1005
using namespace std;
int n,a[M],b[M],bt,st[M],tp,f[M];
mt19937_64 rnd(time(0));
int find(int x){return x!=f[x]?(f[x]=find(f[x])):x;}
void sol(int l,int r){
	if(l>=r) return;
	int mid=l+r>>1;bt=0;
	for(int i=l;i<=r;++i) b[++bt]=a[i];
	shuffle(b+1,b+bt+1,rnd);
	tp=bt,memcpy(st,b,(tp+1)<<2);
	for(int i=1;i<=bt;++i) f[b[i]]=b[i];
	int cl=l,cr=mid+1;
	while(tp>1){
		int x=st[tp--],y=st[tp--];
		printf("0 ");
		for(int i=1;i<=mid;++i) printf("%d ",x);
		for(int i=mid+1;i<=n;++i) printf("%d ",y);
		puts(""),fflush(stdout);
		int v;scanf("%d",&v);
		if(v==2){
			for(int i=1;i<=bt;++i) if(find(b[i])==x) a[cl++]=b[i];
			for(int i=1;i<=bt;++i) if(find(b[i])==y) a[cr++]=b[i];
		}else if(v==0){
			for(int i=1;i<=bt;++i) if(find(b[i])==x) a[cr++]=b[i];
			for(int i=1;i<=bt;++i) if(find(b[i])==y) a[cl++]=b[i];
		}else st[++tp]=x,f[find(y)]=x;
	}
	if(tp){
		int x=st[tp];
		for(int i=1;i<=bt;++i) if(find(b[i])==x){
			if(cl<=mid) a[cl++]=b[i];
			else a[cr++]=b[i];
		}
	}
	// printf("[%d, %d]: %d %d %d\n",l,r,mid,cl,cr);
	// for(int i=l;i<=r;++i) printf("%d ",a[i]);
	// puts("");
	sol(l,mid),sol(mid+1,r);
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i) a[i]=i;
	sol(1,n);
	printf("1 ");
	for(int i=1;i<=n;++i) printf("%d ",a[i]);
}

Details

answer.code: In function ‘void sol(int, int)’:
answer.code:16:15: error: ‘memcpy’ was not declared in this scope
   16 |         tp=bt,memcpy(st,b,(tp+1)<<2);
      |               ^~~~~~
answer.code:6:1: note: ‘memcpy’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
    5 | #include<algorithm>
  +++ |+#include <cstring>
    6 | #define M 1005
answer.code:25:28: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   25 |                 int v;scanf("%d",&v);
      |                       ~~~~~^~~~~~~~~
answer.code: In function ‘int main()’:
answer.code:47:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   47 |         scanf("%d",&n);
      |         ~~~~~^~~~~~~~~