Codeforces452F Permutation -- 线段树 + Hash
来源:互联网 发布:大数据 精准医疗 案例 编辑:程序博客网 时间:2024/06/10 20:21
假如不存在长度大于等于
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;#define N 300010#define P 127#define M 1000000007int c[2][N<<2],p[N];int i,j,k,n,m,x;inline void Up(int x,int l){ c[0][x]=(c[0][x<<1]+1ll*c[0][x<<1|1]*p[l+1>>1]%M)%M; c[1][x]=(c[1][x<<1|1]+1ll*c[1][x<<1]*p[l>>1]%M)%M;}inline void Update(int x,int l,int r,int y){ if(l==r){ c[0][x]=c[1][x]=1; return; } int Mid=l+r>>1; if(y<=Mid)Update(x<<1,l,Mid,y);else Update(x<<1|1,Mid+1,r,y); Up(x,r-l+1);}inline int Query(int x,int l,int r,int L,int R,int d){ if(l>R||r<L)return 0; if(l>=L&&r<=R)return 1ll*c[d][x]*(d?p[R-r]:p[l-L])%M; int Mid=l+r>>1; return (Query(x<<1|1,Mid+1,r,L,R,d)+Query(x<<1,l,Mid,L,R,d))%M;}int main(){ scanf("%d",&n); for(i=p[0]=1;i<n;i++)p[i]=1ll*p[i-1]*P%M; for(i=1;i<=n;i++){ scanf("%d",&x); if(x<=n/2){ if(Query(1,1,n,1,x-1,0)!=Query(1,1,n,x+1,x*2-1,1)){ puts("YES"); return 0; } }else{ if(Query(1,1,n,x+1,n,0)!=Query(1,1,n,x*2-n,x-1,1)){ puts("YES"); return 0; } } Update(1,1,n,x); } puts("NO"); return 0;}
阅读全文
0 0
- Codeforces452F Permutation -- 线段树 + Hash
- 【线段树+Hash】Codeforces452F[Permutation]题解
- Codeforces452F(MemSQL Start[c]UP 2.0)[Permutation]--线段树+Hash
- [线段树 哈希] Codeforces452F. Permutation
- 【Codeforces】452F Permutation hash+线段树
- 【线段树+Hash】Codeforces 452F Permutation
- uva 11525 - Permutation(线段树)
- UVA11525 - Permutation(线段树)
- UVa 11525 Permutation (线段树)
- 线段树+hash+codeforces213E
- 线段树 + 字符串Hash
- Permutation +uva+线段树+点修改
- Codeforces 452F Permutation【线段树】【哈希】
- [线段树+哈希] Codeforces 452F. Permutation
- hdu 3973(hash+线段树)
- Hash练习题:【213E】 Two Permutations(线段树,hash)
- HDU3333(线段树/数状数组 + hash)
- 【Hash\KMP\线段树】文明的复兴
- Java--序列化与反序列化
- Spring中使用定时任务Quartz
- hdu 4417 Super Mario(主席树)
- Spring Boot整合Spring Data
- Sort List —— 归并排序
- Codeforces452F Permutation -- 线段树 + Hash
- 【DBSDFZOJ4473】幻想
- laravel框架入门记录(一)
- 数组中只出现一次的两个不同数字
- ANTLR教程(一)简介
- 在Fedora系统上运行UMLDesigner8报错问题解决
- 个人项目错误锦集
- [LintCode]104.合并k个排序链表
- C++容器适配器