传送门: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. 机器学习之-sklearn

    https://www.cnblogs.com/lianyingteng/p/7811126.html sklearn官方文档: http://scikit-learn.org/stable/

  2. 游戏测试中遇到的奇葩bug(不断整理中...)

    1:跨服组织战中,不同服务器相同组织ID的敌对玩家不能造成伤害. 2:节日活动24点开启,角色不下线自然过渡到活动开启,界面显示异常 3:前端请求数据之后,不管是否接收到后端返回的数据,只要玩家点击仙 ...

  3. 常用模块(chardet)

    作用:检测二进制的编码格式,不是百分百正确 import chardet f = open('test.txt', 'rb')data = f.read()print(data)result = ch ...

  4. Prometheus 普罗米修斯监控

    周末在家无聊 看新闻 看到关于监控的东西 拿来玩玩 试一下 感觉还蛮有意思 特此记录一下 这里只介绍客户端的配置 1:首先在POM中添加依赖 <dependency> <groupI ...

  5. 机器学习性能指标精确率、召回率、F1值、ROC、PRC与AUC--周振洋

    机器学习性能指标精确率.召回率.F1值.ROC.PRC与AUC 精确率.召回率.F1.AUC和ROC曲线都是评价模型好坏的指标,那么它们之间有什么不同,又有什么联系呢.下面让我们分别来看一下这几个指标 ...

  6. nohup追加日志

    背景:用脚本部署Spring Boot应用,用nohup命令进行后台运行 之前的日志处理: nohup command > myout.file 2>&1 & 导致每次用s ...

  7. Linux 进程,线程,线程池

    在linux内核,线程与进程的区别很小,或者说内核并没有真正所谓单独的线程的概念,进程的创建函数是fork,而线程的创建是通过clone实现的. 而clone与fork都是调用do_fork(),差异 ...

  8. lintcode-124-最长连续序列

    124-最长连续序列 给定一个未排序的整数数组,找出最长连续序列的长度. 说明 要求你的算法复杂度为O(n) 样例 给出数组[100, 4, 200, 1, 3, 2],这个最长的连续序列是 [1, ...

  9. 【Linux】——搭建redis

    1.准备安装文件 redis-3.0.5.tar.gz redis-desktop-manager(可视化管理工具) 2.解压.编译 软件存放目录:/usr/local/software 解压存放路径 ...

  10. Visual Studio 2012,创建工程Build Driver,基于纯Source Code.

    拿到一堆纯代码,怎么去Create Project,设置Include路径,lib路径,要不要Pre-compile技术,配置Project之间的依赖关系. SourcesConverter  Bas ...