https://codeforces.com/contest/1080/problem/E
比赛时候一个多小时码不出来。。。
来看遇到的困难:
1.没有能用的随机unsignedlonglong函数
来一个可以A题的:
ull splitmix64(ull x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } ull rd() { static ull x=splitmix64(chrono::steady_clock::now().time_since_epoch().count()); return splitmix64(x=x*6364136223846793005ull+1442695040888963407ull); }
2.不会马拉车
以后学。。以下代码的马拉车(calc函数)是网上找的
1 #include<cstdio> 2 #include<algorithm> 3 #include<cstring> 4 #include<vector> 5 #include<chrono> 6 #include<cstdlib> 7 using namespace std; 8 #define fi first 9 #define se second 10 #define mp make_pair 11 #define pb push_back 12 typedef long long ll; 13 typedef unsigned long long ull; 14 typedef pair<int,int> pii; 15 16 ull cpy[10001]; 17 int rad[10001]; 18 19 ull splitmix64(ull x) { 20 x += 0x9e3779b97f4a7c15; 21 x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; 22 x = (x ^ (x >> 27)) * 0x94d049bb133111eb; 23 return x ^ (x >> 31); 24 } 25 ull rd() 26 { 27 static ull x=splitmix64(chrono::steady_clock::now().time_since_epoch().count()); 28 return splitmix64(x=x*6364136223846793005ull+1442695040888963407ull); 29 } 30 31 void manacher(ull str[], int rad[], int len) { 32 for (int i=1,j=0,k; i < len; i+=k,j-=k) { 33 while (str[i-j-1] == str[i+j+1]) ++j; 34 rad[i] = j; 35 for (k=1; k<=j && rad[i-k]!=rad[i]-k; ++k) { 36 rad[i+k] = min(rad[i-k], rad[i]-k); 37 } 38 } 39 } 40 41 ll calc(const ull *seq,int len) 42 { 43 //for(int i=0;i<len;++i) 44 // printf("1t%llu ",seq[i]); 45 ull t1,t2,t3; 46 while(1) 47 { 48 t1=rd();t2=rd();t3=rd(); 49 if(t1==t2||t1==t3||t2==t3) continue; 50 for(int i=0;i<len;++i) 51 if(t1==seq[i]||t2==seq[i]||t3==seq[i]) 52 continue; 53 break; 54 } 55 cpy[0] = t1, cpy[1] = t2; 56 for (int i=2,j=0; j < len; i+=2,++j) { 57 cpy[i] = seq[j]; 58 cpy[i+1] = t2; 59 } 60 len = len*2+3; 61 cpy[len-1] = t3; 62 manacher(cpy, rad, len); 63 ll ret = 0; 64 for (int i = 2; i < len-2; ++i) { 65 ret += (rad[i]+1) / 2; 66 } 67 //printf("2t%lld ",ret); 68 return ret; 69 } 70 71 ull bs,bss[]={2477,5227,2503,2521,2531,2539}; 72 ull pwx[101]; 73 ull st[1010];int tp; 74 struct CharSet 75 { 76 int num[26],odd; 77 ull hs; 78 void add(int c) 79 { 80 ++num[c]; 81 odd^=(1<<c); 82 hs+=pwx[c]; 83 } 84 void del(int c) 85 { 86 --num[c]; 87 odd^=(1<<c); 88 hs-=pwx[c]; 89 } 90 void clear() 91 { 92 memset(num,0,sizeof(num)); 93 odd=0; 94 hs=0; 95 } 96 }cs[255]; 97 ll ans; 98 bool ok[260]; 99 int n,m; 100 int to[260]; 101 char s[260][260]; 102 int main() 103 { 104 int i,j,l,r; 105 bs=bss[rd()%6]; 106 //printf("1t%llu ",bs); 107 pwx[0]=1; 108 for(i=1;i<=100;++i) 109 pwx[i]=pwx[i-1]*bs; 110 //n=250;m=250; 111 scanf("%d%d",&n,&m); 112 for(i=1;i<=n;++i) 113 { 114 scanf("%s",s[i]+1); 115 //for(j=1;j<=m;++j) 116 // s[i][j]=rand()%3+'a'; 117 } 118 for(l=1;l<=m;++l) 119 { 120 for(i=1;i<=n;++i) 121 cs[i].clear(); 122 for(r=l;r<=m;++r) 123 { 124 for(i=1;i<=n;++i) 125 cs[i].add(s[i][r]-'a'); 126 if((r-l+1)&1) 127 { 128 for(i=1;i<=n;++i) 129 { 130 to[i]=__builtin_ffs(cs[i].odd)-1; 131 cs[i].del(to[i]); 132 } 133 } 134 for(i=1;i<=n;++i) 135 ok[i]=!cs[i].odd; 136 if((r-l+1)&1) 137 { 138 for(i=1;i<=n;++i) 139 cs[i].add(to[i]); 140 } 141 //printf("3t%d %d ",l,r); 142 //for(i=1;i<=n;++i) 143 // printf("4t%llu ",cs[i].hs); 144 for(i=1;i<=n;++i) 145 if(ok[i]) 146 { 147 tp=0; 148 j=i;st[++tp]=cs[i].hs; 149 while(j+1<=n&&ok[j+1]) 150 { 151 ++j; 152 st[++tp]=cs[j].hs; 153 } 154 ans+=calc(st+1,tp); 155 i=j; 156 } 157 //printf("5t%lld ",ans); 158 } 159 } 160 printf("%lld ",ans); 161 return 0; 162 }