AC日记——数颜色 bzoj 2120
思路:
带修改的莫队;
对于离线排序询问的算法,如何修改呢?
每个询问添加一个修改标记;
表示当前询问在第几个修改之后;
然后把修改标记作为第三关键字来排序;
每次更新端点,先更新时间;
块的大小为n的2/3次方;
来,上代码:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; #define maxn 100050 struct QueryType {
int l,r,t,id;
};
struct QueryType qu[maxn]; struct ChangeType {
int to,x,h;
};
struct ChangeType cha[maxn]; int n,m,size=,tot,num,ai[maxn],bel[maxn],ti[maxn*],ans[maxn];
int now; bool if_[maxn]; inline void in(int &now)
{
char Cget=getchar();now=;
while(Cget>''||Cget<'') Cget=getchar();
while(Cget>=''&&Cget<='')
{
now=now*+Cget-'';
Cget=getchar();
}
} bool cmp(QueryType aa,QueryType bb)
{
if(bel[aa.l]==bel[bb.l])
{
if(bel[aa.r]==bel[bb.r]) return aa.t<bb.t;
else return aa.r<bb.r;
}
else return aa.l<bb.l;
} inline void change(int x)
{
if(if_[cha[x].to])
{
ti[ai[cha[x].to]]--;
if(!ti[ai[cha[x].to]]) now--;
}
cha[x].h=ai[cha[x].to];
ai[cha[x].to]=cha[x].x;
if(if_[cha[x].to])
{
if(!ti[ai[cha[x].to]]) now++;
ti[ai[cha[x].to]]++;
}
} inline void unchange(int x)
{
if(if_[cha[x].to])
{
ti[ai[cha[x].to]]--;
if(!ti[ai[cha[x].to]]) now--;
}
ai[cha[x].to]=cha[x].h;
if(if_[cha[x].to])
{
if(!ti[ai[cha[x].to]]) now++;
ti[ai[cha[x].to]]++;
}
} inline void updata(int to,int x)
{
int pos=ti[ai[to]];
ti[ai[to]]+=x;
if(ti[ai[to]]==&&pos==) now--;
if(ti[ai[to]]==&&pos==) now++;
if(x==) if_[to]=true;
else if_[to]=false;
} int main()
{
in(n),in(m);char ch[];int l,r,t;
for(int i=;i<=n;i++) in(ai[i]),bel[i]=(i-)/size;
for(int i=;i<=m;i++)
{
scanf("%s",ch);in(l),in(r);
if(ch[]=='Q') qu[++tot].l=l,qu[tot].r=r,qu[tot].t=num,qu[tot].id=tot;
else cha[++num].to=l,cha[num].x=r;
}
sort(qu+,qu+tot+,cmp),l=,r=,t=,now=;
for(int no=;no<=tot;no++)
{
while(t<qu[no].t) change(++t);
while(t>qu[no].t) unchange(t--);
while(r<qu[no].r) updata(++r,);
while(r>qu[no].r) updata(r--,-);
while(l<qu[no].l) updata(l++,-);
while(l>qu[no].l) updata(--l,);
ans[qu[no].id]=now;
}
for(int i=;i<=tot;i++) printf("%d\n",ans[i]);
fclose(stdin),fclose(stdout);
return ;
}
AC日记——数颜色 bzoj 2120的更多相关文章
- AC日记——数1的个数 openjudge 1.5 40
40:数1的个数 总时间限制: 1000ms 内存限制: 65536kB 描述 给定一个十进制正整数n,写下从1到n的所有整数,然后数一下其中出现的数字“1”的个数. 例如当n=2时,写下1,2. ...
- AC日记——[SCOI2010]游戏 bzoj 1854
1854: [Scoi2010]游戏 Time Limit: 5 Sec Memory Limit: 162 MBSubmit: 4938 Solved: 1948[Submit][Status] ...
- AC日记——[Sdoi2013]森林 bzoj 3123
3123: [Sdoi2013]森林 Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 3216 Solved: 944[Submit][Status] ...
- AC日记——王室联邦 bzoj 1086
Description “余”人国的国王想重新编制他的国家.他想把他的国家划分成若干个省,每个省都由他们王室联邦的一个成员来管理.他的国家有n个城市,编号为1..n.一些城市之间有道路相连,任意两个不 ...
- AC日记——[Hnoi2017]影魔 bzoj 4826
4826 思路: 主席树矩阵加减+单调栈预处理: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 200005 ...
- AC日记——[LNOI2014]LCA bzoj 3626
3626 思路: 离线操作+树剖: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 100005 #defin ...
- AC日记——[ZJOI2012]网络 bzoj 2816
2816 思路: 多个LCT: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 10005 #define l ...
- AC日记——[SCOI2009]游戏 bzoj 1025
[SCOI2009]游戏 思路: 和为n的几个数最小公倍数有多少种. dp即可: 代码: #include <bits/stdc++.h> using namespace std; #de ...
- AC日记——[HNOI2014]世界树 bzoj 3572
3572 思路: 虚树+乱搞: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 300005 #define ...
随机推荐
- windows 定时任务 - 定时关机
添加定时关机,刚好可以利用windows定时任务 [开始]->[控制面板]->[任务计划]->[添加任务计划] 1.找到 shutdown.exe 设置每天执行 2.设置晚上10点 ...
- laravel5.5事件广播系统实例laravel-echo + redis + socket.io
目录 1. 广播配置说明 1.1 广播驱动配置 1.2 注册服务提供器 2. 驱动器配置 2.1 安装predis 2.2. 配置服务端 2.2.1 安装方法 2.2.2 初始化服务端 2.2.3 运 ...
- pip 代理设置,坑爹的代理继续
Linux ubuntu 3.2.0-23-generic-pae #36-Ubuntu SMP Tue Apr 10 22:19:09 UTC 2012 i686 i686 i386 GNU/Lin ...
- 《Cracking the Coding Interview》——第6章:智力题——题目3
2014-03-20 00:48 题目:有3升的瓶子和5升的瓶子,只允许倒满.倒到满为止.或是泼光三种操作,怎么搞出4升水呢? 解法:如果A和B是互质的两个正整数,且A<B,令X=B-A,则(X ...
- CSS系列(5)-如何使用Firebug查看网页的html和css
Firebug是火狐浏览器Firefox的一个插件,专门为开发人员开发的.使用Firebug需要先在Firefox中安装这个插件,网上有很多教程,可以对照着安装一下. 不同的火狐浏览器版本中的Fire ...
- python之while/for循环
一.while循环 (一)循环语句 while 后面接判断语句,在返回结果时有以下几种语句: 1.break 仅适用于循环语句,意思是结束最近的循环 2.continue 仅适用于循环语句,意思是跳到 ...
- Unity-SendMessage
每一个对象都有SendMessage,BroadcastMessage,SendMessageUpwards 三个发送消息的方法! 1.功能: 执行某个对象中的某个方法! 2.实现原理 反射 ...
- (笔记) RealTimeRender[实时渲染] C2
@author: 白袍小道 @来源:RealTime Render @建议书籍:龙书.RealTimeR第四版.GPUGem和PRO (来源:暗影不解释) 引点 这一章关注的管线中的管道功能,而非实现 ...
- (原)UE4 制作执行队列(Action Queue)
队列和树在游戏开发中是比较常见的数据结构,在一定范围能保证执行的顺序. 结合一些设计模式技巧,往往可以做一些神器. 如加载块chunk管理,任务系统(当然也可以使用行为树来做复杂的任务系统). ...
- Linux cooked-mode capture 格式转换
tcpdump抓包时,如果-i选项指定为一个网卡地址,那么抓取的数据包数据链路层是以太网头部:如果指定any,则以太网头部将被替换为linux cooked capture头部 # tcpdump - ...