传送门: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 数颜色的更多相关文章

  1. Bzoj 2120: 数颜色 && 2453: 维护队列 莫队,分块,bitset

    2120: 数颜色 Time Limit: 6 Sec  Memory Limit: 259 MBSubmit: 2645  Solved: 1039[Submit][Status][Discuss] ...

  2. BZOJ 2120: 数颜色

    2120: 数颜色 Time Limit: 6 Sec  Memory Limit: 259 MBSubmit: 3623  Solved: 1396[Submit][Status][Discuss] ...

  3. BZOJ 2120 数颜色(带修改的莫队)

    2120: 数颜色 Time Limit: 6 Sec  Memory Limit: 259 MB Submit: 3478  Solved: 1342 [Submit][Status][Discus ...

  4. BZOJ 2120: 数颜色 分块

    2120: 数颜色 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/problem.php? ...

  5. BZOJ 2120 数颜色 (带修莫队)

    2120: 数颜色 Time Limit: 6 Sec  Memory Limit: 259 MBSubmit: 6367  Solved: 2537[Submit][Status][Discuss] ...

  6. BZOJ 2120 数颜色 【带修改莫队】

    任意门:https://www.lydsy.com/JudgeOnline/problem.php?id=2120 2120: 数颜色 Time Limit: 6 Sec  Memory Limit: ...

  7. bzoj 2120 数颜色 题解

    转载请注明:http://blog.csdn.net/jiangshibiao/article/details/23990489 [原题] 2120: 数颜色 Time Limit: 6 Sec  M ...

  8. bzoj 2120 数颜色 (带修莫队)

    题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=2120 题意:两种操作:Q 询问区间  l - r  内颜色的种类 ,R 单点修改 思路 ...

  9. BZOJ 2120 数颜色(带修改莫队)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2120 [题目大意] 给出一颜色序列,每次可以修改一个位置的颜色或者询问一个区间不同颜色 ...

随机推荐

  1. 配置ORACLE的PRO*C环境

    1.访问数据库的方法    在ORACLE数据库管理和系统中,有三种访问数据库的方法:    ⑴.用SQL*Plus, 它有SQL命令以交互的应用程序访问数据库:    ⑵.用第四代语言应用开发工具开 ...

  2. FPGA数字鉴相鉴频器的开发记录

    1. 对于电机的锁相控制,需要对相差进行PI性质的环路滤波,但现有的锁相环中鉴频鉴相器输出为相差脉冲而非数字量,难以直接进行PI特性的环路滤波. 通过对晶振的非整数分频获取准确的参考时钟,基于触发器机 ...

  3. CentOS修改网卡名称

    转 一.问题说明 测试环境中出现的小问题,因为虚拟机之间经常复制来复制去,导致网卡配置这块的不一致现象. 配置文件的信息: [root@ora10g network-scripts]# catifcf ...

  4. 在Linux中安装和配置OpenVPN Server的最简便方法!

    本文介绍了如何在基于RPM和DEB的系统中安装和配置OpenVPN服务器.我们在本文中将使用一个名为openvpn-install的脚本,它使整个OpenVPN服务器的安装和配置过程实现了自动化.该脚 ...

  5. XML与Object的范型转换

    前段时间做object转换xml想了很多,所有打算整理下 做成以下的通用方法. public static bool ObjectToXml<T>(string filePath, T t ...

  6. 【C#】 语法糖

    [C#] 语法糖 一, 扩展方法 1. 对某个类功能上的扩展 2. 特点: 使用方便,可以在不修改原代码的基础上进行扩展. 参照 linq,linq 就是一系列的扩展方法 3. 语法: 非泛型静态类, ...

  7. C++学习009预处理器指令符号 # ## #@ 符号的使用

    # ## #@ 符号是预处理器指令符号. 当预处理器遇到#指令符号时,会将#之后的部分用双引号括起来 当预处理去遇到##指令符号时,直接将##前后部分连接起来 当预处理器遇到#@指令符号,将#@之后的 ...

  8. CSS3 : box-shadow

    box-shadow 用于设置边框阴影,语法: box-shadow: h-shadow v-shadow blur spread color inset; -moz-box-shadow: h-sh ...

  9. Go基础篇【第8篇】: 内置库模块 bytes [二]

    type Reader ¶ type Reader struct { // 内含隐藏或非导出字段 } Reader类型通过从一个[]byte读取数据,实现了io.Reader.io.Seeker.io ...

  10. 201621044079《Java程序设计》第1周学习总结

    1. 本周学习总结 首先要认识到java这门课程的重要性 了解java语言的发展历史 以及java的特点(*跨平台) 了解JDK JRE JVM的含义以及关系 JVM 是实现平台无关性的关键 学会独立 ...