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. [软件共享]将数据库中的数据导出为SQL脚本

    可以直接将数据库中的数据导出为脚本,并可以自己设置过滤条件.使用方法很简单,不在多说了.下面是软件截图.123 下载:http://files.cnblogs.com/pw/mssql2.rar

  2. 全面解析Java语言 Java技能优化集锦

    通用篇 "通用篇"讨论的问题适合于大多数Java应用. 不用new关键词创建类的实例 用new关键词创建类的实例时,构造函数链中的所有构造函数都会被自动调用.但如果一个对象实现了C ...

  3. Docker PHP7官方镜像安装Redies扩展

    2019独角兽企业重金招聘Python工程师标准>>> 直接RUN docker-php-ext-install redis 失败,google得到: ENV PHPREDIS_VE ...

  4. 题解 P2261【[CQOI2007]余数求和】

    P2261[[CQOI2007]余数求和] 蒟蒻终于不看题解写出了一个很水的蓝题,然而题解不能交了 虽然还看了一下自己之前的博客 题目要求: \[\sum_{i=1}^{n}{k \bmod i} \ ...

  5. mysql的group by

    Group By 有几个规律: Group by的语法:"Group by <字段>“意为按照字段进行分类汇总.这里需要注意四点:        (1)按照你的分类要求Group ...

  6. tomcat 在linux下启动时找不到JDK

    方案一.  修改bashrc (转载: https://www.cnblogs.com/hongzg1982/articles/2101792.html)  $ vim ~/.bashrc #加入JA ...

  7. linux多线程入门

    linux下的多线程通过pthread实现,下面给个简单的例子. #include <stdio.h> #include <stdlib.h> #include <pth ...

  8. 似乎是最实用的hashtable知识总结

    哈希表:将对象转换为索引,然后存储在数组中. 定义注意点: 对象:就是面向对象中的对象,可以为任何东西.整数.浮点数.日期.字符串.类. 转换:通过hash函数来完成,hash函数是hash表的核心与 ...

  9. Vue实现靠边悬浮球(PC端)

    我想把退出登录的按钮做成一个悬浮球的样子,带动画的那种. 实现是这个样子: 手边没有球形图.随便找一个,功能这里演示的为单机悬浮球注销登录 嗯,具体代码: <div :class="[ ...

  10. mac下使用xampp中php显示1044/1045/1046(卸载xampp)

    问题描述 在mac下使用xampp,访问http://192.168.64.3/phpmyadmin/可以正常显示php页面,当创建数据库时提示1044也就是普通用户没有权限 问题猜测 猜测在使用xa ...