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 ...
随机推荐
- Android学习笔记(十六) ContentProvider
1.相关概念 ContentProvider:不同应用程序之间进行数据交换的标准API:程序“暴露”数据的方法. ContentResolver:一个程序访问另一个程序被“暴露”的数据的方法. Uri ...
- Eric's并发用户数估算与Little定律的等价性
在国内性能测试的领域有一篇几乎被奉为大牛之作的经典文章,一个名叫Eric Man Wong 于2004年发表了名为<Method for Estimating the Number of Con ...
- IOS颜色块设置
+ (UIImage *)imageWithColor:(UIColor *)color { CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f); UIG ...
- 使用原生JavaScript模拟getElementByClassName .
最近在工作中,由于有一个插件必须使用jquery-pack.js,而这个包又是非常古老的jquery,所以又的函数是无法使用的,例如$()选择器以及parent()都取不到标签的内容. 所以没办法,只 ...
- mysql数据库比较,各数据库不同之处
和mysql数据库比较,各数据库不同之处: Oracle数据库:字段类型不同 postgresql数据库:show tables不同; SQL语句需要前面加上 模式名 Mongodb数据库:文档存储, ...
- PYTHON_DAY_02
今日内容: 01 列表内置方法 '''''' ''' 列表: 定义: 在[]内,可以存放多个任意类型的值, 并以逗号隔开. 一般用于存放学生的爱好,课堂的周期等等... ''' # 定义一个学生列表, ...
- Linux-03 Linux下的tar命令
功能说明 用来建立,还原备份文件的工具程序,它可以加入,解开备份文件内的文件 参数 -c: 建立压缩档案 -x:解压 -t:查看内容 -r:向压缩归档文件末尾追加文件 -u:更新原压缩包中的文件 这五 ...
- Ubuntu 18的网络配置
包括Ubuntu 18.04和18.10,设置为静态IP及DNS. sudo vim /etc/netplan/50-cloud-init.yaml network: ethernets: enp4s ...
- grep取缩写|awk两个文件取交集
#!/bin/sh les species_latinName_abbr.txt|grep -E 'Aptenodytes|Gavia|Phoenicopterus|Chlamydotis|Phaet ...
- 洛谷——P3939 数颜色(暴力vecotr+二分)
P3939 数颜色 $vecotr$里二分就是好用,全是$STL$ 颜色数目比较少,可以对每一种颜色弄一个$vector$记录一下,查找$l,r$内颜色数为$x$的兔子数,直接在$G[x]$这个$ve ...