Topic Portal
1 /*2 Hash+set: The hash value of each string is stored in the set container first, and then enumerated for each of the strings of each query3 It is not difficult to understand the existence of a replacement string with the Find function of set. In addition, I would like to use the 64-bit natural overflow WA, not clear4 */5 /************************************************6 * Author:running_time7 * Created time:2015-8-5 13:05:498 * File Name:D. cpp9 ************************************************/Ten One#include <cstdio> A#include <algorithm> -#include <iostream> -#include <sstream> the#include <cstring> -#include <cmath> -#include <string> -#include <vector> +#include <queue> -#include <deque> +#include <stack> A#include <list> at#include <map> -#include <Set> -#include <bitset> -#include <cstdlib> -#include <ctime> - using namespacestd; in - #defineLson L, Mid, RT << 1 to #defineRson mid + 1, R, RT << 1 | 1 +typedefLong Longll; - Const intMAXN = 6e5 +Ten; the Const intINF =0x3f3f3f3f; * Const intMOD = 1e9 +7; $ Const intKEY =257;Panax Notoginseng CharS[MAXN]; - Set<ll>S; the ll HA[MAXN]; + intN, M; A the voidInitvoid) { +ha[0] =1; - for(intI=1; i<maxn; ++i) Ha[i] = ha[i-1] * KEY%MOD; $ } $ -ll Get_hash (Char*s) { - intLen =strlen (s); thell res =0; - for(intI=0; i<len; ++i) {Wuyires = (RES * KEY + s[i])%MOD; the } - returnRes; Wu } - About BOOLJudgeChar*s) { $ intLen =strlen (s); -ll h =Get_hash (s); - for(intI=0; i<len; ++i) { - for(LL Ch='a'; ch<='C'; ++ch) { A if(ch = = S[i])Continue; + if(S.find ((((ch-s[i)) * ha[len-i-1] + h)% mod + MoD)% mod)! = S.end ())return true; the } - } $ return false; the } the the intMainvoid) {//codeforces Round #291 (Div. 2) C. Watto and mechanism the init (); - while(SCANF ("%d%d", &n, &m) = =2) { in s.clear (); the for(intI=1; i<=n; ++i) { thescanf ("%s", s); About S.insert (Get_hash (S)); the } the for(intI=1; i<=m; ++i) { thescanf ("%s", s); + if(Judge (s)) puts ("YES"); - ElsePuts ("NO"); the }Bayi } the the return 0; -}
Hash+set codeforces Round #291 (Div. 2) C. Watto and mechanism