【BZOJ3207】花神的嘲讽计划Ⅰ hash+可持久化线段树
来源:互联网 发布:陌陌用什么软件定位 编辑:程序博客网 时间:2024/06/04 18:11
链接:
#include <stdio.h>int main(){ puts("转载请注明出处[vmurder]谢谢"); puts("网址:blog.csdn.net/vmurder/article/details/45688093");}
题解:
首先因为嘲讽长度固定,所以我们可以给每个点固定一个hash值(不固定的话我还真不会做)。
然后用可持久化线段树实现一段区间内有哪些数,然后查询一段区间是否有要的那个数就行了。
代码:
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define N 401000#define LOGN 20#define base 107#define inf 0x3f3f3f3fusing namespace std;int n,m,p;long long a[N],t[N],h[N];struct LSH{ long long x; int i,f; bool operator < (const LSH &A)const {return x<A.x;}}lsh[N];int root[N];struct Segment_Tree{ int l,r,x;}s[N*LOGN];int cnt;void add(int last,int &now,int l,int r,int x){ now=++cnt; if(l==r)s[now].x=s[last].x+1; else { int mid=l+r>>1; if(x<=mid) { add(s[last].l,s[now].l,l,mid,x); s[now].r=s[last].r; } else { s[now].l=s[last].l; add(s[last].r,s[now].r,mid+1,r,x); } s[now].x=s[s[now].l].x+s[s[now].r].x; } }bool ask(int last,int now,int l,int r,long long x){ if(s[now].x-s[last].x==0)return 0; if(lsh[r].x<x)return 0; if(lsh[l].x>x)return 0; if(lsh[l].x==x&&l==r)return 1; int mid=l+r>>1; if(x<=lsh[mid].x)return ask(s[last].l,s[now].l,l,mid,x); else return ask(s[last].r,s[now].r,mid+1,r,x);}int main(){ int i,j,k; int a,b,c; long long baser; scanf("%d%d%d",&n,&m,&p); for(i=1;i<=n;i++)scanf("%lld",&h[i]),h[i]+=h[i-1]*base; for(baser=i=1;i<=p;i++)baser*=base; for(i=n;i>=p;i--)h[i]-=h[i-p]*baser; for(i=p;i<=n;i++)lsh[i].x=h[i],lsh[i].i=i; sort(lsh+p,lsh+n+1); for(i=p;i<=n;i++) { if(i==p||lsh[i].x!=lsh[i-1].x)lsh[++cnt].x=lsh[i].x; h[lsh[i].i]=cnt; } for(k=cnt,cnt=0,i=p;i<=n;i++)add(root[i-1],root[i],1,k,h[i]); while(m--) { scanf("%d%d",&a,&b); for(baser=0,i=1;i<=p;i++) { scanf("%d",&c); baser=baser*base+c; } if(b-a<p)puts("Yes"); else if(ask(root[a+p-2],root[b],1,k,baser))puts("No"); else puts("Yes"); } return 0;}
0 0
- 【BZOJ3207】花神的嘲讽计划Ⅰ hash+可持久化线段树
- [BZOJ3207]花神的嘲讽计划Ⅰ(hash+可持久化线段树)
- BZOJ 3207 花神的嘲讽计划Ⅰ Hash+可持久化线段树
- 【BZOJ 3207】花神的嘲讽计划Ⅰ(Hash + 可持久化线段树)
- BZOJ-3207 花神的嘲讽计划Ⅰ ,hash+可持久化线段树
- [BZOJ3207][花神的嘲讽计划Ⅰ][主席树+Hash]
- BZOJ 3207 花神的嘲讽计划I Hash+可持久化线段树/划分树
- 【bzoj3207】花神的嘲讽计划Ⅰ hash
- 【bzoj3207】【花神的嘲讽计划I】【hash+主席树】
- BZOJ 3207 花神的嘲讽计划Ⅰ 可持久化线段树
- BZOJ3207 花神的嘲讽计划Ⅰ
- BZOJ3207: 花神的嘲讽计划Ⅰ
- BZOJ3207: 花神的嘲讽计划Ⅰ
- bzoj3207 花神的嘲讽计划Ⅰ
- bzoj3207: 花神的嘲讽计划Ⅰ
- bzoj3207: 花神的嘲讽计划Ⅰ( 主席树 (动态开点) + hash )
- bzoj3207 花神的嘲讽计划I
- Bzoj3207:花神的嘲讽计划Ⅰ&&Bzoj2653:middle
- C# 并行编程 之 Barrier的使用 - 通过屏障同步并发任务
- oracle的启动和关闭
- 复数类中的运算符重载(续)
- 第7周项目4-string类的构造
- 第九周 【项目1-复数类中的运算符重载(续)】
- 【BZOJ3207】花神的嘲讽计划Ⅰ hash+可持久化线段树
- 第九周 【项目4-我的向量类】
- 第九周项目二
- Oracle的AWR报告分析
- 第八周上机项目 阅读程序
- redo 和 undo
- 第7周项目4-string类的构造
- 2014年第九周项目一:复数类中的运算符重载(续)
- 新浪看看