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. JS实现元素的全屏、退出全屏功能

     在实际开发中,我们很可能需要实现某一元素的全屏和退出全屏功能,如canvas.所幸的是,js提供了相关api用来处理这一问题,只需简单的调用requestFullScreen.exitFullScr ...

  2. springBoot(6):web开发-模板引擎jsp

    一.新建工程 注意新建的工程下没有webapp目录eclipse下会自动创建webapp目录这里我们需要自动创建一个webapp目录并创建WEB-INF. 对ServletInitializer.ja ...

  3. postman(全局变量设置)

    全局变量 全局变量作用于整个postman工具及所有环境 1.点击小齿轮进入到变量添加页面,点击Globals添加全局变量 2.输入变量名称和变量值 3.接口中设置变量 4.调用 Globals 变量 ...

  4. 看直播 csust oj

    看直播 Description 小明喜欢看直播,他订阅了很多主播,主播们有固定的直播时间 [Li, Ri] . 可是他网速只有2M,不能同时播放两个直播,所以同一时间只能看一个直播. 并且他只会去看能 ...

  5. php使用curl post josn数据

    今天在工作中使用到要使用("Content-Type", "application/json;charset=UTF-8")格式传送和接受数据,再次做个记录 p ...

  6. shell脚本传参执行spark-submit

    读取多个目录下的本地文件,多个目录通过循环遍历的方式,以参数传递: #!/bin/bash i=0while [ $i -lt 10000 ] do echo "i=$i" spa ...

  7. Coursera课程笔记----计算导论与C语言基础----Week 5

    从现实问题到计算机程序(Week 5) 总结回顾 计算机只能按照程序去执行,不可能自己"想出"一个解决问题的方法 面对一个问题,你必须自己找到解决方案,才有可能做出相应的程序 所以 ...

  8. git使用-忽略文件更新的几种方法

    有几种情况我们不希望本地文件在 git 里面得到更新. 一.情况:始终不需要git跟踪本地的一些文件 方法:使用.gitignore文件忽略 解释: 使用git init操作创建git控制管理之后,默 ...

  9. vue-cli中浏览器图标的配置

    在VUE全家桶项目里面,这里给大家提供了2种方案,进行浏览器图标的配置. a):先把图片准备好,放在static文件夹下,再找到根目录下的index.html文件,并打开,在HTML文档的<he ...

  10. ObjectOutputStream:对象的序列化流 ObjectInputStream:对象的反序列化流

    package com.itheima.demo04.ObjectStream; import java.io.FileOutputStream; import java.io.IOException ...