====== 2020牛客暑期多校训练营(第九场) ======
[[https://vjudge.net/contest/389810|比赛网址]]
===== 训练结果 =====
* 时间:''2020-08-17 13:00~18:00''
* rank:''61/951''
* 完成情况:''5/6/11''
===== I.Just Skip The Problem =====
=== 题意 ===
给了一个字符串,问你有多少子串,自身是回文串而且一半也是回文串
=== 题解 ===
由回文自动机的性质知道一个串的本质不同的回文串最多有 $n$ 个,我们可以用回文自动机统计不同回文串的个数并标记位置,之后枚举每个串并用哈希判断他的一半是不是回文串就行
#include
#include
#include
#include
#define ll long long
using namespace std;
const int N=300055;
char s[N];
int fail[N],len[N],last,n,tot,ch[N][26],cnt[N],ps[N],ans[N];
ll hs[N],pw[N],hs2[N];
int newnode(int x)
{
len[++tot]=x;return tot;
}
void init()
{
tot=-1;last=0;
newnode(0);newnode(-1);
fail[0]=1;s[0]=-1;
}
int getfail(int pos,int x)
{
while(s[pos-len[x]-1]!=s[pos]) x=fail[x];
return x;
}
void add(int x,int c)
{
int cur=getfail(x,last);
if(!ch[cur][c])
{
int now=newnode(len[cur]+2);
fail[now]=ch[getfail(x,fail[cur])][c];
ch[cur][c]=now;
}
cnt[last=ch[cur][c]]++;ps[last]=x;
}
ll query(int l,int r,int opt)
{
int len=r-l+1;
if(opt==1)
{
return hs[r]-hs[l-1]*pw[len];
}
else
{
return hs2[l]-hs2[r+1]*pw[len];
}
}
int chk(int l,int r)
{
int mid=l+r>>1,len=r-l+1;
if(len&1)
{
return query(l,mid,1)==query(mid,r,2);
}
else return query(l,mid,1)==query(mid+1,r,2);
}
int main()
{
pw[0]=1;
for(int i=1;i1;i--)
{
// cout<
===== J.Just Skip The Problem =====
=== 题意 ===
求 $n$ 的阶乘,水
===== K.Keen On Everything But Triangle =====
=== 题意 ===
给出一排长度不同的木棒,每次询问一个区间,求这个区间木棒能构成周长最长的三角形
=== 题解 ===
对于一部分木棒,一定是优先选最大的三个尝试组合
如果三个木棒不合法,那么最小的和最大的差别一定减半,所以可以暴力$O(logn)$枚举
那么枚举最大的是第几大,用线段树查询即可
#include
#include
#include
#include
#include
#include
#include
#include
#include
===== L.Longest Subarray =====
=== 题意 ===
一个序列每个位置有一种颜色,找到一个最长的子区间,使得每种颜色要么出现过超过$K$次,要么出现过$0$次
=== 题解 ===
从后往前枚举位置作为子区间的开端,每种颜色有两种状态:
1、数量不足,不能被包含,那么这些位置都被禁了,要选一个最大的子区间,那么右端点一定在最左边被禁的地方
2、当前数量足够$K$个,记录一下如果要包含这种颜色,最少要包含到哪个位置
那么每次只需要在线段树上找当前区间最大值有没有超过设定的右端点即可
#include
#include
#include
#include
#include
#include
#include
#include
#include
===== 训练实况 =====
===== 训练总结 =====
wxg: 网络流没有想出来模型,以后要多练练
hxm:比较遗憾B最后差一点没写出
fyh: