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. nohup 重定向的问题-- 费元星 站长

    费元星 大牛 以前只知道使用nohup可以让一个程序后台执行,但是生成的日志文件都放到nohup.out中了,不能自己指定,尤其是在同一个目录下我需要让两个甚至多个程序都要后台执行时,这样看日志就比较 ...

  2. CSS3 3D圆形设计教程

    http://www.htmleaf.com/ziliaoku/qianduanjiaocheng/201502061338.html

  3. 《Cracking the Coding Interview》——第8章:面向对象设计——题目7

    2014-04-23 23:38 题目:你要如何设计一个聊天服务器,有什么技术难点? 解法:这是基于工作经验的面试题吗?否则,一个new grad碰上这种题目能打点草稿也就算不错了. 代码: // 8 ...

  4. vue.js中created方法作用

    这是它的一个生命周期钩子函数,就是一个vue实例被生成后调用这个函数.一个vue实例被生成后还要绑定到某个html元素上,之后还要进行编译,然后再插入到document中.每一个阶段都会有一个钩子函数 ...

  5. An internal error occurred during: "Launching on Tomcat 7.x"

    1.首先关闭MyEclipse工作空间.2.然后删除工作空间下的文件.“MyEclipse10\workspace.metadata.plugins\org.eclipse.core.runtime. ...

  6. Python基础简介与简单使用

    Python介绍 Python发展史 1989年,为了打发圣诞节假期,Guido开始写Python语言的编译器.Python这个名字,来自Guido所挚爱的电视剧Monty Python’s Flyi ...

  7. Python之日志处理 logging模块

    Python之日志处理(logging模块)   本节内容 日志相关概念 logging模块简介 使用logging提供的模块级别的函数记录日志 logging模块日志流处理流程 使用logging四 ...

  8. 洛谷P2678跳石头(提高)

    题目背景 一年一度的“跳石头”比赛又要开始了! 题目描述 这项比赛将在一条笔直的河道中进行,河道中分布着一些巨大岩石.组委会已经选择好了两块岩石作为比赛起点和终点. 在起点和终点之间,有 N 块岩石( ...

  9. 实用JS系列——面向对象中的类和继承

    背景: 在最开始学习JavaScript时,我们就知道,它是一种脚本语言,也有面向对象机制.但它的面向对象继承机制是基于原型的,即Prototype.今天,我们就来找一下JS中OO的影子. 创建类 1 ...

  10. Scala 基础(1)—— 定义变量 & 定义函数

    1. 使用 val & var 定义变量 Scala 中的变量被分为2种:val 和 var.其含义于 Java 中的 final 关键字类似. val 等同于被 final 修饰过的变量, ...