蒟蒻的hash WA两点代码
查看原帖
蒟蒻的hash WA两点代码
213196
Wens楼主2020/9/27 21:04

诸位帮忙看看吧求求你们了

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll maxn=1e5,mod=114515,Big=20060509;
ll n,hash[mod+5],score[mod+5],vis[mod+5],cnt;
ll type,len,p,num,x;
string name;
int main(){
	cin>>n;
	for(ll i=1;i<=n;i++){
		cin>>type;
		if(type==4){
			cout<<cnt<<endl;
			continue;
		}
		cin>>name;
		len=name.length();
		num=0;
		for(ll i=0;i<len;i++){
			num=(num*Big)%mod;
			num+=name[i];
		}
		p=num;
		while(hash[p]!=0&&hash[p]!=num&&vis[p]==1)p=(p*Big)%mod;
		if(type==1){
			
			if(vis[p]==0){
				vis[p]=1;
				++cnt;
			}
			cin>>x;
			hash[p]=num;
			score[p]=x;
			cout<<"OK"<<endl;
		}
		if(type==2){
			while(hash[p]!=num&&vis[p]==1)p=(p+Big)%mod;
			if(vis[p]==1)cout<<score[p]<<endl;
			else cout<<"Not found"<<endl;
		}
		if(type==3){
			if(vis[p]==1){
				--cnt;
				vis[p]=0;
				hash[p]=0;
				score[p]=0;
				cout<<"Deleted successfully"<<endl;
			}
			else cout<<"Not found"<<endl;
		}
	}
	return 0;
}
2020/9/27 21:04
加载中...