思路:

http://blog.csdn.net/wzq_QwQ/article/details/47152909

代码也是抄的他的

自己写得垃圾线段树怎么都过不了

隔了两个月 再写 再挂

又隔了10天 再写 终于A了………………………..

//By SiriusRen
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define mod 1000000007
#define int long long
int cases,n,a[10050],hash[999999],hash2[999999],p[10050];
void push_up(int pos,int num){
int lson=pos<<1,rson=pos<<1|1;
hash[pos]=(hash[lson]*p[num/2]+hash[rson])%mod;
hash2[pos]=(hash2[rson]*p[num-num/2]+hash2[lson])%mod;
}
void insert(int l,int r,int pos,int num){
if(l==r){hash[pos]=hash2[pos]=1;return;}
int mid=(l+r)>>1,lson=pos<<1,rson=pos<<1|1;
if(num<=mid)insert(l,mid,lson,num);
else insert(mid+1,r,rson,num);
push_up(pos,r-l+1);
}
int query(int L,int R,int l,int r,int pos){
if(L==l&&r==R)return hash[pos];
int mid=(l+r)>>1;
if(R<=mid)return query(L,R,l,mid,pos<<1);
else if(L>mid)return query(L,R,mid+1,r,pos<<1|1);
else return (query(L,mid,l,mid,pos<<1)*p[R-mid]+query(mid+1,R,mid+1,r,pos<<1|1))%mod;
}
int query2(int L,int R,int l,int r,int pos){
if(L==l&&r==R)return hash2[pos];
int mid=(l+r)>>1;
if(R<=mid)return query2(L,R,l,mid,pos<<1);
else if(L>mid)return query2(L,R,mid+1,r,pos<<1|1);
else return (query2(L,mid,l,mid,pos<<1)+query2(mid+1,R,mid+1,r,pos<<1|1)*p[mid-L+1])%mod;
}
signed main(){
p[0]=1;
for(int i=1;i<=10000;i++)p[i]=(p[i-1]*3)%mod;
scanf("%lld",&cases);
while(cases--){
memset(hash,0,sizeof(hash)),memset(hash2,0,sizeof(hash2));
scanf("%lld",&n);
for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
for(int i=1;i<=n;i++){
int len=min(n-a[i],a[i]-1);
int tmp1=query(a[i]-len,a[i],1,n,1);
int tmp2=query2(a[i],a[i]+len,1,n,1);
if(tmp1!=tmp2){puts("Y");goto ed;}
insert(1,n,1,a[i]);
}puts("N");ed:;
}
}

BZOJ 2124 线段树维护hash值的更多相关文章

  1. MemSQL Start[c]UP 2.0 - Round 1 F - Permutation 思维+线段树维护hash值

    F - Permutation 思路:对于当前的值x, 只需要知道x + k, x - k这两个值是否出现在其左右两侧,又因为每个值只有一个, 所以可以转换成,x+k, x-k在到x所在位置的时候是否 ...

  2. cf213E 线段树维护hash

    链接 https://codeforces.com/contest/213/problem/E 题目大意 给出两个排列a.b,长度分别为n.m,你需要计算有多少个x,使 得\(a_1 + x; a_2 ...

  3. BZOJ 2124: 等差子序列 线段树维护hash

    2124: 等差子序列 Description 给一个1到N的排列{Ai},询问是否存在1<=p1=3),使得Ap1,Ap2,Ap3,…ApLen是一个等差序列. Input 输入的第一行包含一 ...

  4. bzoj 2124 等差子序列 (线段树维护hash)

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

  5. HDU3564 --- Another LIS (线段树维护最值问题)

    Another LIS Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  6. Codeforces Round #321 (Div. 2) E Kefa and Watch (线段树维护Hash)

    E. Kefa and Watch time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  7. bzoj 1018 线段树维护连通性

    本题将一道LCT的题特殊化(支持加边和删边,询问图的连通性),将图变成了2×m的网格图,然后就神奇地可以用线段树来维护. 对于每个区间[l,r],维护其四个角落之间的连通性(仅仅通过[l,r]这段的边 ...

  8. BZOJ 1018 线段树维护图的连通性问题

    思路: 我们可以搞一棵线段树 对于一段区间有6种情况需要讨论 左上右下.左上右上.左下右下.左下右上 这四种比较好维护 用左上右下举个例子吧 就是左儿子的左上右下&左区间到右区间下面有路&am ...

  9. BZOJ 1018 线段树维护图连通性

    用8个bool维护即可分别为LURU,LURD,LDRU,LDRD,LULD,RURD,Side[1],Side[2]即可. Side表示这一块有没有接到右边.Merge一下就可以了.码农题,WA了一 ...

随机推荐

  1. mysql字符集修改(ubuntu)

    1.关闭mysql服务 /etc/init.d/mysql start|stop 2.在/etc/mysql/my.cnf,添加下列信息 [client] default-character-set= ...

  2. grep常见使用方法总结

    grep -E 'l\{2,\}' 2.txt grep -E 'h(ell|a)o' test.txt grep '[a-z]\{5,\}' test.txt grep -xf a.txt b.tx ...

  3. BEGINNING SHAREPOINT&#174; 2013 DEVELOPMENT 第6章节--在SharePoint2013中开发、集成和构建应用程序 总结

    BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第6章节--在SharePoint2013中开发.集成和构建应用程序  总结         SharePoint开发已经 ...

  4. mariadb克隆

    oracle有克隆安装,事实上mysql/mariadb相似.仅仅需简单几步就能够直接在异机直接启动. 环境: node01安装完毕的mariadb; node02一个新机器 如今将node01克隆到 ...

  5. 开发者了解NET的15个特性

    NET 开发者了解的15个特性 本文列举了 15 个值得了解的 C# 特性,旨在让 .NET 开发人员更好的使用 C# 语言进行开发工作. ObsoleteAttribute ObsoleteAttr ...

  6. 51nod 1098 最小方差 排序+前缀和+期望方差公式

    题目: 题目要我们,在m个数中,选取n个数,求出这n个数的方差,求方差的最小值. 1.我们知道,方差是描述稳定程度的,所以肯定是着n个数越密集,方差越小. 所以我们给这m个数排个序,从连续的n个数中找 ...

  7. 1、Windows服务器 VS Linux服务器

  8. jdk1.8源码分析-hashMap

    在Java语言中使用的最多的数据结构大概右两种,第一种是数组,比如Array,ArrayList,第二种链表,比如ArrayLinkedList,基于数组的数据结构特点是查找速度很快,时间复杂度为 O ...

  9. 向ueditor中插入内容

    html在ueditor中插入内容不能直接插入,必须判断编辑器是否创建成功,jsp可以用java代码嵌套的方式. html页面中:<textarea id="zym" nam ...

  10. PHP XML操作类DOMDocument

    不得不自已写一个.XML 的操作一直没有用过.下面是自己搜集的XML操作类 DOMDocument相关的内容. 属性: Attributes 存储节点的属性列表(只读) childNodes 存储节点 ...