题目: 链接: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. win8系统安装.net Framework3.5

    Win8 离线安装 .Net Framework 3.5(工具+方法)(支持Win8.1) 微软在最新的 Win8 / Win8.1 系统中没有集成 .NET 3.5,如果安装的话,必须是在线安装,甚 ...

  2. React/数据流

    “Props” 当 React 元素为用户自定义组件时,它会将 JSX 所接收的属性(attributes)转换为单个对象传递给组件,这个对象被称之为 “props”. props的只读性 组件无论是 ...

  3. Struts2系列漏洞起始篇

    前言 到目前位置struts2的漏洞编号已经到了S2-057,一直想系统的学习下Struts2的漏洞,但由于工作量较大,一直搁浅.最近由于工作需要,借此机会来填下坑.个人认为一个框架漏洞出来了仅仅看下 ...

  4. Oracle 11G 数据库迁移【expdp/impdp】

    转自:http://www.th7.cn/db/Oracle/201802/263773.shtml 0x01 环境 A 机器,操作系统 CentOS7.3,Oracle版本:11G,IP地址:192 ...

  5. liunx shell 脚本的基础知识

    Shell脚本编程30分钟入门====================## 什么是Shell脚本### 示例看个例子吧: #!/bin/sh cd ~ mkdir shell_tut cd shell ...

  6. Oracle学习笔记——imp还原数据库

    1.     创建用户及指定用户名密码 create user [用户名] identified by [密码]; create user fskxjsxy  identified by fskxjs ...

  7. 阿里高级架构师教你如何使用Spring Cloud Ribbon重试请求

    在微服务调用中,一些微服务圈可能调用失败,通过再次调用以达到系统稳定性效果,本文展示如何使用Ribbon和Spring Retry进行请求再次重试调用. 在Spring Cloud中,使用load b ...

  8. COM_STMT_PREPARE 1

    mysqld_stmt_prepare void mysqld_stmt_prepare(THD* thd, const char * query, uint length, Prepared_sta ...

  9. 一分钟了解Linux文件系统

    Linux文件系统原理在所有的操作系统中文件都有文件名与数据,在Linux系统上文件系统分成两个部分:用户数据 (user data) 与元数据 (metadata).用户数据,即文件数据块 (dat ...

  10. 版本问题---cuda和tensorflow的版本对应关系

    cuda和tensorflow的版本有对应关系 https://tensorflow.google.cn/install/source#linux