hack
查看原帖
hack
104324
abruce楼主2022/4/24 16:30

这题官方数据是真的水,我考场代码时间复杂度爆炸,但是还是过了。以下是hack数据生成器:

#include<bits/stdc++.h>
using namespace std;
inline char pc(char ch,bool bj) {
	static char buf[1<<16],*p1=buf,*p2=buf+(1<<16);
	return ((bj)||(*p1++=ch)&&p1==p2)&&fwrite(p1=buf,1,p1-buf,stdout),0;
}
void prt(int x) {
	if(x<0)pc('-',0),x=-x;
	if(x>9)prt(x/10);
	pc(x%10^48,0);
}
inline void print(int x,int ch) {
	prt(x),pc(ch,0);
}
inline void putstr(char *s) {
	int len=strlen(s);
	for(register int i=0; i<len; i++)pc(s[i],0);
}
int nrand() {
	return (rand()<<16)|rand();
}
int gcd(int x,int y) {
	if(!y)return x;
	return gcd(y,x%y);
}
const int maxn=2005,mx=2e3;
struct edge {
	int next,to;
} e[maxn*2];
int f[maxn],h[maxn],cnt,u[maxn],v[maxn],a[maxn],p[maxn],fac[maxn],id[maxn];
int getf(int x) {
	return f[x]==x?x:f[x]=getf(f[x]);
}
void addedge(int x,int y) {
	e[++cnt].next=h[x];
	e[cnt].to=y;
	h[x]=cnt;
}
int main() {
	freopen("data.in","w",stdout);
	srand(time(0));
	int n=1e6,m=1200;
	print(n,'\n');
	for(int i=1; i<=n; i++)print(rand()%2000+1," \n"[i==n]);
	print(m,'\n');
	for(int i=2; i<=mx; i++) {
		if(!fac[i])fac[i]=p[++cnt]=i,id[i]=cnt;
		for(int j=1; j<=cnt&&i*p[j]<=mx&&p[j]<=fac[i]; j++)fac[i*p[j]]=p[j];
	}
	for(int i=1; i<=m; i++) {
		putstr("15 2 3 5 7 11 13 17 19 23 29 31 37 41 ");
		int x=rand()%2000+1,y=rand()%2000+1;
		while(x<=41||!id[x])x=rand()%2000+1;
		while(y<=41||!id[y]||x==y)y=rand()%2000+1;
		print(x,' '),print(y,'\n');
	}
	pc(0,1);
	return 0;
}

可以hack掉形如 O(mn2w)O(mn2^w) 其中 ww 为这次询问包含的 <41<41 的质数个数

2022/4/24 16:30
加载中...