F. Machine Learning
time limit per test

4 seconds

memory limit per test

512 megabytes

input

standard input

output

standard output

You come home and fell some unpleasant smell. Where is it coming from?

You are given an array a. You have to answer the following queries:

  1. You are given two integers l and r. Let ci be the number of occurrences of i in al: r, where al: r is the subarray of a from l-th element to r-th inclusive. Find the Mex of {c0, c1, ..., c109}
  2. You are given two integers p to x. Change ap to x.

The Mex of a multiset of numbers is the smallest non-negative integer not in the set.

Note that in this problem all elements of a are positive, which means that c0 = 0 and 0 is never the answer for the query of the second type.

Input

The first line of input contains two integers n and q (1 ≤ n, q ≤ 100 000) — the length of the array and the number of queries respectively.

The second line of input contains n integers — a1, a2, ..., an (1 ≤ ai ≤ 109).

Each of the next q lines describes a single query.

The first type of query is described by three integers ti = 1, li, ri, where 1 ≤ li ≤ ri ≤ n — the bounds of the subarray.

The second type of query is described by three integers ti = 2, pi, xi, where 1 ≤ pi ≤ n is the index of the element, which must be changed and 1 ≤ xi ≤ 109 is the new value.

Output

For each query of the first type output a single integer  — the Mex of {c0, c1, ..., c109}.

Example
Input

Copy
10 4
1 2 3 1 1 2 2 2 9 9
1 1 1
1 2 8
2 7 1
1 2 8
Output

#include<cstdio>
#include<cstring>
#include<map>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=2e5+;
map<int,int>M;
int vis[N],num[N],a[N],b[N],now[N],ans[N],unit,l,r,t;
struct Query{
int l,r,tim,id;
bool operator < (const Query &A)const{
return l/unit==A.l/unit?(r/unit==A.r/unit?tim<A.tim:r<A.r):l<A.l;
}
}Q[N];
struct Change{
int pos,x,y;
}C[N];
void modify(int x,int d){
--vis[num[x]];num[x]+=d;++vis[num[x]];
}
void going(int T,int d){
if(C[T].pos>=l&&C[T].pos<=r) modify(C[T].x,d),modify(C[T].y,-d);
if(d==) a[C[T].pos]=C[T].x;else a[C[T].pos]=C[T].y;
}
int calc(){
for(int i=;;++i) if(!vis[i]) return i;
}
int main(){
int n,q,tot,op,cc=,pp=;
scanf("%d%d",&n,&q);
for(int i=;i<=n;++i) scanf("%d",&a[i]),now[i]=b[i]=a[i];
tot=n,unit=(int)pow(n,0.6666666);
for(int i=;i<=q;++i) {
scanf("%d",&op);
if(op==){
++cc,scanf("%d%d",&C[cc].pos,&C[cc].x);
C[cc].y=now[C[cc].pos],b[++tot]=now[C[cc].pos]=C[cc].x;
}
else {
++pp,scanf("%d%d",&Q[pp].l,&Q[pp].r);
Q[pp].tim=cc,Q[pp].id=pp;
}
}
sort(b+,b+tot+);
tot=unique(b+,b+tot+)-b-;
for(int i=;i<=tot;++i) M[b[i]]=i;
for(int i=;i<=n;++i) a[i]=M[a[i]];
for(int i=;i<=cc;++i) C[i].x=M[C[i].x],C[i].y=M[C[i].y];
sort(Q+,Q+pp+);
for(int i=;i<=pp;++i) {
while(t<Q[i].tim) going(t+,),++t;
while(t>Q[i].tim) going(t,-),--t; while(l<Q[i].l) modify(a[l],-),++l;
while(l>Q[i].l) modify(a[l-],),--l;
while(r<Q[i].r) modify(a[r+],),++r;
while(r>Q[i].r) modify(a[r],-),--r;
ans[Q[i].id]=calc(); }
for(int i=;i<=pp;++i) printf("%d\n",ans[i]);
}

2
3
2

莫队学习博客

F. Machine Learning 带修端点莫队的更多相关文章

  1. 学习笔记——不带修序列莫队 (luogu2079)小B的询问

    莫队是一种对于询问的离线算法 时间复杂度:O(\(n \sqrt n\)) 大致思想就是 首先将询问离线,然后对原序列分块,使得每一个\(l和r\)都在一个块里 然后按照左节点排序,若所在的块相等,就 ...

  2. codeforces 940F 带修改的莫队

    F. Machine Learning time limit per test 4 seconds memory limit per test 512 megabytes input standard ...

  3. 【bzoj4129】Haruna’s Breakfast 带修改树上莫队+分块

    题目描述 给出一棵树,点有点权.支持两种操作:修改一个点的点权,查询链上mex. 输入 第一行包括两个整数n,m,代表树上的结点数(标号为1~n)和操作数.第二行包括n个整数a1...an,代表每个结 ...

  4. P1903 [国家集训队]数颜色 / 维护队列 带修改的莫队

    \(\color{#0066ff}{ 题目描述 }\) 墨墨购买了一套N支彩色画笔(其中有些颜色可能相同),摆成一排,你需要回答墨墨的提问.墨墨会向你发布如下指令: 1. Q L R代表询问你从第L支 ...

  5. UOJ 58 (树上带修改的莫队)

    UOJ 58 糖果公园 Problem : 给一棵n个点的树,每个点上有一种颜色,对于一条路径上的点,若 i 颜色第 j 次出现对该路径权值的贡献为 w[i] * c[j], 每次询问一条路径的权值, ...

  6. BZOJ 2120: 数颜色 带修改的莫队算法 树状数组套主席树

    https://www.lydsy.com/JudgeOnline/problem.php?id=2120 标题里是两种不同的解法. 带修改的莫队和普通莫队比多了个修改操作,影响不大,但是注意一下细节 ...

  7. 【BZOJ】2120: 数颜色 带修改的莫队算法

    [题意]给定n个数字,m次操作,每次询问区间不同数字的个数,或修改某个位置的数字.n,m<=10^4,ai<=10^6. [算法]带修改的莫队算法 [题解]对于询问(x,y,t),其中t是 ...

  8. 【bzoj3052】[wc2013]糖果公园 带修改树上莫队

    题目描述 给出一棵n个点的树,每个点有一个点权,点权范围为1~m.支持两种操作:(1)修改一个点的点权 (2)对于一条路径,求$\sum\limits_{i=1}^m\sum\limits_{j=1} ...

  9. UVA - 12345 带修改的莫队

    题意显然:给出初始序列,单点修改,区间查询元素的种类. 由于时限过宽,暴力可过. 比较优秀的解法应该是莫队. 带修改的莫队题解可以看https://www.luogu.org/blog/user126 ...

随机推荐

  1. cut,xargs,sort,tr,rename命令解析

    cut 文件内容查看 显示行中的指定部分,删除文件中指定字段 显示文件的内容,类似于下的type命令. 语法: cut(选项)(参数) 选项: -b:仅显示行中指定直接范围的内容: -c:仅显示行中指 ...

  2. Neditor 2.1.16 发布,修复缩放图片问题

    开发四年只会写业务代码,分布式高并发都不会还做程序员?   BUG 修复 修复缩放图片时,鼠标mouseUp后图片还是在缩放 by @ShinyHwong Demo:  https://demo.ne ...

  3. Greenplum列存压缩表索引机制

    列存压缩表,简称AOCS表 数据生成 create table testao(date text, time text, open float, high float, low float, volu ...

  4. php并发加锁

    CleverCode在工作项目中,会遇到一些php并发访问去修改一个数据问题,如果这个数据不加锁,就会造成数据的错误.下面CleverCode将分析一个财务支付锁的问题. 1 没有应用锁机制 1.1 ...

  5. 从零开始制作数据集所需要的所有python脚本

    最近一直在做图片数据集,积累了很多心得.我把我所使用的python脚本全部拿出来,当然这些脚本大部分网上都有,只不过比较分散. 我已经把所有代码上传到github上,觉得写的好的话,请给我一个star ...

  6. muduo网络库源码学习————日志类封装

    muduo库里面的日志使方法如下 这里定义了一个宏 #define LOG_INFO if (muduo::Logger::logLevel() <= muduo::Logger::INFO) ...

  7. andorid jar/库源码解析之Butterknife

    目录:andorid jar/库源码解析 Butterknife: 作用: 用于初始化界面控件,控件方法,通过注释进行绑定控件和控件方法 栗子: public class MainActivity e ...

  8. schedule定时任务出现问题 (大坑已填)!!

    因为python每次运行完,并不清除内存,nowtime一直不变,这导致了一个致命问题,使我的脚本一直运行失败,具体如下: 我设置的是每隔30分钟登陆一次,代码如下 if __name__ == &q ...

  9. 002_python的in,while else,格式化输出,逻辑运算符,int与bool转换,编码

    数据 1.什么是数据? x=10,10是我们要存储的数据 2.为何数据要分不同的类型 数据是用来表示状态的,不同的状态就应该用不同的类型的数据去表示 3.数据类型 数字 字符串 列表 元组 字典 集合 ...

  10. vue项目中使用bpmn-自定义platter

    前情提要 经过前四篇的学习,我们能够实现bpmn基本绘图.预览.为节点加事件加颜色等效果,这一篇我们来说,如何自定义左侧工具栏(platter),首先看一下自定义前后效果图对比: 我们本次要实现的目标 ...