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 [题目大意] 给出一颜色序列,每次可以修改一个位置的颜色或者询问一个区间不同颜色 ...
随机推荐
- 《数据结构与算法分析:C语言描述》读书笔记
我们数据结构的课用了这本英文教材,作者是Mark Allen Weiss.总体来说比<算法导论>简单很多,但内容上交集非常大.其实是因为去掉了大多数证明和数学,对于没有耐心看符号和公式的人 ...
- BufferedInputStream/BufferedOutputStream
BufferedInputStream: public synchronized int read() throws IOException int res=bis.read(); System.ou ...
- Python模块学习:logging 日志记录
原文出处: DarkBull 许多应用程序中都会有日志模块,用于记录系统在运行过程中的一些关键信息,以便于对系统的运行状况进行跟踪.在.NET平台中,有非常著名的第三方开源日志组件log4net ...
- Hadoop执行bin/stop-all.sh时no namenode to stop异常
1 先关闭hadoop所有服务 命令: bin/stop-all.sh 2 格式化namenode 命令: bin/hadoop namenode -format 3 重新启动所有服务 命令: bin ...
- poj1094拓扑排序
Sorting It All Out Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 29539 Accepted: 10 ...
- 基于phonegap,html5,ratchet,handlebars等技术的微表情APP
该app是由很多有意思的微表情构成的,支持40种表情,并且每种表情都有不同的状态,主要有搜索表情,分享表情,摇一摇换表情等功能.目前只支持安卓版.由前期构思,到技术选型,到界面设计,到编码测试,再到发 ...
- HDU 2131 Probability
http://acm.hdu.edu.cn/showproblem.php?pid=2131 Problem Description Mickey is interested in probabili ...
- 【Linux】——搭建nexus
1.安装 前提条件: JDK已经安装,运行java -version查看. 将本地下载好的nexus存放到linux上,存放路径为 /usr/local/software.可使用winscp直接拷贝. ...
- 基于Thinkphp5+phpQuery 网络爬虫抓取数据接口,统一输出接口数据api
TP5_Splider 一个基于Thinkphp5+phpQuery 网络爬虫抓取数据接口 统一输出接口数据api.适合正在学习Vue,AngularJs框架学习 开发demo,需要接口并保证接口不跨 ...
- javasisst & JAVA8
今天在服务器上启动tomcat7的时候,提示如下异常: java.io.IOException: invalid constant type: 15 具体看是javasisst抛出来的. 系统运行环境 ...