LOJ#2303. 「NOI2017」蚯蚓排队
$n \leq 200000$的$1 \leq a_i \leq 6$的蚯蚓,有三种操作:让一只队头蚯蚓接在一只队尾蚯蚓后面;让一队蚯蚓从某个蚯蚓后面断成两队;问:给个字符串,问他的。。算了你们直接看题吧


这什么沙雕题QAQ
所有询问的串只有$nk$种,把他们全丢进hash里面就好了。。注意双hash,一个用来当链表一个用来在链表里判重。
复杂度的话,只考虑合并是$nk$的(相当于把所有串算一次),而拆分是$ck^2$的,拆对合并的复杂度影响是跟拆本身复杂度一样的。
//#include<iostream>
#include<cstring>
#include<cstdio>
//#include<math.h>
//#include<set>
//#include<queue>
//#include<bitset>
//#include<vector>
#include<algorithm>
#include<stdlib.h>
using namespace std; #define LL long long
int qread()
{
char c; int s=,f=; while ((c=getchar())<'' || c>'') (c=='-') && (f=-);
do s=s*+c-''; while ((c=getchar())>='' && c<=''); return s*f;
} //Pay attention to '-' , LL and double of qread!!!! int n,m;
#define maxn 200011
#define maxh 1000007
int a[maxn],bb[]; LL cc[]; struct Hash
{
struct Edge{LL to; int v,next;}edge[maxn*]; int first[maxh],le;
Hash() {le=;}
void in(LL x,int h,int v)
{
for (int i=first[h];i;i=edge[i].next)
{
Edge &e=edge[i];
if (e.to==x) {e.v+=v; return;}
}
Edge &e=edge[le]; e.to=x; e.v=; e.next=first[h]; first[h]=le++;
}
int find(LL x,int h)
{
for (int i=first[h];i;i=edge[i].next)
{
Edge &e=edge[i];
if (e.to==x) return e.v;
}
return ;
}
}h; int Nxt[maxn],Pre[maxn];
char s[maxn*]; int len;
int main()
{
bb[]=; for (int i=;i<=;i++) bb[i]=bb[i-]*%maxh;
cc[]=; for (int i=;i<=;i++) cc[i]=cc[i-]*;
n=qread(); m=qread();
for (int i=;i<=n;i++) {Pre[i]=Nxt[i]=; a[i]=qread(); h.in(a[i],a[i],);}
int op; char c; int x,y;
while (m--)
{
op=qread();
if (op==)
{
x=qread(); y=qread();
Nxt[x]=y; Pre[y]=x;
LL B=,C=;
for (int i=x,cnt=,w=;cnt && i;i=Pre[i],w++,cnt--)
{
B=(B+1ll*a[i]*bb[w])%maxh;
C=C+1ll*a[i]*cc[w];
LL nb=B,nc=C;
for (int j=y,k=;j && k<=cnt;j=Nxt[j],k++)
{
nb=(nb*+a[j])%maxh;
nc=nc*+a[j];
h.in(nc,nb,);
}
}
}
else if (op==)
{
x=qread(); y=Nxt[x];
Nxt[x]=; Pre[y]=;
LL B=,C=;
for (int i=x,cnt=,w=;cnt && i;i=Pre[i],w++,cnt--)
{
B=(B+1ll*a[i]*bb[w])%maxh;
C=C+1ll*a[i]*cc[w];
LL nb=B,nc=C;
for (int j=y,k=;j && k<=cnt;j=Nxt[j],k++)
{
nb=(nb*+a[j])%maxh;
nc=nc*+a[j];
h.in(nc,nb,-);
}
}
}
else if (op==)
{
len=;
while ((c=getchar())<'' || c>'');
do s[++len]=c; while ((c=getchar())>='' && c<='');
x=qread();
LL B=,C=;
for (int i=;i<x;i++) B=(B*+s[i]-'')%maxh,C=C*+s[i]-'';
int ans=;
for (int i=x;i<=len;i++)
{
B=(B*+s[i]-'')%maxh; C=C*+s[i]-'';
ans=1ll*ans*h.find(C,B)%;
B=(B-(s[i-x+]-'')*bb[x-])%maxh+maxh; B%=maxh;
C=C-(s[i-x+]-'')*cc[x-];
}
printf("%d\n",ans);
}
}
return ;
}
LOJ#2303. 「NOI2017」蚯蚓排队的更多相关文章
- LOJ 2303 「NOI2017」蚯蚓排队——链表+哈希表
题目:https://loj.ac/problem/2303 想到合并的时候可以只考虑接口附近的50个,但不太会分析复杂度,而且没有清楚地想到用哈希值对应个数. 看了题解才会…… 一直想用 splay ...
- LOJ2303 「NOI2017」蚯蚓排队
「NOI2017」蚯蚓排队 题目描述 蚯蚓幼儿园有$n$只蚯蚓.幼儿园园长神刀手为了管理方便,时常让这些蚯蚓们列队表演. 所有蚯蚓用从$1$到$n$的连续正整数编号.每只蚯蚓的长度可以用一个正整数表示 ...
- 「NOI2017」蚯蚓排队 解题报告
「NOI2017」蚯蚓排队 这题真的草 你考虑\(k\)这么小,每次合并两个串,增加的有用串的数量是\(O(k^2)\)的,暴力加入这些串,求一下这些串的Hash值,塞到Hash表里面去 这里采用类似 ...
- loj #2305. 「NOI2017」游戏
#2305. 「NOI2017」游戏 题目描述 小 L 计划进行 nnn 场游戏,每场游戏使用一张地图,小 L 会选择一辆车在该地图上完成游戏. 小 L 的赛车有三辆,分别用大写字母 AAA.BBB. ...
- loj#2305. 「NOI2017」游戏 2-sat
链接 https://loj.ac/problem/2305 https://www.luogu.org/problemnew/show/P3825 思路 3-sat神马的就不要想了,NP问题 除去x ...
- LOJ 2304 「NOI2017」泳池——思路+DP+常系数线性齐次递推
题目:https://loj.ac/problem/2304 看了各种题解…… \( dp[i][j] \) 表示有 i 列.第 j 行及以下默认合法,第 j+1 行至少有一个非法格子的概率,满足最大 ...
- LOJ 2302 「NOI2017」整数——压位线段树
题目:https://loj.ac/problem/2302 压30位,a最多落在两个位置上,拆成两次操作. 该位置加了 a 之后,如果要进位或者借位,查询一下连续一段 0 / 1 ,修改掉,再在含有 ...
- *LOJ#2306. 「NOI2017」蔬菜
$n \leq 100000$种蔬菜,每个蔬菜有:一单位价格:卖第一单位时额外价格:总量:每天腐烂量.每天能卖$m \leq 10$单位蔬菜,多次询问:前$k \leq 100000$天最多收入多少. ...
- LOJ#2307. 「NOI2017」分身术
$n \leq 100000$个点,$m \leq 100000$次询问,每次问删掉一些点后的凸包面积. 不会啦写个20暴力,其实是可以写到50的.当个计算几何板子练习. //#include< ...
随机推荐
- windows系统下的两个批处理命令
启动应用:***.exe 关闭应用:taskkill /f /im ***.exe 保存为.bat文件
- python入门:while 循环的基本用法
#!/usr/bin/env python # -*- coding:utf-8 -*- #while 循环的作用 import time while True: ") time.sleep ...
- MySQL如何复制一个表
MySQL如何复制一个表 1 复制 employee 表 => employee2 () create table employee2 like employee () insert into ...
- phpstudy2016+phpstorm2017-3+xdebug+chrome
1. 勾选Xdebug 后 phpstudy 会自动重启服务 [XDebug] xdebug.profiler_output_dir="D:\phpStudy\tmp\xdebug" ...
- 什么是python中的元类
所属网站分类: python高级 > 面向对象 作者:goodbody 原文链接: http://www.pythonheidong.com/blog/article/11/ 来源:python ...
- leetcode-21-knapsack
322. Coin Change Write a function to compute the fewest number of coins that you need to make up tha ...
- POJ:3020-Antenna Placement(二分图的最小路径覆盖)
原题传送:http://poj.org/problem?id=3020 Antenna Placement Time Limit: 1000MS Memory Limit: 65536K Descri ...
- HDU 5396 区间DP 数学 Expression
题意:有n个数字,n-1个运算符,每个运算符的顺序可以任意,因此一共有 (n - 1)! 种运算顺序,得到 (n - 1)! 个运算结果,然后求这些运算结果之和 MOD 1e9+7. 分析: 类比最优 ...
- dedecms 建站相关问题
1.栏目新建文章提示:模板文件不存在,无法解析文档! 解决方法:把模板文件使用".html"的格式 /include/arc.archives.class.php 556行 if ...
- Selenium WebDriver- 操作frame中的页面元素
#encoding=utf-8 import unittest import time from selenium import webdriver from selenium.webdriver i ...