【线段树+Hash】Codeforces452F[Permutation]题解
来源:互联网 发布:北京新华电脑学校java 编辑:程序博客网 时间:2024/05/22 04:52
题目概述
一个序列
- 是
n 的排列。 - 不存在一个长度
>2 的子序列使得该子序列是等差数列。
给出一个序列,判断该序列是不是反等差数列。
解题报告
记录
从左到右枚举
示例程序
#include<cstdio>#include<algorithm>#define fr first#define sc second#define mp make_pairusing namespace std;typedef unsigned long long ULL;typedef pair<ULL,int> pui;const int maxn=300000,Ha=1e9+7;int n,a[maxn+5];ULL px[maxn*4+5],A[maxn*4+5],B[maxn*4+5];#define Eoln(x) ((x)==10||(x)==13||(x)==EOF)inline char readc(){ static char buf[100000],*l=buf,*r=buf; if (l==r) r=(l=buf)+fread(buf,1,100000,stdin); if (l==r) return EOF;return *l++;}inline int readi(int &x){ int tot=0,f=1;char ch=readc(),lst='+'; while ('9'<ch||ch<'0') {if (ch==EOF) return EOF;lst=ch;ch=readc();} if (lst=='-') f=-f; while ('0'<=ch&&ch<='9') tot=(tot<<3)+(tot<<1)+ch-48,ch=readc(); return x=tot*f,Eoln(ch);}inline void Pushup(int p,int l,int r) {A[p]=A[p<<1]*px[r]+A[p<<1|1];B[p]=B[p<<1]+B[p<<1|1]*px[l];}void Update(int pos,int l=1,int r=n,int p=1){ if (pos<l||r<pos) return;if (l==r) {A[p]=B[p]=1;return;}int mid=l+(r-l>>1); Update(pos,l,mid,p<<1);Update(pos,mid+1,r,p<<1|1);Pushup(p,mid-l+1,r-mid);}pui Ask_A(int L,int R,int l=1,int r=n,int p=1){ if (R<l||r<L) return mp(0,0);if (L<=l&&r<=R) return mp(A[p],r-l+1);int mid=l+(r-l>>1); pui a=Ask_A(L,R,l,mid,p<<1),b=Ask_A(L,R,mid+1,r,p<<1|1); return mp(a.fr*px[b.sc]+b.fr,a.sc+b.sc);}pui Ask_B(int L,int R,int l=1,int r=n,int p=1){ if (R<l||r<L) return mp(0,0);if (L<=l&&r<=R) return mp(B[p],r-l+1);int mid=l+(r-l>>1); pui a=Ask_B(L,R,l,mid,p<<1),b=Ask_B(L,R,mid+1,r,p<<1|1); return mp(a.fr+b.fr*px[a.sc],a.sc+b.sc);}int main(){ freopen("program.in","r",stdin); freopen("program.out","w",stdout); readi(n);for (int i=1;i<=n;i++) readi(a[i]); px[0]=1;for (int i=1;i<=n;i++) px[i]=px[i-1]*2333; for (int i=1;i<=n;i++) { int k=min(a[i]-1,n-a[i]); if (Ask_A(a[i]-k,a[i]).fr!=Ask_B(a[i],a[i]+k).fr) return printf("YES\n"),0; Update(a[i]); } return printf("NO\n"),0;}
阅读全文
0 0
- 【线段树+Hash】Codeforces452F[Permutation]题解
- Codeforces452F Permutation -- 线段树 + Hash
- 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 (线段树)
- Permutation 题解
- 线段树+hash+codeforces213E
- 线段树 + 字符串Hash
- 【BZOJ】【P3578】【GTY的人类基因组计划2】【题解】【线段树套set or 线段树+set+hash】
- 线段树-题解
- Permutation +uva+线段树+点修改
- Codeforces 452F Permutation【线段树】【哈希】
- [线段树+哈希] Codeforces 452F. Permutation
- hdu 3973(hash+线段树)
- python机器学习实战 getA()函数详解
- 判断两个字符串是否由相同的字符组成
- Java向上向下转型问题
- 数学 gcd
- 在乐视2手机上解决kindle阅读器即译时音标显示正常的问题
- 【线段树+Hash】Codeforces452F[Permutation]题解
- 计算单词数
- Windows7 创建右键发送到桌面的快捷方式
- 处理百万级以上的数据提高查询速度的方法。
- 从尾到头打印链表 【C++实现】
- hdu5972 Regular Number (bitset应用+快速匹配+shiftAnd匹配算法学习模板)
- 第二十课 管理事务处理
- 数字全排列
- mysql安装教程