Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- array <int, 4> mod;
- struct elem{
- int type; // 1 = number, 2 = string
- ll number1;
- string string2;
- void checkMod(){
- if (!mod[0]){
- mod[0] = 998244353; mod[1] = 999995993; mod[2] = 999996989; mod[3] = 999999067;
- }
- }
- elem(): type(0) {
- checkMod();
- }
- elem(ll number1): type(1), number1(number1) {
- checkMod();
- }
- elem(string string2): type(2), string2(string2) {
- checkMod();
- }
- array <int, 4> hashValue(){
- assert(type != 0);
- array <int, 4> ansHashValue;
- if (type == 1){
- For(i, 0, 4){
- ansHashValue[i] = number1 % mod[i];
- if (ansHashValue[i] < 0) ansHashValue[i] += mod[i];
- }
- }
- else if (type == 2){
- For(i, 0, 4){
- ansHashValue[i] = 0;
- For(j, 0, isz(string2)){
- ansHashValue[i] = ((ll)ansHashValue[i] * 256 + string2[j]) % mod[i];
- }
- }
- }
- return ansHashValue;
- }
- };
- array <int, 4> hashValue(elem a){
- return a.hashValue();
- }
- array <int, 4> hashValue(vector <elem> a){
- array <int, 4> ansHashValue;
- vector <array <int, 4>> aHashValue;
- For(j, 0, isz(a)){
- aHashValue[j] = a[j].hashValue();
- }
- For(i, 0, 4){
- ansHashValue[i] = 0;
- For(j, 0, isz(a)){
- ansHashValue[i] ^= aHashValue[j][i] * j;
- }
- }
- return ansHashValue;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement