传送门

解题思路

  刚开始写了个莫队+哈希+$map$的$O(n\sqrt(n)log(n)$的辣鸡做法,$T$飞了。后来看了看别人博客发现其实并不用拿$map$当桶存那些哈希值。因为只有$n-k+1$个哈希值,可以提前预处理出来,然后离散化。时间复杂度$O(n\sqrt(n))$,比主席树都快。

代码

#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map> using namespace std;
typedef unsigned long long ull;
const int N=100005;
const int base=666623333; inline int rd(){
int x=0,f=1;char ch=getchar();
while(!isdigit(ch)) f=ch=='-'?0:1,ch=getchar();
while(isdigit(ch)) x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
return f?x:-x;
} int n,m,k,ans[N],siz,cnt[N],tot;
ull hsh[N],tb[N],a[N],cpy[N]; struct Query{
int l,r,id;
ull w;
friend bool operator<(const Query A,const Query B){
if(A.l/siz!=B.l/siz) return A.l<B.l;
if((A.l/siz)&1) return A.r>B.r;
return A.r<B.r;
}
}q[N]; inline void del(int x){
if(x+k-1>n) return;
cnt[a[x]]--;
} inline void add(int x){
if(x+k-1>n) return;
cnt[a[x]]++;
} int main(){
ull HSH; int x,y,pos; bool flag;
n=rd(),m=rd(),k=rd(); tb[0]=1; siz=sqrt(n);
for(int i=1;i<=n;i++){
x=rd();
hsh[i]=hsh[i-1]*base+x;
}
for(int i=1;i<=k;i++) tb[i]=tb[i-1]*base;
for(int i=1;i<=n-k+1;i++) a[++tot]=hsh[i+k-1]-hsh[i-1]*tb[k],cpy[tot]=a[tot];
sort(cpy+1,cpy+1+tot); int u=unique(cpy+1,cpy+1+tot)-cpy-1;
for(int i=1;i<=tot;i++) a[i]=lower_bound(cpy+1,cpy+1+u,a[i])-cpy;
for(int i=1;i<=m;i++){
x=rd(),y=rd(); flag=false; HSH=0; y=y-k+1;
for(register int j=1;j<=k;j++) HSH=HSH*base+rd();
pos=lower_bound(cpy+1,cpy+1+u,HSH)-cpy;
if(cpy[pos]!=HSH) q[i].w=0;
else q[i].w=pos;
q[i].l=x; q[i].r=y; q[i].id=i;
}
sort(q+1,q+1+m); int L=1,R=0;
for(int i=1;i<=m;i++){
while(L<q[i].l) {del(L); L++;}
while(L>q[i].l) {L--; add(L);}
while(R<q[i].r) {R++; add(R);}
while(R>q[i].r) {del(R); R--;}
ans[q[i].id]=(cnt[q[i].w]>0)?0:1;
}
for(int i=1;i<=m;i++) puts(ans[i]?"Yes":"No");
return 0;
}

最新文章

  1. Ajax请求安全性讨论
  2. oracle sql初次接触
  3. wamp环境PHP安装mongodb扩展
  4. MSIL 教程(二):数组、分支、循环、使用不安全代码和如何调用Win32 API(转)
  5. Java基础之处理事件——使用适配器类(Sketcher 3 using an Adapter class)
  6. Root resource classes
  7. XMPP 初探
  8. JS(一)
  9. 有一种acm题目叫做,奇葩!
  10. CSS之float属性解读
  11. Flask 构建微电影视频网站(八)
  12. antd table 点击行触发radio 或 checkbox
  13. LeetCode算法题-Kth Largest Element in a Stream(Java实现)
  14. python学习笔记第一节
  15. [NewLife.XCode]事务处理(算准你的每一分钱)
  16. python3使用selenium + Chrome基础操作代码
  17. Django 应用 静态文件配置
  18. Markdown显示反引号(`)
  19. 四、Factory Method 工厂方法模式
  20. [RN] 04 - React Navigation

热门文章

  1. Unity编程标准导引-3.1 Component 组件脚本及其基本生命周期
  2. 【已转移】【Java架构:基础技术】一篇文章搞掂:SVN
  3. Windows 08 R2_创建AD DS域服务(图文详解)
  4. left、pixelLeft、posLeft的区别
  5. svn没有权限检出项目
  6. 【刷题笔记】686. Repeated String Match
  7. 从0开始的InfiniBand硬件踩坑过程
  8. lua string.byte怎么判断是中文还是别的
  9. JavaScript DOM编程艺术-第一章
  10. 系统安装2---BIOS设置