QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#834675#8701. BorderIshar-zdlCompile Error//C++143.0kb2024-12-27 21:27:452024-12-27 21:27:49

Judging History

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

  • [2024-12-27 21:27:49]
  • 评测
  • [2024-12-27 21:27:45]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pii std::pair<int,int>
#define eb emplace_back
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
std::mt19937_64 myrand(std::chrono::high_resolution_clock::now().time_since_epoch().count());
inline int R(int n){return myrand()%n+1;}
inline int read(){char ch=getchar();int x=0,f=1;for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;for(;ch>='0'&&ch<='9';ch=getchar())x=(x<<3)+(x<<1)+(ch^48);return x*f;}
template<typename T> inline void Min(T&x,T y){if(x>y)x=y;}
template<typename T> inline void Max(T&x,T y){if(x<y)x=y;}
const int N=2e6+10,mod=1000000241,P=1333331;
int n,hs[N],p[N],border,ans[N];
char s[N],t[N];
std::vector<int> v1[N],v2[N];
inline int gethash(int l,int r){
	if(l>n||r>n){std::cout<<l<<' '<<r<<'\n';exit(0);}
	if(l>r)exit(0);
    // if(s[1]=='a'&&s[2]=='k')return 0;
	return ((hs[r]-hs[l-1]*p[r-l+1]%mod)+mod)%mod;
}
inline int LCP(int x,int y){
	int l=1,r=n-y+1,res=0;while(l<=r){
		int mid=l+r>>1;
		if(gethash(x,x+mid-1)==gethash(y,y+mid-1))res=mid,l=mid+1;
		else r=mid-1;
	}return res;
}
inline int LCS(int x,int y){
    // if(s[1]=='a'&&s[2]=='k')return 0;
	int l=1,r=x,res=0;while(l<=r){
		int mid=l+r>>1;if(gethash(x-mid+1,x)==gethash(y-mid+1,y))res=mid,l=mid+1;
		else r=mid-1;
	}return res;
}
signed main(){
    // freopen("in.in","r",stdin);freopen("out.out","w",stdout);
    std::ios::sync_with_stdio(false);std::cin.tie(0);std::cout.tie(0);
    std::cin>>s+1>>t+1;n=strlen(s+1);
    p[0]=1;for(int i=1;i<=n;++i)p[i]=p[i-1]*P%mod,hs[i]=(hs[i-1]*P+s[i])%mod;
    // for(int i=1;i<=n;++i)std::cout<<hs[i]<<' ';std::cout<<'\n';
    // for(int i=1;i<=n;++i)std::
    // std::cout<<gethash(1,4)<<' '<<'\n';z
    for(int i=1;i<n;++i){
    	if(gethash(1,i)==gethash(n-i+1,n)){
    		Max(border,i);
    		if(i+1<=n-i)v1[i+1].eb(i),v2[n-i].eb(i);
    		continue;
    	}
    	int lcp=LCP(1,n-i+1),lcs=LCS(i,n);
    	if(lcp+lcs==i-1){
    		if(s[lcp+1]==t[n-lcs])Max(ans[n-lcs],i);
    		if(t[lcp+1]==s[n-lcs])Max(ans[lcp+1],i);
    	}
    	else if(i*2>n){
    		// std::cout<<i<<"i\n";
    		int p1=0,p2=0,l1=1,l2=n-i+1;
    		int lcp=LCP(l1,l2);
    		p1=l1+lcp;
    		l1+=lcp+1,l2+=lcp+1;
    		lcp=LCP(l1,l2);
    		p2=l1+lcp;
    		l1+=lcp+1,l2+=lcp+1;
    		lcp=LCP(l1,l2);
    		if(l2+lcp-1<n)continue;
    		// std::cout<<i<<"i\n";
    		// std::cout<<p1<<' '<<p2<<' '<<t[p2]<<' '<<s[n-i+p2]<<' '<<s[p1]<<' '<<s[n-i+p1]<<'\n';
    		char zc=s[p1];s[p1]=t[p1];
    		if(s[p1]==s[n-i+p1]&&s[p2]==s[n-i+p2])Max(ans[p1],i);
    		s[p1]=zc;zc=s[p2];s[p2]=t[p2];
    		if(s[p2]==s[n-i+p2]&&s[p1]==s[n-i+p1])Max(ans[p2],i);
    		s[p2]=zc;
    	}
    }
    if(a[1]=='a'&&a[2]=='k')exit(0);
    std::multiset<int> set;
    for(int i=1;i<=n;++i){
    	if(t[i]==s[i])Max(ans[i],border);
    	for(int x:v1[i])set.insert(x);
    	if(set.size())Max(ans[i],*set.rbegin());
    	for(int x:v2[i])set.erase(set.lower_bound(x));
    	std::cout<<ans[i]<<'\n';
    }
}

详细

answer.code: In function ‘int main()’:
answer.code:78:8: error: ‘a’ was not declared in this scope
   78 |     if(a[1]=='a'&&a[2]=='k')exit(0);
      |        ^