对于每个位置求出L[i]表示左边最大的j,满足从j开始到i-1中存在第一个子序列

R[i]表示右边最小的j,满足从j开始到i-1中存在第二个子序列

然后枚举颜色是相遇点的位置,如果L[i]左边、R[i]右边存在一样的颜色,则可行

#include<cstdio>
#define N 1000010
inline void read(int&a){char c;while(!(((c=getchar())>='0')&&(c<='9')));a=c-'0';while(((c=getchar())>='0')&&(c<='9'))(a*=10)+=c-'0';}
int n,k,m,l,i,j,t,a[N],c[N],nxt[N],loc[N],f[N],L[N],R[N],cnt[N],ret,ans;bool vis[N],can[N];
int main(){
read(n),read(k);
for(i=1;i<=n;i++)read(c[i]);
read(m),read(l);
for(i=1;i<=m;i++)read(a[i]);
for(i=m+l-1;i>=m;i--)read(a[i]);
for(i=1;i<=n;i++)loc[i]=n+1;
for(i=n;i;i--)nxt[i]=loc[c[i]],loc[c[i]]=i;
for(i=1;i<=n;i++){
L[i]=m>1?f[1]:i;
if(c[i]==a[m-1])for(f[m-1]=i,j=m-2;j;j--)while((t=f[j]?nxt[f[j]]:loc[a[j]])<f[j+1])f[j]=t;
}
for(i=1;i<=n;i++)loc[i]=0,f[i]=n+1;
for(i=1;i<=n;i++)nxt[i]=loc[c[i]],loc[c[i]]=i;
for(i=n;i;i--){
R[i]=l>1?f[m+l-1]:i;
if(c[i]==a[m+1])for(f[m+1]=i,j=m+2;j<m+l;j++)while((t=f[j]<=n?nxt[f[j]]:loc[a[j]])>f[j-1])f[j]=t;
}
for(i=1;i<=n;i++)if(L[i]>1&&R[i]<n){
for(j=n;j>R[i];j--)cnt[c[j]]++;
for(j=1;j<L[i];j++)if(!vis[c[j]]&&cnt[c[j]])vis[c[j]]=1,ret++;
if(ret&&c[i]==a[m])ans++,can[i]=1;
break;
}
for(i++;i<=n;i++){
if(R[i]>=n)break;
for(j=R[i];j>R[i-1];j--)if(!(--cnt[c[j]])&&vis[c[j]])ret--,vis[c[j]]=0;
for(j=L[i-1];j<L[i];j++)if(!vis[c[j]]&&cnt[c[j]])vis[c[j]]=1,ret++;
if(ret&&c[i]==a[m])ans++,can[i]=1;
}
printf("%d\n",ans);
for(i=1;i<=n;i++)if(can[i])printf("%d ",i);
return 0;
}

  

BZOJ3828 : [Poi2014]Criminals的更多相关文章

  1. [POI2014]Criminals

    题目大意: 给你一个长度为$n(n\le10^6)$的颜色序列,其中每个颜色互不相同.两个人$A$和$B$分别从某个点出发从左往右.从右往左任意地选择颜色,然后在中间的某一点相遇.分别给出两人所选择的 ...

  2. POI2014题解

    POI2014题解 [BZOJ3521][Poi2014]Salad Bar 把p当作\(1\),把j当作\(-1\),然后做一遍前缀和. 一个合法区间\([l,r]\)要满足条件就需要满足所有前缀和 ...

  3. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  4. BZOJ 3524: [Poi2014]Couriers [主席树]

    3524: [Poi2014]Couriers Time Limit: 20 Sec  Memory Limit: 256 MBSubmit: 1892  Solved: 683[Submit][St ...

  5. BZOJ 3524: [Poi2014]Couriers

    3524: [Poi2014]Couriers Time Limit: 20 Sec  Memory Limit: 256 MBSubmit: 1905  Solved: 691[Submit][St ...

  6. [BZOJ3872][Poi2014]Ant colony

    [BZOJ3872][Poi2014]Ant colony 试题描述 There is an entrance to the ant hill in every chamber with only o ...

  7. Codeforces Round #356 (Div. 2)B. Bear and Finding Criminals(水题)

    B. Bear and Finding Criminals time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

  8. 【BZOJ】【3522】【POI2014】Hotel

    暴力/树形DP 要求在树上找出等距三点,求方案数,那么用类似Free Tour2那样的合并方法,可以写出: f[i][j]表示以 i 为根的子树中,距离 i 为 j 的点有多少个: g[i][j]表示 ...

  9. 【BZOJ】【3831】【POI2014】Little Bird

    DP/单调队列优化 水题水题水题水题 单调队列优化的线性dp…… WA了8次QAQ,就因为我写队列是[l,r),但是实际操作取队尾元素的时候忘记了……不怎么从队尾取元素嘛……平时都是直接往进放的……还 ...

随机推荐

  1. CoreLoation

    - (CLLocationManager *)locationManager { if (!_locationManager) { _locationManager = [[CLLocationMan ...

  2. rocksdb 编译安装 日志

    Compilation RocksDB's library should be able to compile without any dependency installed, although w ...

  3. LSB 简介

    前 Linux 的发行版非常繁多,为了促进 Linux 不同发行版间的兼容性,LSB(Linux Standards Base)开发了一系列标准,使各种软件可以很好地在兼容 LSB 标准的系统上运行, ...

  4. location 、history

    location.href= location.reload() history.go()  0   1  -1 history.back() history.forward() history.le ...

  5. (转)maven eclipse debug

    准备工作: a. 在pom.xml中配置jetty插件: <plugins> <plugin> <groupId>org.mortbay.jetty</gro ...

  6. iOS 中使用Block时需要注意的retain circle

    现在在ios中,block是越来越多了.自己在类中定义block对象时,需要注意block对象的使用方法,防止产生retain circle,导致内存泄露. 现在分析一下产生retain circle ...

  7. Java for LeetCode 027 Remove Element

    Given an array and a value, remove all instances of that value in place and return the new length. T ...

  8. 【JAVA、C++】LeetCode 020 Valid Parentheses

    Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the inpu ...

  9. Android中mesure过程详解

    我们在编写layout的xml文件时会碰到layout_width和layout_height两个属性,对于这两个属性我们有三种选择:赋值成具体的数值,match_parent或者wrap_conte ...

  10. C#学习笔记---修饰符,this关键字和static关键字

    1.  C#中类的修饰符: public 表示不限制对该类的访问  protected 表示只能从所在类和所在类派生的子类进行访问    private 只有其所在类才能访问 internal 只有对 ...