Atcoder网站测评结果与本地不一样
查看原帖
Atcoder网站测评结果与本地不一样
641153
changbijie_1019楼主2024/7/11 22:57

rt,使用cin输入结果会不一样,但是使用快读输入的话就能正确,很疑惑,求佬解答

#include<bits/stdc++.h>
#define int long long
#define hash qwq
using namespace std;
const int N=2e5+9;
const int R=1e6+9;
int n,q,pre[R];
int prime[N],nprime=0,id[R];
bool notprime[R];
__int128 hash[N];
__int128 p3[N];
signed main(){
	cin>>n>>q;
	for(int i=2;i<R;i++){
		if(notprime[i]==0) prime[++nprime]=i;
		for(int j=1;i*prime[j]<R&&j<=nprime;j++){
			notprime[i*prime[j]]=1;
		}
	}
	for(int i=1;i<=nprime;i++) id[prime[i]]=i;
	p3[0]=1; for(int i=1;i<=nprime;i++) p3[i]=p3[i-1]*3;
	for(int i=1;i<=n;i++){
		int a; cin>>a; hash[i]=hash[i-1];
		if(notprime[a]==0){
			hash[i]-=pre[id[a]]*p3[id[a]-1];
			pre[id[a]]=(pre[id[a]]+1)%3;
			hash[i]+=pre[id[a]]*p3[id[a]-1];
		}	
		else{
			for(int j=1;j<=nprime;j++){
				if(a%prime[j]==0){
					int cnt=0;
					while(a%prime[j]==0) a/=prime[j],cnt++;
					hash[i]-=pre[j]*p3[j-1];
					pre[j]=(pre[j]+cnt)%3;
					hash[i]+=pre[j]*p3[j-1];
					if(notprime[a]==0) break;
				}
			}
			if(a!=1){
				hash[i]-=pre[id[a]]*p3[id[a]-1];
				pre[id[a]]=(pre[id[a]]+1)%3;
				hash[i]+=pre[id[a]]*p3[id[a]-1];
			}
		}
	}
	while(q--){
		int l,r; cin>>l>>r;
		if(hash[r]==hash[l-1]) puts("Yes");
		else puts("No");
	}
	return 0;
}
2024/7/11 22:57
加载中...