题目链接: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+带修改莫队)的更多相关文章

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

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

  2. CF940F Machine Learning(带修莫队)

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

  3. CF940F Machine Learning 带修改莫队

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

  4. BZOJ2120 数颜色(带修改莫队)

    本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000作者博客:http://www.cnblogs.com/ljh2000-jump/转 ...

  5. bzoj 2120 数颜色 带修改莫队

    带修改莫队,每次查询前调整修改 #include<cstdio> #include<iostream> #include<cstring> #include< ...

  6. BZOJ2120&2453数颜色——线段树套平衡树(treap)+set/带修改莫队

    题目描述 墨墨购买了一套N支彩色画笔(其中有些颜色可能相同),摆成一排,你需要回答墨墨的提问.墨墨会像你发布如下指令: 1. Q L R代表询问你从第L支画笔到第R支画笔中共有几种不同颜色的画笔. 2 ...

  7. BZOJ.2453.维护队列([模板]带修改莫队)

    题目链接 带修改莫队: 普通莫队的扩展,依旧从[l,r,t]怎么转移到[l+1,r,t],[l,r+1,t],[l,r,t+1]去考虑 对于当前所在的区间维护一个vis[l~r]=1,在修改值时根据是 ...

  8. [BZOJ4129]Haruna’s Breakfast(树上带修改莫队)

    BZOJ3585,BZOJ2120,BZOJ3757三合一. 对于树上路径问题,树链剖分难以处理的时候,就用树上带修改莫队. 这里的MEX问题,使用BZOJ3585的分块方法,平衡了时间复杂度. 剩下 ...

  9. BZOJ.3052.[WC2013]糖果公园(树上莫队 带修改莫队)

    题目链接 BZOJ 当然哪都能交(都比在BZOJ交好),比如UOJ #58 //67376kb 27280ms //树上莫队+带修改莫队 模板题 #include <cmath> #inc ...

随机推荐

  1. winform 删除,清空指定文件夹上的所有文件或文件夹

    //递归删除文件夹及子文件C#代码: public void DeleteFolder(string dir) { if (Directory.Exists(dir)) //如果存在这个文件夹删除之 ...

  2. C# Excel2007 导出生成 2003兼容格式

    //导出2007格式 AppWb.Saved = true; //保存工作薄 AppExcel.ActiveWorkbook.SaveCopyAs(FilePath); //导出2003格式 AppW ...

  3. 使用协程(gevent)实现请求

    协程,又称微线程.英文名Coroutine. 协程最大的优势就是协程极高的执行效率.因为子程序切换不是线程切换,而是由程序自身控制,因此,没有线程切换的开销,和多线程比,线程数量越多,协程的性能优势就 ...

  4. Unity3d学习日记(五)

      之前用3dsmax将模型转成FBX怎么也没有办法自动导入材质到Unity3d中(试过勾选了导出嵌入媒体,没用).索性试了试c4d,发现是可行的,看来像我这种菜鸡还是更加适合用c4d.   拿zoe ...

  5. JavaScript:理解事件、事件处理函数、钩子函数、回调函数

    详情请点击 http://www.jianshu.com/p/a0c580ed3432

  6. 【Redis】- 主从复制

    Redis跟MySQL一样,拥有非常强大的主从复制功能,而且还支持一个master可以拥有多个slave,而一个slave又可以拥有多个slave,从而形成强大的多级服务器集群架构. redis的主从 ...

  7. ASP.NET MVC 多语言解决方案

    1:打开VS,新建ASP.NET MVC4项目 2:创建一个放本地化资源的文件夹并命名为"Language",右键选择添加新项,选择资源文件并命名为"Com" ...

  8. Qt快速入门学习笔记(画图篇)

    1.Qt中提供了强大的2D绘图系统,可以使用相同的API在屏幕和绘图设备上进行绘制,它主要基于QPainter.QPaintDevice和QPaintEngine这三个类.其中QPainter用来执行 ...

  9. P1825 [USACO11OPEN]玉米田迷宫Corn Maze

    题目描述 This past fall, Farmer John took the cows to visit a corn maze. But this wasn't just any corn m ...

  10. 【刷题】SPOJ 1811 LCS - Longest Common Substring

    A string is finite sequence of characters over a non-empty finite set Σ. In this problem, Σ is the s ...