题目: 链接:https://codeforces.com/problemset/problem/940/F

题意:给你n个数,a[i]有q个操作,操作有两种:操作1.       1 x y 表示询问, mex{ c[ 1 ],c[ x + 1 ],...c[ 1e9 ] } 的值, 其中 c[i] 表示 a[ i ] 在 区间 [ x , y ] 出现的次数, (mex{   }  的意思呢,是从1开始数,第一个不出现在集合 {   }  里的数, 比如  mex{  1, 2,  4  } = = 3     因为此题是从1开始数 )       操作2.      2  p  x  将 a[ p ]  重新赋值 为 x                  对每个操作1 输出答案

思路: 将  a[ i ]  离散化  因为 数据有点大,然后找答案 直接 暴力 找   其他的基本上就是 带修莫队 的 模板了

#include<bits/stdc++.h>
#define LL long long
#define ULL unsigned long long
#define rep(i,j,k) for(int i=j;i<=k;i++)
#define dep(i,j,k) for(int i=k;i>=j;i--)
#define INF 0x3f3f3f3f
#define mem(i,j) memset(i,0,sizeof(i))
#define make(i,j) make_pair(i,j)
using namespace std;
const int N=2e5+;
int a[N],pos[N],num[N],cnt[N],now[N],p,ans[N],l=,r=; /// num就是a[i]在l,r出现的次数,然后cnt就是那个 mex { } 的集合
struct noq {
int l,r,id,t;
}q[N];
struct noc {
int x,old,ne;
}c[N];
map<int,int>vis; ///离散化 a[i] 需要
bool cmp(noq a,noq b) {
if(pos[a.l]==pos[b.l]) {
if(pos[a.r]==pos[b.r]) return a.t<b.t;
return pos[a.r]<pos[b.r];
}
return pos[a.l]<pos[b.l];
}
int get(int x) { /// 得到 离散化后的a[i]
if(vis[x]==) vis[x]=++p;
return vis[x];
}
void add(int x,int d) {
cnt[num[x]]--;
num[x]+=d;
cnt[num[x]]++;
}
void go(int x,int ne) {
if(l<=x && x<=r) {
add(a[x],-); add(ne,);
}
a[x]=ne;
}
int cal() {///找答案
for(int i=;;i++) if(cnt[i]==) return i;
}
int main() {
int n,m; int head=,tail=;
scanf("%d %d",&n,&m); int M=(int)pow(n,0.666666);
rep(i,,n) {
scanf("%d",&a[i]);
now[i]=a[i]=get(a[i]);
pos[i]=(i-)/M;
}
rep(i,,m) {
int ch; int x,y;
scanf("%d %d %d",&ch,&x,&y);
if(ch==) q[++head]=(noq){x,y,head,tail};
else {
y=get(y); ///记得y也要离散化,因为 now[x] 是 离散化后的 a[i]
c[++tail]=(noc){x,now[x],y};
now[x]=y;
}
}
sort(q+,q++head,cmp); int t=;
rep(i,,head) {
while(t<q[i].t) go(c[t+].x,c[t+].ne),++t;
while(t>q[i].t) go(c[t].x,c[t].old),--t;
while(l<q[i].l) add(a[l++],-);
while(l>q[i].l) add(a[--l],);
while(r<q[i].r) add(a[++r],);
while(r>q[i].r) add(a[r--],-);
ans[q[i].id]=cal();
}
rep(i,,head) printf("%d\n",ans[i]);
return ;
}

CF 940F - Machine Learning ( 带 修 )的更多相关文章

  1. F. Machine Learning 带修端点莫队

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

  2. Codeforces 940F Machine Learning 带修改莫队

    题目链接 题意 给定一个长度为\(n\)的数组\(a\),\(q\)个操作,操作分两种: 对于区间\([l,r]\),询问\(Mex\{c_0,c_1,c_2,⋯,c_{10^9}\}\),其中\(c ...

  3. Codeforces 940F Machine Learning (带修改莫队)

    题目链接  Codeforces Round #466 (Div. 2) Problem F 题意  给定一列数和若干个询问,每一次询问要求集合$\left\{c_{0}, c_{1}, c_{2}, ...

  4. CF940F Machine Learning 带修改莫队

    题意:支持两种操作:$1.$ 查询 $[l,r]$ 每个数字出现次数的 $mex$,$2.$ 单点修改某一位置的值. 这里复习一下带修改莫队. 普通的莫队中,以左端点所在块编号为第一关键字,右端点大小 ...

  5. CF940F Machine Learning(带修莫队)

    首先显然应该把数组离散化,然后发现是个带修莫队裸题,但是求mex比较讨厌,怎么办?其实可以这样求:记录每个数出现的次数,以及出现次数的出现次数.至于求mex,直接暴力扫最小的出现次数的出现次数为0的正 ...

  6. 【机器学习Machine Learning】资料大全

    昨天总结了深度学习的资料,今天把机器学习的资料也总结一下(友情提示:有些网站需要"科学上网"^_^) 推荐几本好书: 1.Pattern Recognition and Machi ...

  7. 机器学习(Machine Learning)&深度学习(Deep Learning)资料【转】

    转自:机器学习(Machine Learning)&深度学习(Deep Learning)资料 <Brief History of Machine Learning> 介绍:这是一 ...

  8. 机器学习(Machine Learning)与深度学习(Deep Learning)资料汇总

    <Brief History of Machine Learning> 介绍:这是一篇介绍机器学习历史的文章,介绍很全面,从感知机.神经网络.决策树.SVM.Adaboost到随机森林.D ...

  9. 机器学习(Machine Learning)&深度学习(Deep Learning)资料汇总 (上)

    转载:http://dataunion.org/8463.html?utm_source=tuicool&utm_medium=referral <Brief History of Ma ...

随机推荐

  1. Crossword Expert CodeForces - 1194F (期望)

    大意: $n$个题, 按照第$i$题随机$t_i$或$t_i+1$秒钟完成, 最多做$T$秒, 求做题数期望. 期望转为做题数$\ge x$的方案数之和最后再除以总方案数 这是因为$\sum\limi ...

  2. 怎样手写一个Object.create()方法

    Object.create()会将参数对象作为一个新创建的空对象的原型, 并返回这个空对象, 基于这个功能, 就有了下面这个Object.create()的手动实现: function _create ...

  3. C#获取Excel表格所有sheet名(Epplus)

    原文:C#获取Excel表格所有sheet名(Epplus) 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog. ...

  4. SOLID Principles

    Intention: more understandable, easier to maintain and easier to extend.(通过良好的设计使得代码easy and simple, ...

  5. Eclipse 反编译工具 jad

    ** 1 下载 jad工具 ** 2 将.exe文件放在jdk安装路径下,里面有java ,javac 等命令,然后将jad.jar放在eclipse的dropins目录下 ** 3 启动eclips ...

  6. MySQL修改默认编码 utf8

    修改liunux下MySql默认编码 1安装mysql后,启动服务并登陆,使用status m命令发现mysql的编码并不是 utf8! mysql> status; 2关闭mysql 服务: ...

  7. 安装mysql时出现 mysql Install/Remove of the Service Denied! 错误的解决办法

    用cmd在mysql的bin目录下面执行: mysqld --install 命令,出现错误: mysql Install/Remove of the Service Denied! 解决方法:以管理 ...

  8. Cause: com.mysql.jdbc.PacketTooBigException: Packet for query is too large (16944839 > 16777216). You can change this value on the server by setting the max_allowed_packet' variable.

    今天发现task微服务的error日志报如下错误: Cause: com.mysql.jdbc.PacketTooBigException: Packet for query is too large ...

  9. 如何解决js地址栏中传递中文乱码的问题

    目标要求: 实现从A页面跳转至B页面,B页面接收A页面通过地址栏传递过来的中文参数,中文不能出现乱码. A页面部分代码(传递参数): var title = "这是中文"; var ...

  10. 根据导入xlxs的文件,来写入数据库

    今天讲解一下上传文件.前台必须保持传参类型"multipart/form-data" 后台可以设定 public static final String MULTIPART_FOR ...