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( ...
随机推荐
- 使用jquery-combobox实现select下拉框多选之后,如何将下拉框的值传给input隐藏域
我在之前的一篇博文中eaeyui-combobox实现组合查询(即实现多个值得搜索)地址:http://www.cnblogs.com/dushan/p/4778897.html 实现了select下 ...
- China Intelligent Office Summit(2018.11.21)
时间:2018.11.21地点:中关村软件园国际会议中心
- ML.NET 示例:多类分类之问题分类
写在前面 准备近期将微软的machinelearning-samples翻译成中文,水平有限,如有错漏,请大家多多指正. 如果有朋友对此感兴趣,可以加入我:https://github.com/fei ...
- “论 ofo 是如何影响今日头条发展的”
近段时间, ofo 小黄车押金难退的消息频频曝出.尽管 OFO 已经宣布押金只能在线上退还,但是线上退押金也难,因此很多的用户还是选择到 ofo 北京总部“要个说法”.记者昨天在现场发现,位于北京中关 ...
- ABP+AdminLTE+Bootstrap Table权限管理系统第十一节--Bootstrap Table用户管理列表以及Module Zero之用户管理
返回总目录:ABP+AdminLTE+Bootstrap Table权限管理系统一期 用户实体 用户实体代表应用的一个用户,它派生自AbpUser类,如下所示: public class User : ...
- 利用卷积神经网络(VGG19)实现火灾分类(附tensorflow代码及训练集)
源码地址 https://github.com/stephen-v/tensorflow_vgg_classify 1. VGG介绍 1.1. VGG模型结构 1.2. VGG19架构 2. 用Ten ...
- ssh登陆服务器locale告警(-bash: warning: setlocale:)的处理方法
使用ssh远程登陆 IDC机房服务器,发现老是出现如下告警信息: -bash: warning: setlocale: LC_CTYPE: cannot change locale (en_US.UT ...
- python基础学习笔记(三)
序列概览 Python 包含6 种内建的序列,这里重点讨论最常用的两种类型:列表和元组. 列表与元组的主要区别在于,列表可以修改,元组则不能.也就是说如果要根据要求来添加元素,那么列表可以会更好用:而 ...
- C_数据结构_循环队列
# include <stdio.h> # include <malloc.h> typedef struct Queue { int * pBase; int front; ...
- c#代码分析
代码分析是在一个IT行业计算机程序员必须要具有的基本专业技能,在了解一定的专业基础之上去看懂别人编写的代码,分析别人代码实现的功能,以及基本的维护和扩展测试.不同的人有不同的代码风格,要使自己的能要别 ...