题意比较麻烦略

题解:枚举前缀的中点,二分最远能扩展的地方,lcp来check,然后线段树维护每个点最远被覆盖的地方,然后查询线段树即可

//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize(4)
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define fi first
#define se second
#define db double
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 1000000009
#define ld long double
//#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define ull unsigned long long
//#define base 1000000000000000000
#define fin freopen("a.txt","r",stdin)
#define fout freopen("a.txt","w",stdout)
#define fio ios::sync_with_stdio(false);cin.tie(0)
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=ans*a%c;a=a*a%c,b>>=1;}return ans;} using namespace std; const ull ba=233;
const db eps=1e-5;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=1000000+10,maxn=1000000+10,inf=0x3f3f3f3f; char s[N];
int sa[N], t[N], t2[N], c[N], rk[N], height[N];
void buildSa(int n, int m) {
int i, j = 0, k = 0, *x = t, *y = t2;
for(i = 0; i < m; i++) c[i] = 0;
for(i = 0; i < n; i++) c[x[i] = s[i]]++;
for(i = 1; i < m; i++) c[i] += c[i - 1];
for(i = n - 1; i >= 0; i--) sa[--c[x[i]]] = i;
for(int k = 1; k < n; k <<= 1) {
int p = 0;
for(i = n - k; i < n; i++) y[p++] = i;
for(i = 0; i < n; i++) if(sa[i] >= k) y[p++] = sa[i] - k;
for(i = 0; i < m; i++) c[i] = 0;
for(i = 0; i < n; i++) c[x[y[i]]]++;
for(i = 1; i < m; i++) c[i] += c[i - 1];
for(i = n - 1; i >= 0; i--) sa[--c[x[y[i]]]] = y[i];
swap(x, y);
p = 1; x[sa[0]] = 0;
for(int i = 1; i < n; i++) {
if(y[sa[i - 1]] == y[sa[i]] && y[sa[i - 1] + k] == y[sa[i] + k])
x[sa[i]] = p - 1;
else x[sa[i]] = p++;
}
if(p >= n) break;
m = p;
}
for(i = 1; i < n; i++) rk[sa[i]] = i;
for(i = 0; i < n - 1; i++) {
if(k) k--;
j = sa[rk[i] - 1];
while(s[i + k] == s[j + k]) k++;
height[rk[i]] = k;
}
}
int Log[N];
struct ST {
int dp[N][20],ty;
ST()
{
for(int i = -(Log[0]=-1); i < N; i++)
Log[i] = Log[i - 1] + ((i & (i - 1)) == 0);
}
void build(int n, int b[], int _ty) {
ty = _ty;
for(int i = 1; i <= n; i++) dp[i][0] = ty * b[i];
for(int j = 1; j <= Log[n]; j++)
for(int i = 1; i+(1<<j)-1 <= n; i++)
dp[i][j] = max(dp[i][j-1], dp[i+(1<<(j-1))][j-1]);
}
int query(int x, int y) {
int k = Log[y - x + 1];
return ty * max(dp[x][k], dp[y-(1<<k)+1][k]);
}
}st;
int lcp(int x,int y)//from 0 begin
{
x=rk[x],y=rk[y];
if(x>y)swap(x,y);x++;
return st.query(x,y);
}
int n;
struct sgt{
int ma[N<<2],lazy[N<<2];
sgt(){memset(ma,-1,sizeof ma);memset(lazy,-1,sizeof lazy);}
void pushdown(int rt)
{
if(~lazy[rt])
{
ma[rt<<1]=max(ma[rt<<1],lazy[rt]);
ma[rt<<1|1]=max(ma[rt<<1|1],lazy[rt]);
lazy[rt<<1]=max(lazy[rt<<1],lazy[rt]);
lazy[rt<<1|1]=max(lazy[rt<<1|1],lazy[rt]);
lazy[rt]=-1;
}
}
void update(int L,int R,int v,int l,int r,int rt)
{
if(L<=l&&r<=R)
{
ma[rt]=max(ma[rt],v);
lazy[rt]=max(lazy[rt],v);
return ;
}
pushdown(rt);
int m=(l+r)>>1;
if(L<=m)update(L,R,v,ls);
if(m<R)update(L,R,v,rs);
ma[rt]=max(ma[rt<<1],ma[rt<<1|1]);
}
int query(int pos,int l,int r,int rt)
{
if(l==r)
{
if(ma[rt]==-1)return -1;
else return (ma[rt]-l)*2+1;
}
pushdown(rt);
int m=(l+r)>>1;
if(pos<=m)return query(pos,ls);
else return query(pos,rs);
}
}sg;
int main()
{
scanf("%d%s",&n,s);
buildSa(n+1,256);
st.build(n,height,-1);
for(int i=0;i<n/2;i++)
{
if(s[i]!=s[n-i-1])continue;
int l=0,r=i+1;
while(l<r-1)
{
int m=(l+r)>>1;
if(lcp(i-m,n-i-1-m)>=2*m+1)l=m;
else r=m;
}
// if(i==6)printf("%d \n",lcp(5,11));
sg.update(i-l,i,i,0,n-1,1);
// printf("%d %d\n",i-l,i);
}
for(int i=0;i<(n+1)/2;i++)printf("%d ",sg.query(i,0,n-1,1));puts("");
return 0;
}
/******************** ********************/

Educational Codeforces Round 41 (Rated for Div. 2)F. k-substrings的更多相关文章

  1. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...

  2. Educational Codeforces Round 71 (Rated for Div. 2)-F. Remainder Problem-技巧分块

    Educational Codeforces Round 71 (Rated for Div. 2)-F. Remainder Problem-技巧分块 [Problem Description] ​ ...

  3. Educational Codeforces Round 41 (Rated for Div. 2)(A~D)

    由于之前打过了这场比赛的E题,而后面两道题太难,所以就手速半个多小时A了前4题. 就当练手速吧,不过今天除了C题数组开小了以外都是1A A Tetris 题意的抽象解释可以在Luogu里看一下(话说现 ...

  4. Educational Codeforces Round 41 (Rated for Div. 2)

    这场没打又亏疯了!!! A - Tetris : 类似俄罗斯方块,模拟一下就好啦. #include<bits/stdc++.h> #define fi first #define se ...

  5. Educational Codeforces Round 41 (Rated for Div. 2) ABCDEF

    最近打的比较少...就只有这么点题解了. A. Tetris time limit per test 1 second memory limit per test 256 megabytes inpu ...

  6. D. Pair Of Lines( Educational Codeforces Round 41 (Rated for Div. 2))

    #include <vector> #include <iostream> #include <algorithm> using namespace std; ty ...

  7. C. Chessboard( Educational Codeforces Round 41 (Rated for Div. 2))

    //暴力 #include <iostream> #include <algorithm> #include <string> using namespace st ...

  8. B. Lecture Sleep( Educational Codeforces Round 41 (Rated for Div. 2))

    前缀后缀和搞一搞,然后枚举一下区间,找出最大值 #include <iostream> #include <algorithm> using namespace std; ; ...

  9. 【Educational Codeforces Round 41 (Rated for Div. 2) D】Pair Of Lines

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 如果点的个数<=3 那么直接输出有解. 否则. 假设1,2最后会在一条直线上,则把这条直线上的点都删掉. 看看剩余的点是否在同 ...

随机推荐

  1. Ubuntu14.04 安装 Sublime Text 3

    Linux下安装,一种办法是从官网下载 tar.bz ,手动安装.另一种是使用apt-ge安装 这里介绍用 apt-get 自动安装方法: 1.添加sublime text 3的仓库: sudo ad ...

  2. python安装pip的步骤记录

    因为重新装了系统,所以python所有的环境都要重新走一遍. 首先去python官网下载python最新版本.如果python没有自动加入环境变量的话就需要你自己手动加入.这个一般在安装python的 ...

  3. laravel 核心类Kernel

    vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php.是laravel处理网络请求的最核心类,在app容器准备好了之后, ...

  4. 网络-01-端口号-linux端口详解大全

    0 | 无效端口,通常用于分析操作系统1 | 传输控制协议端口服务多路开关选择器2 | 管理实用程序3 | 压缩进程5 | 远程作业登录7 | 回显9 | 丢弃11 | 在线用户13 | 时间17 | ...

  5. 多个for循环嵌套会影响速度

    在复现Meta-SR的过程中,发现如果嵌套多个for 循环会使速度过慢.这是下面实验得出的结论: import time t1 = time.time() a = range(3000) b = ra ...

  6. html中div标签怎么用?

    div现在一般网页的布局都是使用的div+css来布局,div的话,就是通过. <div> <div><p></p></div> </ ...

  7. 用iPhone查看pc电脑上写的html(Mac电脑Charles)简单版

    对于客户端同学开发来说,写一段代码想在真机上看看,是非常容易的. 那么在这么一个大前端的环境下,客户端开发想写点html和js代码,又想在手机上看看效果,怎么办呢? 需要以下几个步骤: 大体流程:1. ...

  8. ie8下new Date()指定时间

    项目开发中很可能会需要创建一个指定日期的时间对象,火狐浏览器可以直接使用new Date('yyyy-mm-dd')生成时间,但是在ie8下就会发现生成的时间输出的是NaN-NaN-NaN.为了兼容可 ...

  9. Liunx中三种网络模式配置及Xshell连接

    Liunx网络配置 NAT模式下的网络配置: 首先打开网络配置文件:vi   /etc/sysconfig/network-scripts/ifcfg-ens33 修改网卡信息,配置动态Ip过程中,只 ...

  10. TeamCity Build 步骤的执行策略

    TeamCity 会根据前一个 build 步骤的返回状态和当前的 build 状态来综合判断是否运行下一个 build 步骤.1 失败状态 当满足下面条件时 build 步骤的状态被确定为失败: b ...