bzoj2453/2120 数颜色
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=2120
http://www.lydsy.com/JudgeOnline/problem.php?id=2453
【题解】
带修改莫队,分块大小n^(2/3),总复杂度O(n^(5/3))
简单说下,就是按照开始block,结束block,时间顺序分别排序后,不仅按照两个端点像莫队那样做,还把时间也按莫队那样做,就是维护恰好到询问时间的所有修改。
# include <math.h>
# include <stdio.h>
# include <string.h>
# include <iostream>
# include <algorithm>
// # include <bits/stdc++.h> using namespace std; typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int M = 2e5 + , N = 2e6 + ;
const int mod = 1e9+; # define RG register
# define ST static int n, m, a[M], t[M];
int BLOCK, bl[M];
struct pa {
int x, y, t;
pa() {}
pa(int x, int y, int t) : x(x), y(y), t(t) {}
friend bool operator < (pa a, pa b) {
return bl[a.x] < bl[b.x] || (bl[a.x] == bl[b.x] && bl[a.y] < bl[b.y]) ||
(bl[a.x] == bl[b.x] && bl[a.y] == bl[b.y] && a.t < b.t);
}
}q[M]; struct paa {
int x, oc, nc, t;
paa() {}
paa(int x, int oc, int nc, int t) : x(x), oc(oc), nc(nc), t(t) {}
}p[M]; int pn, qn, ans[M]; int c[N], cnt, L, R; inline void add(int x) {
++ c[a[x]];
if(c[a[x]] == ) ++cnt;
} inline void del(int x) {
-- c[a[x]];
if(c[a[x]] == ) --cnt;
} inline void DEL(int x) {
--c[x];
if(c[x] == ) --cnt;
} inline void ADD(int x) {
++c[x];
if(c[x] == ) ++cnt;
} int main() {
cin >> n >> m;
BLOCK = pow(n, 2.0/3.0);
for (int i=; i<=n; ++i) {
scanf("%d", a+i); t[i] = a[i];
bl[i] = (i-)/BLOCK + ;
}
char opt[];
for (int i=, x, y; i<=m; ++i) {
scanf("%s%d%d", opt, &x, &y);
if(opt[] == 'R') {
p[++pn] = paa(x, t[x], y, i);
t[x] = y;
} else q[++qn] = pa(x, y, i);
ans[i] = ;
}
sort(q+, q+qn+);
L = , R = ;
for (int i=, j=; i<=qn; ++i) {
while(j <= pn && q[i].t > p[j].t) {
if(L <= p[j].x && p[j].x <= R) DEL(p[j].oc), ADD(p[j].nc);
a[p[j].x] = p[j].nc; ++j;
}
while(j- >= && q[i].t < p[j-].t) {
--j; if(L <= p[j].x && p[j].x <= R) DEL(p[j].nc), ADD(p[j].oc);
a[p[j].x] = p[j].oc;
}
while(R < q[i].y) ++R, add(R);
while(R > q[i].y) del(R), --R;
while(L > q[i].x) --L, add(L);
while(L < q[i].x) del(L), ++L;
ans[q[i].t] = cnt;
}
for (int i=; i<=m; ++i)
if(ans[i]) printf("%d\n", ans[i]);
return ;
}
bzoj2453/2120 数颜色的更多相关文章
- Bzoj 2120: 数颜色 && 2453: 维护队列 莫队,分块,bitset
2120: 数颜色 Time Limit: 6 Sec Memory Limit: 259 MBSubmit: 2645 Solved: 1039[Submit][Status][Discuss] ...
- BZOJ 2120: 数颜色
2120: 数颜色 Time Limit: 6 Sec Memory Limit: 259 MBSubmit: 3623 Solved: 1396[Submit][Status][Discuss] ...
- BZOJ 2120 数颜色(带修改的莫队)
2120: 数颜色 Time Limit: 6 Sec Memory Limit: 259 MB Submit: 3478 Solved: 1342 [Submit][Status][Discus ...
- BZOJ 2120: 数颜色 分块
2120: 数颜色 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/problem.php? ...
- BZOJ 2120 数颜色 (带修莫队)
2120: 数颜色 Time Limit: 6 Sec Memory Limit: 259 MBSubmit: 6367 Solved: 2537[Submit][Status][Discuss] ...
- BZOJ 2120 数颜色 【带修改莫队】
任意门:https://www.lydsy.com/JudgeOnline/problem.php?id=2120 2120: 数颜色 Time Limit: 6 Sec Memory Limit: ...
- bzoj 2120 数颜色 题解
转载请注明:http://blog.csdn.net/jiangshibiao/article/details/23990489 [原题] 2120: 数颜色 Time Limit: 6 Sec M ...
- bzoj 2120 数颜色 (带修莫队)
题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=2120 题意:两种操作:Q 询问区间 l - r 内颜色的种类 ,R 单点修改 思路 ...
- BZOJ 2120 数颜色(带修改莫队)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2120 [题目大意] 给出一颜色序列,每次可以修改一个位置的颜色或者询问一个区间不同颜色 ...
随机推荐
- python中判断输入是否为数字(包括浮点数)
1.当num确定为数字后 num=123.4print(isinstance(num,float))#判断是否为浮点数 print(isinstance(num,int))#判断是否为整数 2.当nu ...
- Python的import导入与时间
一.模块与包 模块,在Python可理解为对应于一个文件.在创建了一个脚本文件后,定义了某些函数和变量.你在其他需要这些功能的文件中,导入这模块,就可重用这些函数和变量.一般用module_name. ...
- mutation与vuex区别
vuex- action 1.当点发送过快,页面中渲染的内容与state中的数据不一致,vuex里面的state变得慢,且不持续更新 2.action中是可以做到页面中state中数据保持一致 责 ...
- swarm 服务器安装
apt install docker.io-----------------------配置加速器.私有仓库地址---------------------mkdir -p /etc/dockertee ...
- 了解游戏编程与 AI
噫语系列... 闲话 最近在重写我的一个 QQ 群机器人项目,并尝试将它改成更通用的结构,以方便在未来加入对 Wechat 和 Telegram 的支持. 在查资料的过程中,发现很多人认为一个群内多人 ...
- Hadoop伪分布式安装步骤(hadoop0.20.2版本)
最近在学习hadoop,自己下了个视频教程,他的教学版本是hadoop0.20.2版本,现在的最新版本都到了3.0了,版本虽然有点老,但是还是学了一下,觉得有借鉴的价值. 不废话了,开始介绍: 先说一 ...
- JavaScript中注册时间处理程序的方式
基本的方式有两种: 一.第一种方式,出现在Web初期,给时间目标对象或文档元素设置属性. 1.设置JavaScript对象属性为事件处理程序. 示例: 缺点,这种设计都是围绕着假设每个事件目标对于每种 ...
- Map.Entry遍历Map
Map.entry是Java中的一个接口.每一个Map.entry代表一个map对象. 可以通过 Map是java中的接口,Map.Entry是Map的一个内部接口,它表示map中的一个实体(及一个k ...
- php array_merge和“+”的区别和使用《细说php2》
php array_merge和“+”的区别和使用
- clientHeight & clientWidth & offsetHeight & offsetWidth & outerWidth & innerWidth & outerWidth & outerHeight
clientHeight & clientWidth & offsetHeight & offsetWidth MDN https://developer.mozilla.or ...