bzoj 4516 生成魔咒
来源:互联网 发布:网络招聘司机 编辑:程序博客网 时间:2024/05/04 16:21
因为SAM增量法构造的特点,所以每一次增加节点计算就可以了
因为SAM的转移是线性的,所以开个map也是兹辞的
#include<bits/stdc++.h>using namespace std;const int maxn = 112345;struct Node{ int len,fa; map<int,int> nex; Node(int _len = 0){ len = _len; fa = 0; nex.clear(); } void copy(const Node & v){ nex = v.nex; fa = v.fa; } bool exist(int x){ return nex.find(x) != nex.end(); }}node[maxn*2]; int _cnt;int newNode(int len){ node[_cnt] = Node(len); return _cnt++;}int root,omg;void init(){ _cnt = 1; root = omg = newNode(0);}void extend(int x){ int ox = newNode(node[omg].len+1); while(omg && !node[omg].exist(x)){ node[omg].nex[x] = ox; omg = node[omg].fa; } if(!omg) node[ox].fa = root; else{ int omgx = node[omg].nex[x]; if(node[omg].len + 1 == node[omgx].len) node[ox].fa = omgx; else{ int ax = newNode(node[omg].len+1); node[ax].copy(node[omgx]); node[ox].fa = node[omgx].fa = ax; while(omg && node[omg].exist(x) && node[omg].nex[x] == omgx){ node[omg].nex[x] = ax; omg = node[omg].fa; } } } omg = ox;}#define LL long long int main(){ int n; while(~scanf("%d",&n)){ LL ans = 0; init(); int x; while(n--){ scanf("%d",&x); extend(x); ans += node[omg].len - node[node[omg].fa].len; printf("%lld\n",ans); } } return 0;}
0 0
- bzoj 4516 生成魔咒
- BZOJ 4516: [Sdoi2016]生成魔咒
- BZOJ 4516: [Sdoi2016]生成魔咒
- BZOJ 4516 [Sdoi2016]生成魔咒
- bzoj 4516 [Sdoi2016]生成魔咒
- bzoj 4516: [Sdoi2016]生成魔咒 后缀数组
- [后缀数组 set] BZOJ 4516 [Sdoi2016]生成魔咒
- bzoj 4516 [Sdoi2016]生成魔咒 后缀自动机
- bzoj 4516: [Sdoi2016]生成魔咒 (后缀自动机)
- 【BZOJ 4516】 [Sdoi2016]生成魔咒 后缀自动机
- bzoj 4516: [Sdoi2016]生成魔咒 后缀数组
- bzoj 2561: 最小生成树
- [bzoj 3193][JLOI2013]地形生成
- BZOJ 1050 最小生成树
- bzoj 1232 最小生成树
- bzoj 3943 最大生成树
- bzoj 5044 岛屿生成 构造
- bzoj 2561: 最小生成树
- 99%的人都理解错了HTTP中GET与POST的区别
- MAVEN多模块打包,自动部署到tomcat
- Android TV Input Framework(TIF)--构建TV input list
- 自己动手实现消息队列之JMS
- C++卷积神经网络实例:tiny_cnn代码详解(8)——partial_connected_layer层结构类分析(上)
- bzoj 4516 生成魔咒
- 【华为OJ】输入n个整数,输出其中最小的k个
- px4飞控源码总结
- hadoop的安装与配置
- 8月31日,主要讲解的是方法和方法的调用
- ORACLE性能优化之SQL语句优化
- SPOJ SUBLEX
- 路由算法总结
- 【C++】使用sstream头文件进行格式转换