(RERERERERERERERERERERE) BZOJ 2746: [HEOI2012]旅行问题
二次联通门 : BZOJ 2746: [HEOI2012]旅行问题
神TM STL的vector push_back进一个数后取出时就变成了一个很小的负数。。
调不出来了, 不调了
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue> #define Max 100 #define Mod 1000000007LL void read (int &now)
{
now = ;
register char word = getchar ();
while (word < '' || word > '')
word = getchar ();
while (word >= '' && word <= '')
{
now = now * + word - '';
word = getchar ();
}
} int N, M; struct T_D
{ T_D *child[]; T_D *Fail;
int number; long long value; T_D ()
{
for (int i = ; i < ; i ++)
this->child[i] = NULL; Fail = NULL;
value = ;
number = ;
}
}; inline int swap (int &x, int &y)
{
int now = x;
x = y;
y = now; } std :: vector <int> List[Max << ]; T_D *map[Max]; class Tree_Chain_Get_Type
{ private : int size[Max];
int deep[Max]; int father[Max]; int __to[Max];
int __next[Max]; int Edge_Count;
int edge_list[Max]; int top[Max];
int Count; public : inline void Add_Edge (int from, int to)
{
Edge_Count ++; __to[Edge_Count] = to;
__next[Edge_Count] = edge_list[from];
edge_list[from] = Edge_Count; Edge_Count ++;
__to[Edge_Count] = from;
__next[Edge_Count] = edge_list[to];
edge_list[to] = Edge_Count; } void Dfs_1 (int now, int __father)
{ int pos = Count ++; deep[now] = deep[__father] + ;
father[now] = __father; for (int i = edge_list[now]; i; i = __next[i])
if (__to[i] != __father)
Dfs_1 (__to[i], now); size[now] = Count - pos;
} void Dfs_2 (int now, int chain)
{
int pos = ;
top[now] = chain; for (int i = edge_list[now]; i; i = __next[i])
if (__to[i] != father[now] && size[pos] < size[__to[i]])
pos = __to[i]; if (!pos)
return ;
Dfs_2 (pos, chain);
for (int i = edge_list[now]; i; i = __next[i])
if (__to[i] != father[now] && __to[i] != pos)
Dfs_2 (__to[i], __to[i]);
} int Get_Lca (int x, int y)
{
for (; top[x] != top[y]; x = father[top[x]])
if (deep[top[x]] < deep[top[y]])
swap (x, y); return deep[x] < deep[y] ? x : y;
} inline void Prepare ()
{
Count = ;
Dfs_1 (, );
Count = ;
Dfs_2 (, );
Count = ;
}
}; Tree_Chain_Get_Type Make; class AC_Type
{ private : T_D *Root;
int Count; public : AC_Type ()
{
Root = new T_D;
Count = ;
Root->number = ++ Count;
map[Root->number] = Root;
} void Insert (char *key)
{
T_D *now = Root, *pos; int Len = strlen (key); int Id;
for (int i = ; i < Len; i ++)
{
Id = key[i] - 'a';
if (now->child[Id] == NULL)
{
now->child[Id] = new T_D;
now->child[Id]->number = ++ Count;
map[Count] = now->child[Id];
now->child[Id]->value = (now->value * 26LL + Id) % Mod;
}
List[i].push_back (now->child[Id]->number);
now = now->child[Id];
}
} void Build_AC ()
{
std :: queue <T_D *> Queue; Queue.push (Root);
T_D *now, *pos;
while (!Queue.empty ())
{
now = Queue.front ();
Queue.pop (); pos = NULL; for (int i = ; i < ; i ++)
{
if (now->child[i] == NULL)
continue;
if (now == Root)
now->child[i]->Fail = Root;
else
{
for (pos = now->Fail; pos; pos = pos->Fail)
if (pos->child[i])
{
now->child[i]->Fail = pos->child[i];
break;
}
if (pos == NULL)
now->child[i]->Fail = Root;
}
Queue.push (now->child[i]);
Make.Add_Edge (now->child[i]->number, now->child[i]->Fail->number);
}
}
} }; AC_Type AC; char line[Max]; int main (int argc, char *argv[])
{
int x, y; read (N); for (int i = ; i <= N; i ++)
{
scanf ("%s", line);
AC.Insert (line);
} AC.Build_AC (); Make.Prepare ();
int x_1, y_1, x_2, y_2; for (read (M); M --; )
{
read (x_1);
read (y_1);
read (x_2);
read (y_2); int now = Make.Get_Lca (List[x_1][y_1 - ], List[x_2][y_2 - ]);
printf ("%lld\n", map[now]->value);
} return ;
}
(RERERERERERERERERERERE) BZOJ 2746: [HEOI2012]旅行问题的更多相关文章
- bzoj 2746: [HEOI2012]旅行问题 AC自动机fail树
2746: [HEOI2012]旅行问题 Time Limit: 30 Sec Memory Limit: 256 MBSubmit: 489 Solved: 174[Submit][Status ...
- BZOJ 2746: [HEOI2012]旅行问题
2746: [HEOI2012]旅行问题 Time Limit: 30 Sec Memory Limit: 256 MBSubmit: 921 Solved: 291[Submit][Status ...
- [bzoj2746][HEOI2012]旅行问题 _AC自动机_倍增
[HEOI2012]旅行问题 题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=2746 题解: 这个是讲课时候的题. 讲课的时候都在想怎么后 ...
- AC日记——[HEOI2012]旅行问题 bzoj 2746
2746 思路: 建立ac自动机,然后把fail树抽出来: 然后在fail树上走lca(神奇): 代码: #include <cstdio> #include <vector> ...
- 旅行问题(bzoj 2746)
Description yz是Z国的领导人,他规定每个地区的名字只能为26个小写拉丁字母的一个.由于地 区数有可能超过26个,便产生了一个问题,如何辨别名字相同的地区?于是yz规定,一个 地区的描述必 ...
- BZOJ 3091: 城市旅行 [LCT splay 期望]
3091: 城市旅行 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1454 Solved: 483[Submit][Status][Discuss ...
- BZOJ 3531 [Sdoi2014]旅行 树链剖分+动态开点线段树
题意 S国有N个城市,编号从1到N.城市间用N-1条双向道路连接,满足从一个城市出发可以到达其它所有城市.每个城市信仰不同的宗教,如飞天面条神教.隐形独角兽教.绝地教都是常见的信仰. 为了方便,我们用 ...
- BZOJ 3531: [Sdoi2014]旅行 [树链剖分]
3531: [Sdoi2014]旅行 Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 1685 Solved: 751[Submit][Status] ...
- BZOJ 2743: [HEOI2012]采花
2743: [HEOI2012]采花 Time Limit: 15 Sec Memory Limit: 128 MBSubmit: 2056 Solved: 1059[Submit][Status ...
随机推荐
- (二十五)JSP九大内置对象(转)
--转载自孤傲苍狼博客 一.JSP运行原理 每个JSP 页面在第一次被访问时,WEB容器都会把请求交给JSP引擎(即一个Java程序)去处理.JSP引擎先将JSP翻译成一个_jspServlet(实质 ...
- 重装win7后如何恢复ubuntu引导
在重装系统之后,开机启动界面的ubuntu引导不见了,直接进入新安装的window系统中.下面是如何恢复ubuntu引导的方法: 1)准备一张ubuntu系统安装盘: 2)将ubuntu系统安装盘放入 ...
- 英特尔vPro博锐技术激活
英特尔vPro博锐技术激活 参考: Intel官方Management Engine BIOS Extension (Intel®MEBX)手册:http://www.intel.com/conten ...
- luogu题解P1967货车运输--树链剖分
题目链接 https://www.luogu.org/problemnew/show/P1967 分析 NOIp的一道裸题,直接在最大生成树上剖分取最小值一下就完事了,非常好写,常数也比较小,然而题解 ...
- vagrant 搭建开发环境
虚拟机盒子地址 https://app.vagrantup.com/boxes/search vagrant init hirocom/centos7.2vagrant up 修改配置 config. ...
- 阿里P7告诉你什么是java并发包、线程池、锁
并发包 java.util.concurrent从jdk1.5开始新加入的一个包,致力于解决并发编程的线程安全问题,使用户能够更为快捷方便的编写多线程情况下的并发程序. 同步容器 同步容器只有包括Ve ...
- vue 的虚拟 DOM 有什么好处?
vue 中的虚拟DOM有什么好处?快! 首先了解浏览器显示网页经历的5个过程 1.解析标签,生成元素树(DOM树) 2.解析样式,生成样式树 3.生成元素与样式的关系 4.生成元素的显示坐标 5.显示 ...
- Jupyter notebook部署引导
一.简介方面很多博客写得比较好,主要转发几篇: 1.对Jupyter notebook 的整体进行介绍: https://www.itcodemonkey.com/article/6025.html ...
- Cannot debug in IntellijIdea on Linux
OS: Deepin LinuxIDE: Intellij IdeaProject: SpringBoot based maven project Issue: cannot debug in Ide ...
- 目标检测---搬砖一个ALPR自动车牌识别的环境
目标检测---搬砖一个ALPR自动车牌识别的环境 参考License Plate Detection and Recognition in Unconstrained Scenarios@https: ...