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 ...
随机推荐
- iOS开发应用程序生命周期
各个程序运行状态时代理的回调: - (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSD ...
- TCP系列13—重传—3、协议中RTO计算和RTO定时器维护
从上一篇示例中我们可以看到在TCP中有一个重要的过程就是决定何时进行超时重传,也就是RTO的计算更新.由于网络状况可能会受到路由变化.网络负载等因素的影响,因此RTO也必须跟随网络状况动态更新.如果T ...
- sql 插入列放第一列
如果是SQLSERVER 的话就这样:select * from dbo.syscolumns where id=OBJECT_ID(N'你的表名') 然后COLID这列就是列的顺序 修改这个字段就行 ...
- 【Asp.Net Core】ASP.NET Core 2.0 + EF6 + Linux +MySql混搭
好消息!特好消息!同时使用ASP.NET Core 2.0和.NET Framework类库还能运行在linux上的方法来啦! 是的,你没有看错!ASP.NET Core 2.0,.NET Frame ...
- [洛谷P4999]烦人的数学作业
题目大意:定义$f(x)$表示$x$每一个数位(十进制)的数之和,求$\sum\limits_{i=l}^rf(i)$,多组询问. 题解:数位$DP$,可以求出每个数字的出现个数,再乘上每个数字的大小 ...
- [Leetcode] word search 单词查询
Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from l ...
- 如何给apk文件签名
1.签名的意义 为了保证每个应用程序开发商合法ID,防止部分开放商可能通过使用相同的Package Name来混淆替换已经安装的程序,我们需要对我们发布的APK文件进行唯一签名,保证我们每次发布的版本 ...
- 在某OC字符串中,搜索指定的某字符串:-rangeOfString:
NSString *originalStr = @"搜索:王者拜仁!"; NSString *subStr = @"搜索:"; // 在originalStr这 ...
- Codeforces Round #396 (Div. 2) A B C D 水 trick dp 并查集
A. Mahmoud and Longest Uncommon Subsequence time limit per test 2 seconds memory limit per test 256 ...
- Uva-oj Product 大数乘法
Product Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Status Des ...