题意:给定一个n个数的数字序列,第i个数为a[i],每次操作会将a[i]插入或移到最前端:

1.若a[i]已经在序列中出现过,则将其移到最前端,并删除原出现位置

2.若a[i]未出现过,则直接将其插入到最前端

有q个询问,每个询问给出一个长度为m的序列,问是否在某个时刻询问序列与操作的序列相同,忽略后缀的0

n<=5e3,q<=2e3,sigma m<=2e6

思路:做法一:

实现参考了claris的代码,使用自然溢出哈希,下标标记的方法避免了重新排序或者map之类的带log,现场应该必挂

cf打多了确实喜欢为了方便加个map多个log之类的,还是要做BZOJ的时限紧张题

 #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> PII;
typedef pair<ll,ll> Pll;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef pair<ll,ll>P;
#define N 200010
#define M 1000000
#define INF 1e9
#define fi first
#define se second
#define MP make_pair
#define pb push_back
#define pi acos(-1)
#define mem(a,b) memset(a,b,sizeof(a))
#define rep(i,a,b) for(int i=(int)a;i<=(int)b;i++)
#define per(i,a,b) for(int i=(int)a;i>=(int)b;i--)
#define lowbit(x) x&(-x)
#define Rand (rand()*(1<<16)+rand())
#define id(x) ((x)<=B?(x):m-n/(x)+1)
#define ls p<<1
#define rs p<<1|1
#define fors(i) for(auto i:e[x]) if(i!=p) const int MOD=1e8+,inv2=(MOD+)/;
int p=1e4+;
double eps=1e-;
int dx[]={-,,,};
int dy[]={,,-,}; int a[N],b[N],ans[N],len[N],n;
ull c[N],h[N]; int read()
{
int v=,f=;
char c=getchar();
while(c<||<c) {if(c=='-') f=-; c=getchar();}
while(<=c&&c<=) v=(v<<)+v+v+c-,c=getchar();
return v*f;
} ll readll()
{
ll v=,f=;
char c=getchar();
while(c<||<c) {if(c=='-') f=-; c=getchar();}
while(<=c&&c<=) v=(v<<)+v+v+c-,c=getchar();
return v*f;
} void calc(int n)
{
rep(i,,n) h[i]=h[i-]*p+b[i];
} void add(int x)
{
int k=;
rep(i,,n)
if(b[i]==x){k=i; break;}
if(k)
{
per(i,k,) b[i]=b[i-];
b[]=x;
}
else
{
per(i,n+,) b[i]=b[i-];
b[]=x;
}
} void solve()
{
n=read();
int q=read();
rep(i,,n) a[i]=read();
rep(i,,q)
{
int m=read();
len[i]=m;
rep(j,,m) b[j]=read();
calc(m);
c[i]=h[m];
ans[i]=;
}
rep(i,,n) b[i]=;
rep(i,,n)
{
if(i) add(a[i]);
calc(n);
rep(j,,q)
if(h[len[j]]==c[j]) ans[j]=;
}
rep(i,,q)
if(ans[i]) printf("Yes\n");
else printf("No\n");
} int main()
{
//freopen("1.in","r",stdin);
//freopen("1.out","w",stdout);
int cas=read();
while(cas--) solve();
return ;
}

【gym102394L】LRU Algorithm(自然溢出哈希)的更多相关文章

  1. 自然溢出哈希 hack 方法

    今天不知道在什么地方看到这个东西,感觉挺有意思的,故作文以记之( 当 \(base\) 为偶数时,随便造一个长度 \(>64\) 的字符串,只要它们后 \(64\) 位相同那么俩字符串的哈希值就 ...

  2. [CCPC2019 哈尔滨] L. LRU Algorithm - 哈希

    [CCPC2019 哈尔滨] L. LRU Algorithm Description 对一个序列执行 LRU 算法.每次询问给定一个窗口,问它是否出现过. Solution 很显然我们可以先假设窗口 ...

  3. LRU Algorithm Gym - 102394L (HASH)

    LRU Algorithm \[ Time Limit: 1000 ms\quad Memory Limit: 524288 kB \] 题意 给出 \(n\) 个数字和 \(m\) 次查询. 每次询 ...

  4. 关于如何让写自然溢出hash的无辜孩子见祖宗这件事

    关于如何让写自然溢出hash的无辜孩子见祖宗这件事 来源博客 这几天考试连着好几次被卡hash卡到死. 我谔谔,为什么连hash都要卡. 码力弱鸡什么时候才能站起来. 只需要任意两种字符,比如噫呜呜噫 ...

  5. Operating System Memory Management、Page Fault Exception、Cache Replacement Strategy Learning、LRU Algorithm

    目录 . 引言 . 页表 . 结构化内存管理 . 物理内存的管理 . SLAB分配器 . 处理器高速缓存和TLB控制 . 内存管理的概念 . 内存覆盖与内存交换 . 内存连续分配管理方式 . 内存非连 ...

  6. 转:MD5(Message-Digest Algorithm 一种哈希算法)

    什么是MD5算法 MD5讯息摘要演算法(英语:MD5 Message-Digest Algorithm),一种被广泛使用的密码杂凑函数,可以产生出一个128位元(16位元组)的散列值(hash val ...

  7. [Algorithm] 局部敏感哈希算法(Locality Sensitive Hashing)

    局部敏感哈希(Locality Sensitive Hashing,LSH)算法是我在前一段时间找工作时接触到的一种衡量文本相似度的算法.局部敏感哈希是近似最近邻搜索算法中最流行的一种,它有坚实的理论 ...

  8. [algorithm][security] 模糊哈希(转)

    modsecurity中用到:  http://ssdeep.sourceforge.net/ 原文:http://www.xuebuyuan.com/1536438.html 最近看一篇paper, ...

  9. 【BZOJ3529】数表(莫比乌斯反演,BIT,自然溢出)

    题意: 思路: #include<cstdio> #include<cstring> #include<string> #include<cmath> ...

随机推荐

  1. hbase的读写过程

    hbase的读写过程: hbase的架构: Hbase真实数据hbase真实数据存储在hdfs上,通过配置文件的hbase.rootdir属性可知,文件在/user/hbase/下hdfs dfs - ...

  2. Nmap Windows 版本时区显示乱码

    Nmap 版本 $ nmap --version Nmap version 7.80 ( https://nmap.org ) Platform: i686-pc-windows-windows Co ...

  3. laravel框架之批刪&全選&全不選&反選

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. java.lang.ClassNotFoundException: org.springframework.web.filter.CharacterEncodingFilter的解决方案

    白天在实验室的电脑上的项目搭起来,晚上回到宿舍发现跑不起来了,网上查到的大多不是想要的答案. 最终的解决方案是maven clean一下再重新package.

  5. ReactNative: Android与iOS平台兼容处理

    方法一: 创建不同的文件扩展名:*.android.js*.io.js 方法二: import { Platform } from 'react-native'; if (Platform.OS == ...

  6. C++ new、delete、namespace关键字。

    C++ 中的动态内存分配: C++与C语言分配内存关键字不同,C语言中的动态内存分配是通过 malloc(分配内存) 与 free(释放内存)完成.C++使用new(分配内存)  delete(释放内 ...

  7. 17.AutoMapper 之配置(Configuration)

    https://www.jianshu.com/p/031ff68797dd 配置(Configuration) 通过构造函数创建并初始化MapperConfiguration实例: config = ...

  8. go依赖包管理工具vendor基础

    go依赖包管理工具vendor基础 vendor是go的依赖包管理工具,主要用于管理项目中使用到的一些依赖. 它将项目依赖的包,特指外部包,复制到当前工程下的vendor目录下,这样go build的 ...

  9. 吴恩达深度学习:2.15python中的广播

    1.Broadcasting example (1)下面矩阵描述了来自四种不同的100克碳水化合物,蛋白质和脂肪的卡路里数量 比如说100g苹果所含的热量有56克来自碳水化合物,相比之下来自蛋白质和脂 ...

  10. TableView 两种Style Plain and Group 区别以及进阶使用

    一.UITableViewStylePlain 1.有多段时 段头停留(自带效果) 2.没有中间的间距和头部间距(要想有的重写UITableViewCell /UITableViewHeaderFoo ...