zoukankan      html  css  js  c++  java
  • 【BZOJ3555】 [Ctsc2014]企鹅QQ

    BZOJ3555 [Ctsc2014]企鹅QQ


    Solution

    只需要前缀Hash,然后考虑每一段的贡献就好了!!!

    代码实现

    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    #include<math.h>
    #include<algorithm>
    #include<queue>
    #include<set>
    #include<map>
    #include<iostream>
    using namespace std;
    #define ll long long
    #define re register
    #define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
    inline int gi()
    {
    	int f=1,sum=0;char ch=getchar();
    	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
    	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
    	return f*sum;
    }
    #define ull unsigned long long
    const int N=30010,L=210;
    const ull Base=19260817,Base1=19491001,Base2=23333;
    ull Hash[N][L],tmp[N],pw[L];
    int n,l,S;
    ll ans;
    char s[N];
    void hAsh(int id)
    {
    	for(int i=1;i<=l;i++)
    		Hash[id][i]=Hash[id][i-1]*Base+s[i];
    }
    ull getHash(int id,int l,int r)
    {
    	if(l>r)return 0;
    	return Hash[id][r]-Hash[id][l-1]*pw[r-l+1];
    }
    int main()
    {
    	n=gi();l=gi();S=gi();
    	pw[0]=1;
    	for(int i=1;i<=l;i++)
    		pw[i]=pw[i-1]*Base;
    	for(int i=1;i<=n;i++)
    	{
    		scanf("%s",s+1);
    		hAsh(i);
    	}
    	for(int j=1;j<=l;j++)
    	{
    		for(int i=1;i<=n;i++)tmp[i]=Hash[i][j-1]*pw[l-j]+getHash(i,j+1,l);
    		sort(tmp+1,tmp+n+1);
    		int now=1;
    		for(int i=2;i<=n;i++)
    		{
    			if(tmp[i]==tmp[i-1])ans+=now,now++;
    			else now=1;
    		}
    	}
    	printf("%lld
    ",ans);
    	return 0;
    }
    
  • 相关阅读:
    ES6 随记(1)-- let 与 const
    this 机制的四种规则
    BEM(一种 CSS 命名规则)
    WebSocket 的后记
    WebSocket 初体验
    “空”的艺术-当数据为空时显示什么
    前端路由以及浏览器回退,hash & history & location
    体验 WebFont,网页上的艺术字
    dedecms安装全过程(集成环境)
    面向对象(五)
  • 原文地址:https://www.cnblogs.com/mleautomaton/p/10371029.html
Copyright © 2011-2022 走看看