题面

传送门

Sol

这题可能是假的

离线莫队搞一搞,把数字再分块搞一搞,就行了

# include <bits/stdc++.h>
# define IL inline
# define RG register
# define Fill(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long ll;
const int _(2e5 + 5); IL ll Input(){
RG char c = getchar(); RG ll x = 0, z = 1;
for(; c < '0' || c > '9'; c = getchar()) z = c == '-' ? -1 : 1;
for(; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
return x * z;
} int n, q, bl[_], val[_], ans[_], cnt[_], sum[_];
struct Qry{
int l, r, id;
IL bool operator <(RG Qry B) const{
return bl[l] != bl[B.l] ? bl[l] < bl[B.l] : r < B.r;
}
} qry[_]; IL void Modify(RG int x, RG int d){
if(d > 0){
if(!cnt[x]) ++sum[x / 500];
++cnt[x];
}
else{
--cnt[x];
if(!cnt[x]) --sum[x / 500];
}
} IL int Calc(){
RG int ret = 0;
for(RG int i = 0; ; ++i)
for(RG int j = 0; j < 500 && sum[i] != 500; ++j)
if(!cnt[i * 500 + j]) return i * 500 + j;
} int main(RG int argc, RG char* argv[]){
n = Input(); q = Input();
RG int blo = sqrt(n);
for(RG int i = 1; i <= n; ++i){
val[i] = Input();
bl[i] = (i - 1) / blo + 1;
}
for(RG int i = 1; i <= q; ++i) qry[i] = (Qry){Input(), Input(), i};
sort(qry + 1, qry + q + 1);
for(RG int L = qry[1].l, R = qry[1].l - 1, i = 1; i <= q; ++i){
while(L < qry[i].l) Modify(val[L], -1), ++L;
while(L > qry[i].l) --L, Modify(val[L], 1);
while(R < qry[i].r) ++R, Modify(val[R], 1);
while(R > qry[i].r) Modify(val[R], -1), --R;
ans[qry[i].id] = Calc();
}
for(RG int i = 1; i <= q; ++i) printf("%d\n", ans[i]);
return 0;
}

Luogu4137:Rmq Problem/mex的更多相关文章

  1. 【Luogu4137】Rmq Problem/mex (莫队)

    [Luogu4137]Rmq Problem/mex (莫队) 题面 洛谷 题解 裸的莫队 暴力跳\(ans\)就能\(AC\) 考虑复杂度有保证的做法 每次计算的时候把数字按照大小也分块 每次就枚举 ...

  2. 【luogu4137】 Rmq Problem / mex - 莫队

    题目描述 有一个长度为n的数组{a1,a2,…,an}.m次询问,每次询问一个区间内最小没有出现过的自然数. 思路 莫队水过去了 233 #include <bits/stdc++.h> ...

  3. 主席树||可持久化线段树+离散化 || 莫队+分块 ||BZOJ 3585: mex || Luogu P4137 Rmq Problem / mex

    题面:Rmq Problem / mex 题解: 先离散化,然后插一堆空白,大体就是如果(对于以a.data<b.data排序后的A)A[i-1].data+1!=A[i].data,则插一个空 ...

  4. 分块+莫队||BZOJ3339||BZOJ3585||Luogu4137||Rmq Problem / mex

    题面:P4137 Rmq Problem / mex 题解:先莫队排序一波,然后对权值进行分块,找出第一个没有填满的块,直接for一遍找答案. 除了bzoj3339以外,另外两道题Ai范围都是1e9. ...

  5. BZOJ 3339 && luogu4137 Rmq Problem / mex(莫队)

    P4137 Rmq Problem / mex 题目描述 有一个长度为n的数组{a1,a2,-,an}.m次询问,每次询问一个区间内最小没有出现过的自然数. 输入输出格式 输入格式: 第一行n,m. ...

  6. BZOJ3339&&3585 Rmq Problem&&mex

    BZOJ3339&&3585:Rmq Problem&&mex Description 有一个长度为n的数组{a1,a2,...,an}.m次询问,每次询问一个区间内最 ...

  7. P4137 Rmq Problem / mex (莫队)

    题目 P4137 Rmq Problem / mex 解析 莫队算法维护mex, 往里添加数的时候,若添加的数等于\(mex\),\(mex\)就不能等于这个值了,就从这个数开始枚举找\(mex\): ...

  8. 洛谷 P4137 Rmq Problem /mex 解题报告

    P4137 Rmq Problem /mex 题意 给一个长为\(n(\le 10^5)\)的数列\(\{a\}\),有\(m(\le 10^5)\)个询问,每次询问区间的\(mex\) 可以莫队然后 ...

  9. [bzoj3585] Rmq Problem / mex

    [bzoj3585] Rmq Problem / mex bzoj luogu 看上一篇博客吧,看完了这个也顺理成章会了( (没错这篇博客就是这么水) #include<cstdio> # ...

随机推荐

  1. linux 下创建GRE隧道

    其他国家的互联网如同一个孤岛.要想访问国外网站异常的缓慢,甚至被和谐了.可以建立一条隧道来避免这种情况,下面说说GRE隧道如何建立. 1. GRE介绍 GRE隧道是一种IP-over-IP的隧道,是通 ...

  2. H-ui.admin v2.3后台模版!

    一个很好的 后台开发模板 演示地址 http://demo.h-ui.net/H-ui.admin/3.1/index.html 下载地址 http://downs.h-ui.net/h-ui/H-u ...

  3. Linux 编译安装 php 扩展包 curl

    php源码目录:/root/php php编译目录:/usr/local/webserver/php/ curl源码目录:/root/curl 1.curl,主要用于发送http请求,是php的一个扩 ...

  4. CSS预处理器之Less详解

    本文最初发表于博客园,并在GitHub上持续更新前端的系列文章.欢迎在GitHub上关注我,一起入门和进阶前端. 以下是正文. CSS 预处理器 为什么要有 CSS 预处理器 CSS基本上是设计师的工 ...

  5. echarts legend 重叠 (转载)

    解决方案:  1. 调整option中的grid.top值才能避免重叠:(可以设置定制,也可以定义了一个计算公式) 2. 文档注明[特殊字符串 ''(空字符串)或者 '\n' (换行字符串)用于图例的 ...

  6. MVC5中使用Log4Net

    最早搜到的是这篇: http://www.codeproject.com/Articles/823247/How-to-use-Apache-log-net-library-with-ASP-NET- ...

  7. crack the coding interview

    crack the coding interview answer c++ 1.1 #ifndef __Question_1_1_h__  #define __Question_1_1_h__  #i ...

  8. iOS程序闪退的原因以及处理办法

    iOS程序闪退是一种比较常见的现象.闪退的情况很多,造成程序闪退的原因也很多. ================================启动时闪退======================= ...

  9. 在linux ubuntu下搭建深度学习/机器学习开发环境

    一.安装Anaconda 1.下载 下载地址为:https://www.anaconda.com/download/#linux 2.安装anaconda,执行命令: bash ~/Downloads ...

  10. hiho第151周 Building in Sandbox floodfill

    题意:题目背景是<<我的世界>>,堆方块造房子,堆的规则是:新堆的方块必须和已有方块有重合面,而且不能往封闭空间里堆. 在三维空间中,给定一个堆的序列,判断符不符合规则. 数据 ...