题意:给一个 1 到 N 的排列{Ai},询问是否存在 1<=p1<p2<p3<p4<p5<…<pLen<=N(Len>=3),使得 Ap1,Ap2,Ap3,…ApLen 是一个等差序列。

按值建线段树,逐个插入,hash判断。

#include<bits/stdc++.h>
#define N (1<<15)
#define M (l+r>>1)
#define P (k<<1)
#define S (k<<1|1)
#define K l,r,k
#define L l,M,P
#define R M+1,r,S
#define Z \
int l=0,int r=n,int k=1
using namespace std;
int n,q;
typedef unsigned long long ull;
const ull base=23;
ull d[N],u[N],v[N];
void amend(int s,int t,Z){
if(l==r)
u[k]=v[k]=s;
else{
if(t<=M)
amend(s,t,L);
else
amend(s,t,R);
u[k]=u[P]+u[S]*d[M-l+1];
v[k]=v[S]+v[P]*d[r-M];
}
}
ull Q1(int s,int t,Z){
return s==l&&t==r?u[k]:t<=M?Q1(s,t,L):s>M?Q1(s,t,R):Q1(s,M,L)+Q1(M+1,t,R)*d[M-s+1];
}
ull Q2(int s,int t,Z){
return s==l&&t==r?v[k]:t<=M?Q2(s,t,L):s>M?Q2(s,t,R):Q2(M+1,t,R)+Q2(s,M,L)*d[t-M];
}
bool check(){
memset(u,0,sizeof u);
memset(v,0,sizeof v);
static int a[N];
for(int i=0;i!=n;++i)
scanf("%d",a+i);
for(int i=0;i!=n;amend(1,a[i++]))
if(int j=min(a[i]-1,n-a[i]))
if(Q1(a[i]+1,a[i]+j)^Q2(a[i]-j,a[i]-1))
return 1;
return 0;
}
int main(){
d[0]=1;
for(int i=1;i!=N;++i)
d[i]=d[i-1]*base;
for(scanf("%d",&q);q;--q){
scanf("%d",&n);
puts(check()?"Y":"N");
}
}

BZOJ2124: 等差子序列的更多相关文章

  1. bzoj2124: 等差子序列线段树+hash

    bzoj2124: 等差子序列线段树+hash 链接 https://www.lydsy.com/JudgeOnline/problem.php?id=2124 思路 找大于3的等差数列其实就是找等于 ...

  2. [BZOJ2124]等差子序列/[CF452F]Permutation

    [BZOJ2124]等差子序列/[CF452F]Permutation 题目大意: 一个\(1\sim n\)的排列\(A_{1\sim n}\),询问是否存在\(i,j(i<j)\),使得\( ...

  3. BZOJ2124 等差子序列(树状数组+哈希)

    容易想到一种暴力的做法:枚举中间的位置,设该位置权值为x,如果其两边存在权值关于x对称即合法. 问题是如何快速寻找这个东西是否存在.考虑仅将该位置左边出现的权值标1.那么若在值域上若关于x对称的两权值 ...

  4. [bzoj2124]等差子序列_线段树_hash

    等差子序列 bzoj-2124 题目大意:给定一个1~n的排列,问是否存在3个及以上的位置上的数构成连续的等差子序列. 注释:$1\le n\le 10^4$. 想法:这题就相当于是否存在3个数i,j ...

  5. [bzoj2124]等差子序列(hash+树状数组)

    我又来更博啦     2124: 等差子序列 Time Limit: 3 Sec  Memory Limit: 259 MBSubmit: 941  Solved: 348[Submit][Statu ...

  6. bzoj2124 等差子序列(hash+线段树)

    2124: 等差子序列 Time Limit: 3 Sec  Memory Limit: 259 MBSubmit: 719  Solved: 261[Submit][Status][Discuss] ...

  7. BZOJ2124:等差子序列(线段树,hash)

    Description 给一个1到N的排列{Ai},询问是否存在1<=p1<p2<p3<p4<p5<…<pLen<=N (Len>=3), 使得A ...

  8. BZOJ2124: 等差子序列(树状数组&hash -> bitset 求是否存在长度为3的等差数列)

    2124: 等差子序列 Time Limit: 3 Sec  Memory Limit: 259 MBSubmit: 2354  Solved: 826[Submit][Status][Discuss ...

  9. [bzoj2124]等差子序列——线段树+字符串哈希

    题目大意 给一个1到N的排列\(A_i\),询问是否存在\(p_i\),\(i>=3\),使得\(A_{p_1}, A_{p_2}, ... ,A_{p_len}\)是一个等差序列. 题解 显然 ...

随机推荐

  1. [BZOJ1579][Usaco2009 Feb]Revamping Trails 道路升级(二维最短路问题)

    题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1579 分析: 设d[i][j]表示从1走到i.改了j条边的最短路径长度 如果设i相连的 ...

  2. Windows10一周年庆典壁纸

    example: 下载:http://pan.baidu.com/s/1b55D5k

  3. ipython又一方便的调试和应用工具!!!

    控制台下://ipython 命令丰富 比如:ls 显示目录  ipython --pylab %run -p *.py quit关闭     示例: In []: %run -p test.py H ...

  4. iOS 'The sandbox is not sync with the Podfile.lock'问题解决

    问题描述: github下载的Demo,很多时候使用到CocoaPods,有的时候因为依赖关系或者版本问题不能编译运行.出现例如The sandbox is not sync with the Pod ...

  5. there is issue about change event of checkbox in the ie8 oe ie7

    some people said the change event of checkbox can not trigger in the ie7 or ie8,that's not true. thi ...

  6. SharePoint 2013 安装图解

    转自: http://www.cnblogs.com/jianyus/archive/2013/02/01/2889653.html 介绍:文章就是SharePoint2013安装过程的图解,包括步骤 ...

  7. git工作流程

    git工作流程 一般工作流程如下: 克隆 Git 资源作为工作目录. 在克隆的资源上添加或修改文件. 如果其他人修改了,你可以更新资源. 在提交前查看修改. 提交修改. 在修改完成后,如果发现错误,可 ...

  8. Maven2-profile多环境配置

    使用maven管理项目有一个好处是就是可以针对不同的环境使用不同的编译打包设置,方便了多环境下的打包部署,一般我们开发项目都会有至少开发环境和正式环境两个,针对这两个环境的配置信息也会有所不同,比如数 ...

  9. BeautifulSoup_python3

    1.错误排除 bsObj = BeautifulSoup(html.read()) 报错: UserWarning: No parser was explicitly specified, so I' ...

  10. NGUI之添加响应函数

    public void ButtonNextClicked() { SelectIndex++; SelectIndex %= ; showGameObject(); } public void Bu ...