Codeforces 452F
来源:互联网 发布:剑三明教正太捏脸数据 编辑:程序博客网 时间:2024/06/06 19:45
哈希学到不好。。。
假如,a+c=2*b
对于比b小的数左高位右低位求hash
对于比b小的数低高位右高位求hash
当两个hash值完全一样就gg掉
#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <algorithm>#include <set>#include <map>#include <vector>#include <stack>#include <cmath>#include <cassert>#include <bitset>using namespace std;typedef __int64 LL;typedef unsigned __int64 ULL;const int N = 300005;int n , a[N];ULL MAGIC = 3 , power[N];struct stree { ULL Hl , Hr;}t[N << 1];inline int id(int l , int r) {return l + r | l != r;}#define MID int mid = l + r >> 1#define Left l , mid#define Right mid + 1 , rinline void pushup(int p , int l , int mid , int r) { int L = id(Left) , R = id(Right); t[p].Hl = t[L].Hl * power[r - mid] + t[R].Hl; t[p].Hr = t[R].Hr * power[mid - l + 1] + t[L].Hr;}void update(int l , int r , int x , int w) { int p = id(l , r); if (l == r) { t[p].Hl = t[p].Hr = w + 1; return; } MID; if (x <= mid) update(Left , x , w); else update(Right , x , w); pushup(p , l , mid , r);}ULL gethashl(int l , int r , int top , int bot) { int p = id(l , r); if (top <= l && r <= bot) return t[p].Hl; MID; if (bot <= mid) return gethashl(Left , top , bot); else if (top > mid) return gethashl(Right , top , bot); else return gethashl(Left , top , mid) * power[bot - mid] + gethashl(Right , mid + 1 , bot);}ULL gethashr(int l , int r , int top , int bot) { int p = id(l , r); if (top <= l && r <= bot) return t[p].Hr; MID; if (bot <= mid) return gethashr(Left , top , bot); else if (top > mid) return gethashr(Right , top , bot); else return gethashr(Right , mid + 1 , bot) * power[mid - top + 1] + gethashr(Left , top , mid);}#define mid (l+r)/2void query(int l,int r){ int p=id(l,r); printf("%llu %llu %d %d %d\n",t[p].Hl,t[p].Hr,l,r,p); if(l==r){ return ; } query(l,mid); query(mid+1,r);}void work() { int i , x , y; scanf("%d",&n) ; for(int i=1;i<=n;i++)scanf("%d",&a[i]); power[0] = 1; for(int i=1;i<=n;i++)power[i]=power[i-1]*MAGIC; for (i = 1 ; i <= n ; ++ i) { update(1 , n , i , 0); } //query(1,n); for (i = 1 ; i <= n ; ++ i) { x = min(a[i] - 1 , n - a[i]); //[a[i] - x , a[i] - 1] //[a[i] + 1 , a[i] + x] if (x && gethashl(1 , n , a[i] - x , a[i] - 1) != gethashr(1 , n , a[i] + 1 , a[i] + x)) { puts("YES"); return; } update(1 , n , a[i] , 1); } puts("NO");}int main(){ #ifdef DouBi freopen("in.cpp","r",stdin); #endif // DouBi work(); return 0;}
0 0
- Codeforces 452F
- Codeforces 659F F
- 【集训讲课8.15】Codeforces 452F
- 【Codeforces】452F Permutation hash+线段树
- 【线段树+Hash】Codeforces 452F Permutation
- Codeforces 452F Permutation【线段树】【哈希】
- [线段树+哈希] Codeforces 452F. Permutation
- Codeforces 234 F. Fence
- 【Codeforces 500F】Dp
- codeforces 234F - Fence
- F-Logo Turtle codeforces
- 【CODEFORCES】 F. Ant colony
- Codeforces 567F
- CodeForces 241F Race
- Codeforces 611F 思维
- Codeforces 542F 构造
- codeforces 626f
- codeforces 622f
- 打造强大的Python开发环境--vim
- Java正则表达式之截取字符串
- Composer笔记(二):建立自己的PHP类库
- 文章标题
- 二分搜索
- Codeforces 452F
- 深入理解计算机各种类型大小(sizeof)
- web前端
- libjpeg 库的安装
- php 数组 类对象 值传递 引用传递 区别
- PhpStorm支持CI框架的代码提示自动补全(自己写的model类和Service类及类里的function的自动提示)(详细步骤)
- mysql5.5.49多实例安装
- Andriod资料库
- OpenGL 入门3