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的更多相关文章

  1. AC日记——数1的个数 openjudge 1.5 40

    40:数1的个数 总时间限制:  1000ms 内存限制:  65536kB 描述 给定一个十进制正整数n,写下从1到n的所有整数,然后数一下其中出现的数字“1”的个数. 例如当n=2时,写下1,2. ...

  2. AC日记——[SCOI2010]游戏 bzoj 1854

    1854: [Scoi2010]游戏 Time Limit: 5 Sec  Memory Limit: 162 MBSubmit: 4938  Solved: 1948[Submit][Status] ...

  3. AC日记——[Sdoi2013]森林 bzoj 3123

    3123: [Sdoi2013]森林 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 3216  Solved: 944[Submit][Status] ...

  4. AC日记——王室联邦 bzoj 1086

    Description “余”人国的国王想重新编制他的国家.他想把他的国家划分成若干个省,每个省都由他们王室联邦的一个成员来管理.他的国家有n个城市,编号为1..n.一些城市之间有道路相连,任意两个不 ...

  5. AC日记——[Hnoi2017]影魔 bzoj 4826

    4826 思路: 主席树矩阵加减+单调栈预处理: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 200005 ...

  6. AC日记——[LNOI2014]LCA bzoj 3626

    3626 思路: 离线操作+树剖: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 100005 #defin ...

  7. AC日记——[ZJOI2012]网络 bzoj 2816

    2816 思路: 多个LCT: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 10005 #define l ...

  8. AC日记——[SCOI2009]游戏 bzoj 1025

    [SCOI2009]游戏 思路: 和为n的几个数最小公倍数有多少种. dp即可: 代码: #include <bits/stdc++.h> using namespace std; #de ...

  9. AC日记——[HNOI2014]世界树 bzoj 3572

    3572 思路: 虚树+乱搞: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 300005 #define ...

随机推荐

  1. Trident整合Kafka

    首先编写一个打印函数KafkaPrintFunction import org.apache.storm.trident.operation.BaseFunction; import org.apac ...

  2. dubbo-admin管理控制台的安装和使用

    因为zookeeper只是一个黑框,我们无法看到是否存在了什么提供者或消费者,这时就要借助Dubbo-Admin管理平台来实时的查看,也可以通过这个平台来管理提者和消费者. dubbo下载及配置 du ...

  3. Win Server 8中的利器:微软在线备份服务

    微软在Windows Server 8中添加在线备份服务了?你一定以为我在开玩笑,是吧?但是微软确实这么做了.     微软在Windows Server 8中添加在线备份服务了?你一定以为我在开玩笑 ...

  4. 网易OpenStack部署运维实战

    OpenStack自2010年项目成立以来,已经有超过200个公司加入了 OpenStack 项目,目前参与 OpenStack 项目的开发人员有 17,000+,而且这些数字还在增加,作为一个开源的 ...

  5. app分享功能开发

    最近在开发一个社交平台的app需要用到分享功能,本来想自己开发的,在网上花了很长时间查了很多教程结果却不尽人意,无意中看到还有类似的开源组件友推,结合自己的开发经验,把一些集成步骤和问题整理成文档奉献 ...

  6. wireshark简单使用

    过滤表达式的规则   表达式规则   1. 协议过滤   比如TCP,只显示TCP协议. ip.src == 219.216.87.200 and ip.dst==219.216.87.254   2 ...

  7. ASP.NET——视频总结

    ASP.NET的视频很早就看完了,但一直还没顾上总结.虽然在备战软考,学习任务很重,但是阶段的总结还是不要推太久了,不然也就起不到总结的效果了.在看视频之前,虽然已经做过了新闻发布系统,但是对B/S一 ...

  8. Hexo添加字数统计、阅读时长

    统计插件 配置 NexT 主题默认已经集成了文章[字数统计].[阅读时长]统计功能,如果我们需要使用,只需要在主题配置文件 _config.yml 中打开 wordcount 统计功能即可.如下所示: ...

  9. TensorFlow 模型文件

    在这篇 TensorFlow 教程中,我们将学习如下内容: TensorFlow 模型文件是怎么样的? 如何保存一个 TensorFlow 模型? 如何恢复一个 TensorFlow 模型? 如何使用 ...

  10. 大型C++项目必须注意的几个小问题

    大型C++项目必须注意的几个小问题 有些问题对于小型的C++项目来说可能无关紧要,但对于大中型C++项目来讲,这些问题却成了大问题.什么样的项目算是小型项目呢,什么样的算是大中型项目呢,我认为10万L ...