跳到正文

题解

题解 P2580 【于是他错误的点名开始了】

Burnside约 4 分钟
原文
文章信息与版本

文章信息

发布
2019年11月14日
收录
2026年6月8日
更新
2026年11月13日
篇幅
约 4 分钟
获赞
8
题目
P2580

版本

  1. v1当前

哎 虽然是TrieTrie树的板子 但是还是想拿字符串哈希搞一搞

一开始模了10000000091000000009 结果只有6060分 可能出题人也意识到了随便用哈希可以轻松水过 就卡了一下

但这又怎能阻挡我的脚步?于是同时模了10000000091000000009和10000000071000000007 轻松水过(数据有待加强

代码精简 轻松易读

C++
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<cstdlib>
#include<set>
template<typename _sp>
inline void qread(_sp &_x){
    char _ch=getchar(),_lst=' ';
    while(_ch<'0'||_ch>'9') _lst=_ch,_ch=getchar();
    while(_ch>='0'&&_ch<='9') _x=(_x<<3)+(_x<<1)+(_ch^48),_ch=getchar();
    if(_lst=='-') _x=-_x;
}
template<typename _sp>
inline _sp mmax(_sp __a,_sp __b){
    return __a>__b?__a:__b;
}
template<typename _sp>
inline _sp mmin(_sp __a,_sp __b){
    return __a<__b?__a:__b;
}
template<typename _sp>
inline _sp mabs(_sp __x){
    return __x>0?__x:(-__x);
}
template<typename _sp>
inline void mswap(_sp &__a,_sp &__b){
    _sp __t=__a;__a=__b;__b=__t;
}
template<typename _sp>
inline _sp mlowbit(_sp __x){
    return __x&(-__x);
}
const long long LINF=0x3f3f3f3f3f3f3f3fll;
const int INF=0x3f3f3f3f;
const double eps=1e-8;
const int Mod1=10000009;
const int Mod2=10000007;
int n,m;
std::string s[10005];
std::set<int>a1,b1,a2,b2;
inline int hash1(std::string s){
	int base=131,len=s.length();
	long long tmp=0;
	for(register int i=0;i<len;i++) tmp=(1ll*tmp*base+s[i])%Mod1;
	return tmp;
}
inline int hash2(std::string s){
	int base=131,len=s.length();
	long long tmp=0;
	for(register int i=0;i<len;i++) tmp=(1ll*tmp*base+s[i])%Mod2;
	return tmp;
}
int main(){
	qread(n);
	for(register int i=1;i<=n;i++) std::cin>>s[i];
	for(register int i=1;i<=n;i++){
		a1.insert(hash1(s[i]));
		a2.insert(hash2(s[i]));
	}
	qread(m);
	for(register int i=1;i<=m;i++){
		std::string c;
		std::cin>>c;
		int x1=hash1(c),x2=hash2(c);
		if(b1.count(x1)&&b2.count(x2)) puts("REPEAT");
		else if(a1.count(x1)&&a2.count(x2)){
			puts("OK");
			b1.insert(x1);
			b2.insert(x2);
		}
		else puts("WRONG");
	}
	return 0;
}

码风太丑不喜勿喷(

原文
存档评论4 条抓取于