Machine Learning(CF940F+带修改莫队)
题目链接:http://codeforces.com/problemset/problem/940/F
题目:


题意:求次数的mex,mex的含义为某个集合(如{1,2,4,5})第一个为出现的非负数(3),注意是次数,而不是某个元素的mex。
思路:这一题数据太大,所以我们首先得进行一次离散化。用一个num2来记录每个次数出现次数,num1来记录次数出现次数,最后用一个for循环来求出mex。
代码实现如下:
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; typedef long long ll;
typedef unsigned long long ull; #define bug printf("*********\n");
#define FIN freopen("in.txt", "r", stdin);
#define debug(x) cout<<"["<<x<<"]" <<endl;
#define IO ios::sync_with_stdio(false),cin.tie(0); const double eps = 1e-;
const int mod = 1e9 + ;
const int maxn = 1e5 + ;
const double pi = acos(-);
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f; inline int read() {//读入挂
int ret = , c, f = ;
for(c = getchar(); !(isdigit(c) || c == '-'); c = getchar());
if(c == '-') f = -, c = getchar();
for(; isdigit(c); c = getchar()) ret = ret * + c - '';
if(f < ) ret = -ret;
return ret;
} int n, q, block, idq, idc, x, y;
int a[maxn], num1[ * maxn], num2[ * maxn];
vector<int> v; struct query {
int l, r, id, t, ans;
bool operator < (const query& x) const {
if((l - ) / block != (x.l - ) / block) {
return l < x.l;
}
if((r - ) / block != (x.r - ) / block) {
return r < x.r;
}
return t < x.t;
}
}ask[maxn]; struct modify {
int p, pre, val;
}myf[maxn]; int get_id(int x) {
return lower_bound(v.begin(), v.end(), x) - v.begin() + ;
} void add(int x) {
num1[num2[x]]--;
num2[x]++;
num1[num2[x]]++;
} void del(int x) {
num1[num2[x]]--;
num2[x]--;
num1[num2[x]]++;
} int main() {
//FIN;
num1[] = 1e8;
n = read();
q = read();
block = ;
for(int i = ; i <= n; i++) {
a[i] = read();
v.push_back(a[i]);
}
int nw = ;
for(int i = ; i <= q; i++) {
int op;
op = read();
if(op == ) {
x = read();
y = read();
idq++;
ask[idq].l = x, ask[idq].r = y;
ask[idq].id = idq;
ask[idq].t = nw;
} else {
x = read();
y = read();
idc++;
nw++;
myf[idc].p = x;
myf[idc].pre = a[x];
myf[idc].val = y;
a[x] = y;
v.push_back(y);
}
}
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
sort(ask + , ask + idq + );
for(int i = ; i <= n; i++) {
a[i] = get_id(a[i]);
}
for(int i = ; i <= idc; i++) {
myf[i].pre = get_id(myf[i].pre);
myf[i].val = get_id(myf[i].val);
}
int tmp = nw, r = , l = ;
for(int i = ; i <= idq; i++) {
int res = ;
while(r > ask[i].r) {
del(a[r--]);
}
while(r < ask[i].r) {
add(a[++r]);
}
while(l > ask[i].l) {
add(a[--l]);
}
while(l < ask[i].l) {
del(a[l++]);
}
while(tmp < ask[i].t) {
tmp++;
if(myf[tmp].p >= l && myf[tmp].p <= r) {
del(myf[tmp].pre);
add(myf[tmp].val);
}
a[myf[tmp].p] = myf[tmp].val;
}
while(tmp > ask[i].t) {
if(myf[tmp].p >= l && myf[tmp].p <= r) {
del(myf[tmp].val);
add(myf[tmp].pre);
}
a[myf[tmp].p] = myf[tmp].pre;
tmp--;
}
while(num1[res] > ) res++;
ask[ask[i].id].ans = res;
}
for(int i = ; i <= idq; i++) {
printf("%d\n", ask[i].ans);
}
return ;
}
Machine Learning(CF940F+带修改莫队)的更多相关文章
- Codeforces 940F Machine Learning (带修改莫队)
题目链接 Codeforces Round #466 (Div. 2) Problem F 题意 给定一列数和若干个询问,每一次询问要求集合$\left\{c_{0}, c_{1}, c_{2}, ...
- CF940F Machine Learning(带修莫队)
首先显然应该把数组离散化,然后发现是个带修莫队裸题,但是求mex比较讨厌,怎么办?其实可以这样求:记录每个数出现的次数,以及出现次数的出现次数.至于求mex,直接暴力扫最小的出现次数的出现次数为0的正 ...
- CF940F Machine Learning 带修改莫队
题意:支持两种操作:$1.$ 查询 $[l,r]$ 每个数字出现次数的 $mex$,$2.$ 单点修改某一位置的值. 这里复习一下带修改莫队. 普通的莫队中,以左端点所在块编号为第一关键字,右端点大小 ...
- BZOJ2120 数颜色(带修改莫队)
本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000作者博客:http://www.cnblogs.com/ljh2000-jump/转 ...
- bzoj 2120 数颜色 带修改莫队
带修改莫队,每次查询前调整修改 #include<cstdio> #include<iostream> #include<cstring> #include< ...
- BZOJ2120&2453数颜色——线段树套平衡树(treap)+set/带修改莫队
题目描述 墨墨购买了一套N支彩色画笔(其中有些颜色可能相同),摆成一排,你需要回答墨墨的提问.墨墨会像你发布如下指令: 1. Q L R代表询问你从第L支画笔到第R支画笔中共有几种不同颜色的画笔. 2 ...
- BZOJ.2453.维护队列([模板]带修改莫队)
题目链接 带修改莫队: 普通莫队的扩展,依旧从[l,r,t]怎么转移到[l+1,r,t],[l,r+1,t],[l,r,t+1]去考虑 对于当前所在的区间维护一个vis[l~r]=1,在修改值时根据是 ...
- [BZOJ4129]Haruna’s Breakfast(树上带修改莫队)
BZOJ3585,BZOJ2120,BZOJ3757三合一. 对于树上路径问题,树链剖分难以处理的时候,就用树上带修改莫队. 这里的MEX问题,使用BZOJ3585的分块方法,平衡了时间复杂度. 剩下 ...
- BZOJ.3052.[WC2013]糖果公园(树上莫队 带修改莫队)
题目链接 BZOJ 当然哪都能交(都比在BZOJ交好),比如UOJ #58 //67376kb 27280ms //树上莫队+带修改莫队 模板题 #include <cmath> #inc ...
随机推荐
- LintCode-373.奇偶分割数组
奇偶分割数组 分割一个整数数组,使得奇数在前偶数在后. 样例 给定 [1, 2, 3, 4],返回 [1, 3, 2, 4]. 挑战 在原数组中完成,不使用额外空间. 标签 数组 两根指针 code ...
- error LNK2019: 无法解析的外部符号 该符号在函数 中被引用 解决方案
需要添加lib或者dll库.项目-属性-配置属性-链接器-输入-附件依赖项,添加需要的lib. 例如我在运行OSG程序的时候,忘记添加了附件依赖项就会报这个错. 解决方案如图.
- JTS空间分析工具包(GIS开源)学习 JAVA
JST空间分析工具包是一套JAVA API,提供一系列的空间数据分析操作.最近开发项目刚好需要用到,上网搜资料也少,就自己写下来记录一下.C++版本的拓扑分析开源工具叫:geos:.NET版本的拓扑分 ...
- python实现post请求
今天无论如何都要留下一些什么东西... 可以说今天学到一个新的一个东西,也需要分享出来,给更多的人去使用. 今天爬取的数据里面是客户端向服务器端发送加密过的token和一些页码之类的一个数据.(我主要 ...
- Linux文件传输FTP详解
ftp命令用来设置文件系统相关功能.ftp服务器在网上较为常见,Linux ftp命令的功能是用命令的方式来控制在本地机和远程机之间传送文件,这里详细介绍Linux ftp命令的一些经常使用的命令,相 ...
- 内存交换空间(swap)的构建
一.使用物理分区构建swap 1.先进行分区的行为. [root@iZ255cppmtxZ ~]# fdisk /dev/xvdb Welcome to fdisk (util-linux ). Ch ...
- Android各分辨率定义的图片规格
我们定义的app图片规格 app图标需要分iphone和android两套 iphone: 名称 Iphone4 Iphone5 手机尺寸 960*640(高*宽) 1136*640 (高*宽) 电池 ...
- [剑指Offer] 65.矩阵中的路径
题目描述 请设计一个函数,用来判断在一个矩阵中是否存在一条包含某字符串所有字符的路径.路径可以从矩阵中的任意一个格子开始,每一步可以在矩阵中向左,向右,向上,向下移动一个格子.如果一条路径经过了矩阵中 ...
- 【bzoj1877】[SDOI2009]晨跑 费用流
题目描述 Elaxia最近迷恋上了空手道,他为自己设定了一套健身计划,比如俯卧撑.仰卧起坐等 等,不过到目前为止,他坚持下来的只有晨跑. 现在给出一张学校附近的地图,这张地图中包含N个十字路口和M条街 ...
- Linux内核中的常用宏container_of其实很简单
http://blog.csdn.net/npy_lp/article/details/7010752 通过一个结构体变量的地址,求该结构体的首地址. #ifndef CONTAINER_OF #de ...