ACM-ICPC 2018 焦作赛区网络预赛 H、L
https://nanti.jisuanke.com/t/31721
题意 n个位置 有几个限制相邻的三个怎么怎么样,直接从3开始 矩阵快速幂进行递推就可以了
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+,maxn=;
struct Matrix
{
ll m[maxn][maxn];
Matrix()
{
memset(m,,sizeof(m));
}
void init()
{
for(int i=; i<maxn; i++)
for(int j=; j<maxn; j++)
m[i][j]=(i==j);
}
Matrix operator +(const Matrix &b)const
{
Matrix c;
for(int i=; i<maxn; i++)
{
for(int j=; j<maxn; j++)
{
c.m[i][j]=(m[i][j]+b.m[i][j])%mod;
}
}
return c;
}
Matrix operator *(const Matrix &b)const
{
Matrix c;
for(int i=; i<maxn; i++)
{
for(int j=; j<maxn; j++)
{
for(int k=; k<maxn; k++)
{
c.m[i][j]=(c.m[i][j]+(m[i][k]*b.m[k][j])%mod)%mod;
}
}
}
return c;
}
Matrix operator^(const ll &t)const
{
Matrix ans,a=(*this);
ans.init();
ll n=t;
while(n)
{
if(n&) ans=ans*a;
a=a*a;
n>>=;
}
return ans;
}
};
int xishu[][]={
,,,,,,,,,
,,,,,,,,,
,,,,,,,,,
,,,,,,,,,
,,,,,,,,,
,,,,,,,,,
,,,,,,,,,
,,,,,,,,,
,,,,,,,,};
int main()
{
int t;
ll n,m,a,b;
scanf("%d",&t);
while(t--)
{
scanf("%lld",&n);
if(n==)
{
printf("3\n");
continue;
}
if(n==)
{
printf("9\n");
continue;
}
Matrix temp,aa;
for(int i=;i<maxn;i++)
{
for(int j=;j<maxn;j++)
{
temp.m[i][j]=xishu[i][j];
}
}
for(int i=;i<maxn;i++)
aa.m[i][]=;
temp=temp^(n-);
aa=temp*aa;
ll ans=;
for(int i=;i<maxn;i++)
ans=(ans+aa.m[i][])%mod;
cout<<ans<<endl;
}
return ;
}
https://nanti.jisuanke.com/t/31717
解析 傻逼题,数据范围应该是2e5,真是傻逼,被安排的明明白白。存个后缀自动机的板子。
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5+;
typedef long long ll;
char s[maxn];
int len,k,n,m;
char temp[];
struct SAM{
int last,cnt,nxt[maxn*][],fa[maxn*],l[maxn*],num[maxn*];
ll ans;
void init(){
last = cnt=;
memset(nxt[],,sizeof nxt[]);
fa[]=l[]=num[]=;
ans=;
}
int inline newnode(){
cnt++;
memset(nxt[cnt],,sizeof nxt[cnt]);
fa[cnt]=l[cnt]=num[cnt]=;
return cnt;
}
void add(int c){
int p = last;
int np = newnode();
last = np;
l[np] =l[p]+;
while (p&&!nxt[p][c]){
nxt[p][c] = np;
p = fa[p];
}
if (!p){
fa[np] =;
}else{
int q = nxt[p][c];
if (l[q]==l[p]+){
fa[np] =q;
}else{
int nq = newnode();
memcpy(nxt[nq],nxt[q],sizeof nxt[q]);
fa[nq] =fa[q];
num[nq] = num[q];
l[nq] = l[p]+;
fa[np] =fa[q] =nq;
while (nxt[p][c]==q){
nxt[p][c]=nq;
p = fa[p];
}
}
}
int temp = last;
while (temp){
if (num[temp]>=k){
break;
}
num[temp]++;
if (num[temp]==k){
ans+=l[temp]-l[fa[temp]];
}
temp = fa[temp];
}
}
}sam;
int main(){
while (scanf("%s",s)!=EOF){
scanf("%d%d",&m,&k);k++;
n=len = strlen(s);
sam.init();
for (int i=;i<len;i++){
sam.add(s[i]-'A');
}
ll ans1=sam.ans;
k=m;
sam.init();
for (int i=;i<len;i++){
sam.add(s[i]-'A');
}
ll ans2=sam.ans;
printf("%lld\n",ans2-ans1);
}
return ;
}
ACM-ICPC 2018 焦作赛区网络预赛 H、L的更多相关文章
- ACM-ICPC 2018 焦作赛区网络预赛 H题 String and Times(SAM)
Now you have a string consists of uppercase letters, two integers AA and BB. We call a substring won ...
- ACM-ICPC 2018 焦作赛区网络预赛- G:Give Candies(费马小定理,快速幂)
There are N children in kindergarten. Miss Li bought them NNN candies. To make the process more inte ...
- ACM-ICPC 2018 焦作赛区网络预赛- L:Poor God Water(BM模板/矩阵快速幂)
God Water likes to eat meat, fish and chocolate very much, but unfortunately, the doctor tells him t ...
- ACM-ICPC 2018 焦作赛区网络预赛
这场打得还是比较爽的,但是队友差一点就再过一题,还是难受啊. 每天都有新的难过 A. Magic Mirror Jessie has a magic mirror. Every morning she ...
- ACM-ICPC 2018 焦作赛区网络预赛J题 Participate in E-sports
Jessie and Justin want to participate in e-sports. E-sports contain many games, but they don't know ...
- ACM-ICPC 2018 焦作赛区网络预赛 K题 Transport Ship
There are NN different kinds of transport ships on the port. The i^{th}ith kind of ship can carry th ...
- ACM-ICPC 2018 焦作赛区网络预赛 L 题 Poor God Water
God Water likes to eat meat, fish and chocolate very much, but unfortunately, the doctor tells him t ...
- ACM-ICPC 2018 焦作赛区网络预赛 I题 Save the Room
Bob is a sorcerer. He lives in a cuboid room which has a length of AA, a width of BB and a height of ...
- ACM-ICPC 2018 焦作赛区网络预赛 G题 Give Candies
There are NN children in kindergarten. Miss Li bought them NN candies. To make the process more inte ...
随机推荐
- jacob的使用方法
网上一大堆你抄我的,我抄你的,但基本配置都没说清,做个笔记让后来的人少走冤枉路 1.下载最新的jacob,jdk版本一一对应,1.6对应jacob的1.16,1.7对应1.17.... 2.应用程序将 ...
- AngularJS日期格式化
本地化日期格式化:({{ today | date:'medium' }}) Mar 28, 2016 6:42:25 PM({{ today | date:'short' }}) 3/28 ...
- Photoshop 注册破解
本机测试环境为Photoshop cs4 破解方式一: 打开C:\windows\system32\drivers\etc\"找到 hosts 文件, 右键点击--打开方式---记事本,然后 ...
- springmvc+maven搭建web项目之二 通过另一种方式配置spring
1.创建maven web项目 2. 配置pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:x ...
- liunx 常用的命令
常用命令 ======================输入模式=================== Ctrl+d 向前缩进 Ctrl+t 向后缩进 =====================光标模式 ...
- 安装 配置 IIS
一 .找到 控制面板 ------ 在程序和功能 -----打开或关闭window 功能 :这里可能要等一下 才会显示 . 二‘.找到 Internet信息服务 ,勾选大部分如下图:点击 ...
- Java中类,对象,方法的内存分配
Java中类,对象,方法的内存分配 以下针对引用数据类型: 在内存中,类是静态的概念,它存在于内存中的CodeSegment中. 当我们使用new关键字生成对象时,JVM根据类的代码,去堆内存中开辟一 ...
- DLL动态链接库的创建
dll的创建主要有两种方法:一是使用 __declspec(dllexport) 创建dll,二是使用模块定义(.def)文件创建dll. 使用 __declspec(dllexport) 创建dll ...
- 【转】NIO的定义和原理是什么?
NIO和IO到底有什么区别?有什么关系? 首先说一下核心区别: NIO是以块的方式处理数据,但是IO是以最基础的字节流的形式去写入和读出的.所以在效率上的话,肯定是NIO效率比IO效率会高出很多. N ...
- poj2368 Buttons
题目描述 题解: 非常简单的巴什博弈问题. 简单来说保证$L+1$是$K$的因数即可. 决策是,先手取$x$个,后手就取$L+1-x$个. 那个$L>=2$真的很坑. 代码: #include& ...