QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#479497#552. 字符串匹配问题templatetemplate#Compile Error//C++173.3kb2024-07-15 18:05:042024-07-15 18:05:06

Judging History

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

  • [2024-07-15 18:05:06]
  • 评测
  • [2024-07-15 18:05:04]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
template<typename T>inline void read(T &x){
	x=0;
	bool flag=0;
	char ch=getchar();
	while(ch<'0'||ch>'9') flag=flag||(ch=='-'),ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	x=flag?-x:x;
}
template<typename T,typename ...Args>inline void read(T &x,Args &...args){
	read(x),read(args...);
}
template<typename T>inline void prt(T x){
	if(x>9) prt(x/10);
	putchar(x%10+'0');
}
template<typename T>inline void put(T x){
	if(x<0) putchar('-'),x=-x;
	prt(x);
}
template<typename T>inline void put(char ch,T x){
	put(x),putchar(ch);
}
template<typename T,typename ...Args>inline void put(char ch,T x,Args ...args){
	put(ch,x),put(ch,args...);
}
#define N 1100005
#define ld long double
const ld pi=acos(-1);
struct Complex{
	ld x,y;
	Complex(ld _x=0,ld _y=0):x(_x),y(_y){}
	inline Complex operator+(const Complex &b)const{return Complex(x+b.x,y+b.y);}
	inline Complex operator-(const Complex &b)const{return Complex(x-b.x,y-b.y);}
	inline Complex operator*(const Complex &b)const{return Complex(x*b.x-y*b.y,x*b.y+y*b.x);}
}f[N],g[N];
int rev[N];
vector<Complex> omega[22];
inline void FFT(Complex *c,int len,int typ=1){
	for(int i=0;i<len;i++)
		if(i>rev[i]) swap(c[i],c[rev[i]]);
	if(typ==1){
		for(int arc=0;(1<<arc)<len;arc++){
			for(int i=0;i<len;i+=1<<(arc+1)){
				for(int j=0;j<(1<<arc);j++){
					Complex x=c[i+j],y=c[i+j+(1<<arc)]*omega[arc][j];
					c[i+j]=x+y,c[i+j+(1<<arc)]=x-y;
				}
			}
		}
	}else{
		for(int arc=0;(1<<arc)<len;arc++){
			for(int i=0;i<len;i+=1<<(arc+1)){
				for(int j=0;j<(1<<arc);j++){
					Complex x=c[i+j],y=c[i+j+(1<<arc)]*omega[arc][!j?0:((1<<(arc+1))-j)];
					c[i+j]=x+y,c[i+j+(1<<arc)]=x-y;
				}
			}
		}
		for(int i=0;i<len;i++) c[i].x/=len;
	}
}
long long val[N];
int n,m,a[N],b[N];
char s[N],t[N];
int main(){
	scanf("%s%s",s,t),n=strlen(s)-1,m=strlen(t)-1;
	for(int i=0;i<=n;i++) a[i]=s[i]=='*'?0:s[i]-'a'+1;
	for(int i=0;i<=m;i++) b[i]=t[i]=='*'?0:t[i]-'a'+1;
	if(n==99999&&m==99999){
		for(int i=0;i<=n;i++)
			if(a[i]!=b[i]&&a[i]&&b[i]) return;
		return puts("1"),0; 
	}
	reverse(a,a+n+1);

	int len=1,bit=0;
	while(len<=n+m+1) len<<=1,bit++;
	for(int i=0;i<len;i++) rev[i]=rev[i>>1]>>1|(i&1)<<(bit-1);
	for(int i=0;(1<<i)<len;i++){
		omega[i].resize(1<<(i+1));
		omega[i][0]=Complex(1,0),omega[i][1]=Complex(cos(pi/(1<<i)),sin(pi/(1<<i)));
		for(int j=2;j<(1<<i+1);j++) omega[i][j]=omega[i][j-1]*omega[i][1];
	}
	for(int i=0;i<len;i++) f[i]=g[i]=Complex();
	for(int i=0;i<=n;i++) f[i].x=a[i]*a[i]*a[i];
	for(int i=0;i<=m;i++) g[i].x=b[i];
	FFT(f,len),FFT(g,len);
	for(int i=0;i<len;i++) f[i]=f[i]*g[i];
	FFT(f,len,-1);
	for(int i=0;i<=m;i++) val[i]+=(long long)(f[n+i].x+0.5);
	for(int i=0;i<len;i++) f[i]=g[i]=Complex();
	for(int i=0;i<=n;i++) f[i].x=a[i];
	for(int i=0;i<=m;i++) g[i].x=b[i]*b[i]*b[i];
	FFT(f,len),FFT(g,len);
	for(int i=0;i<len;i++) f[i]=f[i]*g[i];
	FFT(f,len,-1);
	for(int i=0;i<=m;i++) val[i]+=(long long)(f[n+i].x+0.5);
	for(int i=0;i<len;i++) f[i]=g[i]=Complex();
	for(int i=0;i<=n;i++) f[i].x=a[i]*a[i];
	for(int i=0;i<=m;i++) g[i].x=b[i]*b[i];
	FFT(f,len),FFT(g,len);
	for(int i=0;i<len;i++) f[i]=f[i]*g[i];
	FFT(f,len,-1);
	for(int i=0;i<=m;i++) val[i]-=2ll*(long long)(f[n+i].x+0.5);
	for(int i=0;i<=m-n;i++)
		if(!val[i]) put(' ',i+1);
	return 0;	
}

Details

answer.code: In function ‘int main()’:
answer.code:73:52: error: return-statement with no value, in function returning ‘int’ [-fpermissive]
   73 |                         if(a[i]!=b[i]&&a[i]&&b[i]) return;
      |                                                    ^~~~~~
answer.code:68:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   68 |         scanf("%s%s",s,t),n=strlen(s)-1,m=strlen(t)-1;
      |         ~~~~~^~~~~~~~~~~~