https://codeforces.com/contest/1080/problem/E

比赛时候一个多小时码不出来。。。

来看遇到的困难:

1.没有能用的随机unsignedlonglong函数

来一个可以A题的:

ull splitmix64(ull x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> )) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> )) * 0x94d049bb133111eb;
return x ^ (x >> );
}
ull rd()
{
static ull x=splitmix64(chrono::steady_clock::now().time_since_epoch().count());
return splitmix64(x=x*6364136223846793005ull+1442695040888963407ull);
}

2.不会马拉车

以后学。。以下代码的马拉车(calc函数)是网上找的

 #include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<chrono>
#include<cstdlib>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii; ull cpy[];
int rad[]; ull splitmix64(ull x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> )) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> )) * 0x94d049bb133111eb;
return x ^ (x >> );
}
ull rd()
{
static ull x=splitmix64(chrono::steady_clock::now().time_since_epoch().count());
return splitmix64(x=x*6364136223846793005ull+1442695040888963407ull);
} void manacher(ull str[], int rad[], int len) {
for (int i=,j=,k; i < len; i+=k,j-=k) {
while (str[i-j-] == str[i+j+]) ++j;
rad[i] = j;
for (k=; k<=j && rad[i-k]!=rad[i]-k; ++k) {
rad[i+k] = min(rad[i-k], rad[i]-k);
}
}
} ll calc(const ull *seq,int len)
{
//for(int i=0;i<len;++i)
// printf("1t%llu\n",seq[i]);
ull t1,t2,t3;
while()
{
t1=rd();t2=rd();t3=rd();
if(t1==t2||t1==t3||t2==t3) continue;
for(int i=;i<len;++i)
if(t1==seq[i]||t2==seq[i]||t3==seq[i])
continue;
break;
}
cpy[] = t1, cpy[] = t2;
for (int i=,j=; j < len; i+=,++j) {
cpy[i] = seq[j];
cpy[i+] = t2;
}
len = len*+;
cpy[len-] = t3;
manacher(cpy, rad, len);
ll ret = ;
for (int i = ; i < len-; ++i) {
ret += (rad[i]+) / ;
}
//printf("2t%lld\n",ret);
return ret;
} ull bs,bss[]={,,,,,};
ull pwx[];
ull st[];int tp;
struct CharSet
{
int num[],odd;
ull hs;
void add(int c)
{
++num[c];
odd^=(<<c);
hs+=pwx[c];
}
void del(int c)
{
--num[c];
odd^=(<<c);
hs-=pwx[c];
}
void clear()
{
memset(num,,sizeof(num));
odd=;
hs=;
}
}cs[];
ll ans;
bool ok[];
int n,m;
int to[];
char s[][];
int main()
{
int i,j,l,r;
bs=bss[rd()%];
//printf("1t%llu\n",bs);
pwx[]=;
for(i=;i<=;++i)
pwx[i]=pwx[i-]*bs;
//n=250;m=250;
scanf("%d%d",&n,&m);
for(i=;i<=n;++i)
{
scanf("%s",s[i]+);
//for(j=1;j<=m;++j)
// s[i][j]=rand()%3+'a';
}
for(l=;l<=m;++l)
{
for(i=;i<=n;++i)
cs[i].clear();
for(r=l;r<=m;++r)
{
for(i=;i<=n;++i)
cs[i].add(s[i][r]-'a');
if((r-l+)&)
{
for(i=;i<=n;++i)
{
to[i]=__builtin_ffs(cs[i].odd)-;
cs[i].del(to[i]);
}
}
for(i=;i<=n;++i)
ok[i]=!cs[i].odd;
if((r-l+)&)
{
for(i=;i<=n;++i)
cs[i].add(to[i]);
}
//printf("3t%d %d\n",l,r);
//for(i=1;i<=n;++i)
// printf("4t%llu\n",cs[i].hs);
for(i=;i<=n;++i)
if(ok[i])
{
tp=;
j=i;st[++tp]=cs[i].hs;
while(j+<=n&&ok[j+])
{
++j;
st[++tp]=cs[j].hs;
}
ans+=calc(st+,tp);
i=j;
}
//printf("5t%lld\n",ans);
}
}
printf("%lld\n",ans);
return ;
}

Sonya and Matrix Beauty Codeforces - 1080E的更多相关文章

  1. Sonya and Matrix Beauty CodeForces - 1080E (manacher)

    大意: 给定$nm$字符串矩阵. 若一个子矩形每一行重排后可以满足每行每列都是回文, 那么它为好矩形. 求所有好矩形个数. 一个矩形合法等价于每一行出现次数为奇数的最多只有一个字符, 并且对称的两行对 ...

  2. 【题解】Sonya and Matrix Beauty [Codeforces1080E]

    [题解]Sonya and Matrix Beauty [Codeforces1080E] 传送门:\(Sonya\) \(and\) \(Matrix\) \(Beauty\) \([CF1080E ...

  3. Codeforces Round #524 (Div. 2) E. Sonya and Matrix Beauty(字符串哈希,马拉车)

    https://codeforces.com/contest/1080/problem/E 题意 有一个n*m(<=250)的字符矩阵,对于每个子矩阵的每一行可以任意交换字符的顺序,使得每一行每 ...

  4. codeforces 495D Sonya and Matrix

    Since Sonya has just learned the basics of matrices, she decided to play with them a little bit. Son ...

  5. Codeforces Round #495 (Div. 2) D. Sonya and Matrix

    http://codeforces.com/contest/1004/problem/D 题意: 在n×m的方格中,选定一个点(x,y)作为中心点,该点的值为0,其余点的值为点到中心点的曼哈顿距离. ...

  6. Sonya and Matrix CodeForces - 1004D (数学,构造)

    http://codeforces.com/contest/1004/problem/D 题意:网格图给定到中心点的曼哈顿距离数组, 求该图n,m及中心点位置 首先可以观察到距离最大值mx一定在某个角 ...

  7. Codeforces Round #495 (Div. 2) Sonya and Matrix

    正常没有正方形的限制下,值为i的点个数4i 那么从0开始遍历,第一个不为4i的值就是min(x, y) 由于对称性我们姑且令x为这个值 我们先列举n*m=t的各种情况 对于一对n, m.我们已经知道n ...

  8. Sonya and Robots(CodeForces 1004C)

    Since Sonya is interested in robotics too, she decided to construct robots that will read and recogn ...

  9. D. Vasya And The Matrix(Educational Codeforces Round 48)

    D. Vasya And The Matrix time limit per test2 seconds memory limit per test256 megabytes inputstandar ...

随机推荐

  1. RQNOJ 622 最小重量机器设计问题:dp

    题目链接:https://www.rqnoj.cn/problem/622 题意: 一个机器由n个部件组成,每一种部件都可以从m个不同的供应商处购得. w[i][j]是从供应商j处购得的部件i的重量, ...

  2. jenkins maven tomcat做持续集成

    maven 采用 maven 3.0以上的版本.tomcat 采用 tomcat 7.0 以上的版本 1. tomcat 配置用户账号和权限 tomcat-users.xml <role rol ...

  3. X-Forward-For ip

    用 Firefox 的Moify Headers 插件 服务器重新配置X-Forward-For 为正确的值. 如对典型的nginx + php fastcgi 环境( nginx 与 php fas ...

  4. 1087 All Roads Lead to Rome (30)(30 分)

    Indeed there are many different tourist routes from our city to Rome. You are supposed to find your ...

  5. bzoj1177&p3625 [APIO2009]采油区域p[大力讨论]

    我好菜菜啊. 给定矩形,从中选出三个边长K的正方形互不重叠,使得覆盖到的数总和最大. 想的时候往dp上钻去了..结果一开始想了一个错的dp,像这样 /************************* ...

  6. 洛谷P2024食物链——并查集补集的灵活运用

    题目:https://www.luogu.org/problemnew/show/P2024 自己在做本题时最大的障碍就是:不会在一个集合的father改变时把相应的补集也跟着改变. 借鉴题解后,才明 ...

  7. JVM中的Hello World运行机制:

    栗子: package zagoo; public class HelloWorld { public static String HELLOWORLD="Hello World" ...

  8. JavaScript高级程序设计学习笔记第二章

    1.向 HTML 页面中插入 JavaScript 的主要方法,就是使用<script>元素 2.HTML 4.01中定义了<script>元素的六个属性(方便记忆,可将6个属 ...

  9. 面试题: mysql数据库 已看1 索引和事务 没用

    mysql数据库面试总结 2017年09月04日 00:11:40 阅读数:151 结合网上大神还有自己面试经历,收集的总结Mysql面试题,方便自己准备面试: mysql一个永远都复习不完,尽量总结 ...

  10. 玩转 React 服务器端渲染

    React 提供了两个方法 renderToString 和 renderToStaticMarkup 用来将组件(Virtual DOM)输出成 HTML 字符串,这是 React 服务器端渲染的基 ...