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 ...
随机推荐
- TCP系列06—连接管理—5、TCP fastopen(TFO)
一.TFO背景 当前web和web-like应用中一般都是在三次握手后开始数据传输,相比于UDP,多了一个RTT的时延,即使当前很多应用使用长连接来处理这种情况,但是仍然由一定比例的短连接,这额外多出 ...
- <Effective C++>读书摘要--Designs and Declarations<二>
<Item 20> Prefer pass-by-reference-to-const to pass-by-value 1.By default, C++ passes objects ...
- asp.net中Repeater结合js实现checkbox的全选/全不选
前台界面代码: <input name="CheckAll" type="checkbox" id="CheckAll" value= ...
- ZigBee设备入网流程之关联方式
ZigBee设备入网流程 ZigBee设备入网有关联方式和直接方式两种,我所熟悉的是关联方式,这也是最常用的方式. 关联方式 step1 设备发出Beacon Request 设备会在预先设置的几个信 ...
- python爬虫 妹子图片网
代码如下 #coding=utf-8 import os import re import urllib from time import sleep import requests from lxm ...
- tomcat8配置管理员后仍然报403
tomcat8配置管理员后仍然报403 修改conf/tomcat-users.xml <role rolename="manager"/> <role ro ...
- 修改IP的批处理
昨天遇到一个客户,说是抢火车票来着,用了3个公网IP,要求在抢票前15分钟换次IP(看我这毛病,废话多了,正题) 系统是2003 32位的 因为自己不懂脚本,网上找了个修改了下,就有了下面的脚本: 首 ...
- MongoDb企业应用实战(一) 写在MongoDB应用介绍之前(ii)
上一篇: MongoDb企业应用实战(一) 写在MongoDB应用介绍之前(i) 有段时间没跟大家去分享和探讨过一些问题,分享过一些经验了(失败过的,痛苦过的才最有看点啊,不知道各位同仁们怎么去看这个 ...
- VisualVM使用方法
VisualVM 简介 VisualVM 是一个工具,它提供了一个可视界面,用于查看 Java 虚拟机 (Java Virtual Machine, JVM) 上运行的基于 Java 技术的应用程序( ...
- mysql 迁移 mariadb
背景: mysql5.7数据库安装在windows环境中,数据需要迁移到CentOS7.4的mariadb5.5中.web应用是采用springboot2.x开发的,迁移数据完成后,还需要简单修改一些 ...