F. Machine Learning 带修端点莫队
4 seconds
512 megabytes
standard input
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:
- 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}
- 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.
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.
For each query of the first type output a single integer — the Mex of {c0, c1, ..., c109}.
10 4
1 2 3 1 1 2 2 2 9 9
1 1 1
1 2 8
2 7 1
1 2 8
#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 带修端点莫队的更多相关文章
- 学习笔记——不带修序列莫队 (luogu2079)小B的询问
莫队是一种对于询问的离线算法 时间复杂度:O(\(n \sqrt n\)) 大致思想就是 首先将询问离线,然后对原序列分块,使得每一个\(l和r\)都在一个块里 然后按照左节点排序,若所在的块相等,就 ...
- codeforces 940F 带修改的莫队
F. Machine Learning time limit per test 4 seconds memory limit per test 512 megabytes input standard ...
- 【bzoj4129】Haruna’s Breakfast 带修改树上莫队+分块
题目描述 给出一棵树,点有点权.支持两种操作:修改一个点的点权,查询链上mex. 输入 第一行包括两个整数n,m,代表树上的结点数(标号为1~n)和操作数.第二行包括n个整数a1...an,代表每个结 ...
- P1903 [国家集训队]数颜色 / 维护队列 带修改的莫队
\(\color{#0066ff}{ 题目描述 }\) 墨墨购买了一套N支彩色画笔(其中有些颜色可能相同),摆成一排,你需要回答墨墨的提问.墨墨会向你发布如下指令: 1. Q L R代表询问你从第L支 ...
- UOJ 58 (树上带修改的莫队)
UOJ 58 糖果公园 Problem : 给一棵n个点的树,每个点上有一种颜色,对于一条路径上的点,若 i 颜色第 j 次出现对该路径权值的贡献为 w[i] * c[j], 每次询问一条路径的权值, ...
- BZOJ 2120: 数颜色 带修改的莫队算法 树状数组套主席树
https://www.lydsy.com/JudgeOnline/problem.php?id=2120 标题里是两种不同的解法. 带修改的莫队和普通莫队比多了个修改操作,影响不大,但是注意一下细节 ...
- 【BZOJ】2120: 数颜色 带修改的莫队算法
[题意]给定n个数字,m次操作,每次询问区间不同数字的个数,或修改某个位置的数字.n,m<=10^4,ai<=10^6. [算法]带修改的莫队算法 [题解]对于询问(x,y,t),其中t是 ...
- 【bzoj3052】[wc2013]糖果公园 带修改树上莫队
题目描述 给出一棵n个点的树,每个点有一个点权,点权范围为1~m.支持两种操作:(1)修改一个点的点权 (2)对于一条路径,求$\sum\limits_{i=1}^m\sum\limits_{j=1} ...
- UVA - 12345 带修改的莫队
题意显然:给出初始序列,单点修改,区间查询元素的种类. 由于时限过宽,暴力可过. 比较优秀的解法应该是莫队. 带修改的莫队题解可以看https://www.luogu.org/blog/user126 ...
随机推荐
- Spring5参考指南:AspectJ高级编程之Configurable
文章目录 遇到的问题 @Configurable 原理 重要配置 遇到的问题 前面的文章我们讲到了在Spring中使用Aspect.但是Aspect的都是Spring管理的Bean. 现在有一个问题, ...
- 解决material UI中弹窗(dialog、popover等)内容被遮挡问题
在material ui中有几种弹出层,比如:dialog.popover等,这些弹出层都会遇到的一个公共问题是: 假如弹出层中的内容变化了,弹出层的位置并不会重新定位. 这样,假如一开始弹出层定位在 ...
- 【React踩坑记五】React项目中引入并使用react-ace代码编辑插件(自定义列表提示)
最近有一个引入sql编辑器插件的需求,要求代码高亮显示,代码智能提示,以及支持自定义代码提示列表等功能.中途在自定义代码提示列表中由于没有相关demo,所以踩了一些坑,遂将其整理如下,以便日后查看. ...
- android开发之自定义View 详解 资料整理 小冰原创整理,原创作品。
2019独角兽企业重金招聘Python工程师标准>>> /** * 作者:David Zheng on 2015/11/7 15:38 * * 网站:http://www.93sec ...
- 《Redis设计与实现》之第十二章:事件
Redis服务器是一个事件驱动程序,服务器需要处理两类事件: 文件事件: 文件事件就是服务器对套接字(socket)操作的抽象,服务器和客户端的通信会产生文件事件 时间事件: 时间事件就是服务器对定时 ...
- 记一次Pinpoint监控工具部署过程
环境:Centos 7.4 X64IP:192.168.1.11 1.配置环境,先安装jdk 到Oracle官网下载安装JDK https://www.oracle.com/technetwork/j ...
- MySQL5.7 并行复制
MySQL5.7 并行复制 1.缘由: 某天看到主从复制延时的告警有点频繁,就想着是不是彻底可以解决一下. 一般主从复制,有三个线程参与,都是单线程:Binlog Dump(主) ----->I ...
- 与IBM的Lin Sun关于Istio 1.0和微服务的问答
北京时间 7 月 31 日,Istio 正式发布了 1.0 版本,并表示已经可用于生产环境.该版本的主要新特性包括跨集群 mesh 支持.细粒度流量控制以及在一个 mesh 中增量推出 mutual ...
- Java 常用API(二)
目录 Java 常用API(二) 1. Object类 2. Date类 概述 构造方法和成员方法 3. DateFormat类 概述 SimpleDateFormat类 练习 4. Calendar ...
- 一文教你快速搞懂 FOC ramp function 斜坡函数的作用和实现
文章目录 定义 程序的实现 matlab 程序 C语言程序 定义 x(t)={0,t<0At,t≥0 x(t) = \begin{cases} 0,t<0\\ At,t \ge 0\\ \ ...