[PKUSC2018]神仙的游戏(FFT)
给定一个01?串,对所有len询问是否存在一种填法使存在长度为len的border。
首先有个套路的性质:对于一个长度为len的border,这个字符串一定有长度为n-len的循环节(最后可以不完整)。
逆推得到,如果有一个0位置和一个1位置之差为len,则所有len的因数k的n-k都不可能成为border。
先将b翻转,作差卷起来,然后$O(n\log n)$枚举倍数即可。
$A(x)=x^{n-1}A(\frac 1x)$是作差卷积的本质。
#include<cstdio>
#include<cstring>
#include<algorithm>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
using namespace std; const int N=,mod=,G=;
int n,len,l,a[N],b[N],rev[N],lg[N];
char s[N]; int ksm(int a,int b){
int res=;
for (; b; a=1ll*a*a%mod,b>>=)
if (b & ) res=1ll*res*a%mod;
return res;
} void NTT(int a[],int n,int f){
for (int i=; i<n; i++) if (i<rev[i]) swap(a[i],a[rev[i]]);
for (int i=; i<n; i<<=){
int wn=ksm(G,(f==) ? (mod-)/(i<<) : (mod-)-(mod-)/(i<<));
for (int p=i<<,j=; j<n; j+=p)
for (int w=,k=; k<i; k++,w=1ll*w*wn%mod){
int x=a[j+k],y=1ll*w*a[i+j+k]%mod;
a[j+k]=(x+y)%mod; a[i+j+k]=(x-y+mod)%mod;
}
}
if (f==) return;
int inv=ksm(n,mod-);
for (int i=; i<n; i++) a[i]=1ll*a[i]*inv%mod;
} int main(){
freopen("pkub.in","r",stdin);
freopen("pkub.out","w",stdout);
scanf("%s",s); n=strlen(s);
for (len=; len<=(n<<); len<<=) l++;
for (int i=; i<len; i++) rev[i]=(rev[i>>]>>)|((i&)<<(l-));
for (int i=; i<n; i++) a[i]=s[i]=='',b[i]=s[n-i-]=='';
NTT(a,len,); NTT(b,len,);
for (int i=; i<len; i++) a[i]=1ll*a[i]*b[i]%mod;
NTT(a,len,-);
long long ans=1ll*n*n;
for (int i=; i<n; i++){
int f=;
for (int j=i; j<n; j+=i) if (a[n-j-]|a[n+j-]) { f=; break; }
if (f) ans^=1ll*(n-i)*(n-i);
}
printf("%lld\n",ans);
return ;
}
[PKUSC2018]神仙的游戏(FFT)的更多相关文章
- BZOJ5372: [Pkusc2018]神仙的游戏
BZOJ5372: [Pkusc2018]神仙的游戏 https://lydsy.com/JudgeOnline/problem.php?id=5372 分析: 如果\(len\)为\(border\ ...
- BZOJ5372: PKUSC2018神仙的游戏
传送门 Sol 自己还是太 \(naive\) 了,上来就构造多项式和通配符直接匹配,然后遇到 \(border\) 相交的时候就 \(gg\) 了 神仙的游戏蒟蒻还是玩不来 一个小小的性质: 存在长 ...
- LOJ6436 [PKUSC2018] 神仙的游戏 【FFT】
题目分析: 题目要求前后缀相同,把串反过来之后是一个很明显的卷积的形式.这样我们可以完成初步判断(即可以知道哪些必然不行). 然后考虑一下虽然卷积结果成立,但是存在问号冲突的情况. 箭头之间应当不存在 ...
- bzoj 5372: [Pkusc2018]神仙的游戏
Description 小D和小H是两位神仙.他们经常在一起玩神仙才会玩的一些游戏,比如"口算一个4位数是不是完全平方数". 今天他们发现了一种新的游戏:首先称s长度为len的前缀 ...
- loj 6436 PKUSC2018 神仙的游戏
传送门 好妙蛙 即串\(s\)长度为\(n\)首先考虑如果一个长度为\(len\)的\(border\)存在,当且仅当对所有\(i\in[1,len],s[i]=s[n-len+i]\),也就是所有模 ...
- [PKUSC2018]神仙的游戏
题目 画一画就会发现一些奇诡的性质 首先如果\(len\)为一个\(\operatorname{border}\),那么必然对于\(\forall i\in [1,len]\),都会有\(s_i=s_ ...
- BZOJ5372 PKUSC2018神仙的游戏(NTT)
首先有一个想法,翻转串后直接卷积看有没有0匹配上1.但这是必要而不充分的因为在原串和翻转串中?不能同时取两个值. 先有一些结论: 如果s中长度为len的前缀是border,那么其存在|s|-len的循 ...
- [LOJ6436][PKUSC2018]神仙的游戏
loj description 给你一个只有01和?的字符串,问你是否存在一种把?改成01的方案使串存在一个长度为\(1-n\)的\(border\).\(n\le5\times10^5\) sol ...
- LOJ #6436. 「PKUSC2018」神仙的游戏(字符串+NTT)
题面 LOJ #6436. 「PKUSC2018」神仙的游戏 题解 参考 yyb 的口中的长郡最强选手 租酥雨大佬的博客 ... 一开始以为 通配符匹配 就是类似于 BZOJ 4259: 残缺的字符串 ...
随机推荐
- [NOIP2012] 文化之旅 dfs
这道题就体现了聪明的搜索策略的重要性,如果我们正着搜,判断效率会明显下滑,所以我们就采用倒着搜索.(其实很玄学.....) #include <cstdio> #include <b ...
- Backup and Restore MySQL Database using mysqlhotcopy
mysqlhotcopy is a perl script that comes with MySQL installation. This locks the table, flush the ta ...
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) C (用map 超时)
C. Bear and Colors time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- 用实例工厂的方法实例化bean
在实例化bean时,除了setter,constructor方法外,还有实例工厂方法,和静态工厂方法. 看代码: People类的代码如下: package com.timo.domain; publ ...
- expect 实现本地到远程的scp
expect文件demo 令文件名为test.exp #!/usr/bin/expect -f set timeout -1 set pwd " set src_file [lindex $ ...
- Java并发(10)- 简单聊聊JDK中的七大阻塞队列
引言 JDK中除了上文提到的各种并发容器,还提供了丰富的阻塞队列.阻塞队列统一实现了BlockingQueue接口,BlockingQueue接口在java.util包Queue接口的基础上提供了pu ...
- 河南省第十届省赛 Plumbing the depth of lake (模拟)
title: Plumbing the depth of lake 河南省第十届省赛 题目描述: There is a mysterious lake in the north of Tibet. A ...
- react+redux基础用法
在学react的是,发现一旦我们封装好了我们的组件,那么我们的项目就跟搭积木一样简单快速,可是我们发现了一个问题,在一个页面往往会嵌套很多的组件,子组件必须要通过父组件传递参数才能渲染出数据,我们回想 ...
- 多表查询与pymysql
一.子查询 #1:子查询是将一个查询语句嵌套在另一个查询语句中. #2:内层查询语句的查询结果,可以为外层查询语句提供查询条件. #3:子查询中可以包含:IN.NOT IN.ANY.ALL.EXIST ...
- [Leetcode Week3]Course Schedule
Course Schedule题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/course-schedule/description/ Descript ...