BZOJ3207花神的嘲讽计划Ⅰ——主席树+hash
题目描述
输入
输出
样例输入
1 2 3 4 5 6 7 8
2 5 2 3 4
1 8 3 2 1
5 7 4 5 6
2 5 1 2 3
1 7 3 4 5
样例输出
Yes
Yes
Yes
No
提示
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define mid L+((R-L)>>1)
using namespace std;
const int base=13131;
int n,m,k;
int cnt;
int tot;
int x,y,z;
int l[8000010];
int r[8000010];
int sum[8000010];
int root[200010];
unsigned long long h[200010];
unsigned long long s[200010];
int updata(int pre,unsigned long long L,unsigned long long R,unsigned long long x)
{
int rt=++cnt;
l[rt]=l[pre];
r[rt]=r[pre];
sum[rt]=sum[pre]+1;
if(L<R)
{
if(x<=mid)
{
l[rt]=updata(l[pre],L,mid,x);
}
else
{
r[rt]=updata(r[pre],mid+1,R,x);
}
}
return rt;
}
bool query(int ll,int rr,unsigned long long L,unsigned long long R,unsigned long long k)
{
if(L>=R)
{
if(sum[rr]-sum[ll]!=0)
{
return true;
}
return false;
}
int x=sum[rr]-sum[ll];
if(x!=0)
{
if(k<=mid)
{
query(l[ll],l[rr],L,mid,k);
}
else
{
query(r[ll],r[rr],mid+1,R,k);
}
}
else
{
return false;
}
}
int main()
{
scanf("%d%d%d",&n,&m,&k);
s[0]=1;
for(int i=1;i<=n;i++)
{
scanf("%d",&x);
h[i]=h[i-1]*base+x;
s[i]=s[i-1]*base;
}
for(int i=k;i<=n;i++)
{
unsigned long long a=h[i]-h[i-k]*s[k];
root[i]=updata(root[i-1],0,18446744073709551615ull,a);
}
for(int i=1;i<=m;i++)
{
scanf("%d%d",&x,&y);
unsigned long long a=0;
for(int j=1;j<=k;j++)
{
scanf("%d",&z);
a=a*base+z;
}
x+=k-1;
if(x>y)
{
printf("Yes\n");
continue;
}
if(query(root[x-1],root[y],0,18446744073709551615ull,a)==true)
{
printf("No\n");
}
else
{
printf("Yes\n");
}
}
}
BZOJ3207花神的嘲讽计划Ⅰ——主席树+hash的更多相关文章
- bzoj 3207 花神的嘲讽计划Ⅰ 主席树+hash
花神的嘲讽计划Ⅰ Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 3112 Solved: 1086[Submit][Status][Discuss] ...
- [BZOJ3207] 花神的嘲讽计划Ⅰ (主席树)
Description 背景 花神是神,一大癖好就是嘲讽大J,举例如下: “哎你傻不傻的![hqz:大笨J]” “这道题又被J屎过了!!” “J这程序怎么跑这么快!J要逆袭了!” …… 描述 这一天D ...
- BZOJ3207: 花神的嘲讽计划Ⅰ(hash)
3207: 花神的嘲讽计划Ⅰ Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 3569 Solved: 1258[Submit][Status][Di ...
- [bzoj3207][花神的嘲讽计划Ⅰ] (字符串哈希+主席树)
Description 背景 花神是神,一大癖好就是嘲讽大J,举例如下: “哎你傻不傻的![hqz:大笨J]” “这道题又被J屎过了!!” “J这程序怎么跑这么快!J要逆袭了!” …… 描述 这一天D ...
- BZOJ3207 花神的嘲讽计划I
Time Limit: 10 Sec Memory Limit: 128 MB Summary 给你一个模式串P,q个询问,对每个询问回答从Pl到Pr是否存在与给定串相同的子串,同时有所有的给定串长度 ...
- BZOJ3207 花神的嘲讽计划
hash值建主席树. 垃圾题面没有熟虑范围害我MLE——>RE. By:大奕哥 #include<bits/stdc++.h> #define unll unsigned long ...
- [bzoj3207]花神的嘲讽计划Ⅰ[可持久化线段树,hash]
将每k个数字求一个哈希值,存入可持久化线段树,直接查询即可 #include <iostream> #include <algorithm> #include <cstd ...
- BZOJ3207: 花神的嘲讽计划Ⅰ
显然hash,然后stl随便搞. #include<bits/stdc++.h> #define N 100005 using namespace std; typedef unsigne ...
- bzoj3207花神的嘲讽计划Ⅰ
题意:http://www.lydsy.com/JudgeOnline/problem.php?id=3207 给定一个原字符串和m个询问,每次查询原字符串[l,r]内是否包含给定字符串s (len( ...
随机推荐
- kubespray 容器存储设备 -- rook ceph
1./root/kubespray/roles/docker/docker-storage/defaults/main.yml #在用kubespray部署集群是制定docker用什么设备 dock ...
- GIT 分支管理:分支管理策略、Bug分支、Feature分支
通常,合并分支时,如果可能,Git会用Fast forward模式,但这种模式下,删除分支后,会丢掉分支信息. 如果要强制禁用Fast forward模式,Git就会在merge时生成一个新的comm ...
- Identity(五)
本文摘自 ASP.NET MVC 随想录—— 使用ASP.NET Identity实现基于声明的授权,高级篇 在这篇文章中,我将继续ASP.NET Identity 之旅,这也是ASP.NET Ide ...
- java計算年齡的工具類
整理一篇Java計算年齡的工具類,方便實用 public static int getAgeByBirth(String birthday) throws ParseException { // 格式 ...
- BZOJ3676 APIO2014 回文串 Manacher、SA
传送门 首先一个结论:串\(S\)中本质不同的回文串个数最多有\(|S|\)个 证明考虑以点\(i\)结尾的所有回文串,假设为\(S[l_1,i],S[l_2,i],...,S[l_k,i]\),其中 ...
- UVA10559&POJ1390 Blocks 区间DP
题目传送门:http://poj.org/problem?id=1390 题意:给出一个长为$N$的串,可以每次消除颜色相同的一段并获得其长度平方的分数,求最大分数.数据组数$\leq 15$,$N ...
- Bitcoin 使用及配置记录
常用配置 bitcoin-qt.exe -testnet -printtoconsole -conf=D:\Bitcoin\bitcoin.conf -datadir=D:\Bitcoin\Data ...
- Luogu P3374 【模板】树状数组 1
真正的模板题. 树状数组的思想很简单(不如说背代码更简单),每个节点记录多个节点的信息(每个点存x&(-x)个). 道理可以参见很多大佬的博客,最后前缀和的思想搞一下就好了.不想说也不会说. ...
- 【php增删改查实例】第二十节 - 把用户管理页面集成到main.php中
把这个代码: <a href="javascript:openTab('用户管理','user/userManage.html ','icon-roleManage')" c ...
- [Socket]Socket聊天小程序
一个简单是Socket聊天小程序,读写操作在不同的线程中.服务器端采用线程池. 1.Server import java.io.IOException; import java.net.ServerS ...