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. Cocos2d-x中定时器的使用

    CCTimer:轻量级的计时器 CCTimer (void) ccTime  getInterval (void) void  setInterval (ccTime fInterval) bool  ...

  2. 分享知识-快乐自己:Struts2中 获取 Request和Session

    目录结构: POM: <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEnco ...

  3. ES搜索排序,文档相关度评分介绍——Vector Space Model

    Vector Space Model The vector space model provides a way of comparing a multiterm query against a do ...

  4. C语言中的指针(一)

    指针也是一种数据类型,占用内存空间,内存中存储的只能是变量的地址. *p是操作内存的意思,在声明成为指针变量的时候使用*,在使用指针的时候,*表示操作内存. *p放在等号的左边,相当于是从内存中取值, ...

  5. POI2014

    ...一个shabi和一堆神题的故事 今天只写了两道 之后随缘更吧 啊 顺便 snake我是不会更的 bzoj3829 POI2014 Farmcraft mhy住在一棵有n个点的树的1号结点上,每个 ...

  6. java.lang.NoSuchMethodException: cn.pb.bean.Category.<init>()报错

    代码如下: package cn.pb.bean; import java.util.ArrayList;import java.util.List; /** * 分类的实体类 */public cl ...

  7. C++多态的实现条件

    #include <iostream> class Person{ public: virtual void say(){ std::cout<<"person&qu ...

  8. /etc/bashrc和/etc/profile

    在一般的 linux 或者 unix 系统中, 都可以通过编辑 bashrc 和 profile来设置用户的工作环境, 很多文章对于 profile 和 bashrc 也都有使用, 但究竟每个文件都有 ...

  9. java-并发-进程和线程

    浏览以下内容前,请点击并阅读 声明 软件的并发是指同时做多件事情,java平台一开始就支持并发编程,java编程语言以及类库含有对并发最基本的支持,从5.0版本开始,java平台开始包含一些高并发的A ...

  10. day1 java基础回顾-泛型

    2.泛型(Generic) 当集合中存储的对象类型不同时,那么会导致程序在运行的时候的转型异常 1 import java.util.ArrayList; 2 import java.util.Ite ...