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. centos使用--rpm和yum的关系以及基本用法

    1 RPM包 RPM是RedHat Package Manager(RedHat软件包管理工具)类似Windows里面的"添加/删除程序" rpm 执行安装包 二进制包(Binar ...

  2. USACO Section1.5 Superprime Rib 解题报告

    sprime解题报告 —— icedream61 博客园(转载请注明出处)--------------------------------------------------------------- ...

  3. mac虚拟机上(centos系统)设置联网第二种方式

    这种方式简单,不容易出错,用的桥接的方式. 这样的安装的centos会得到ip地址 然后编辑一下网卡配置,使其变为静态得ip 输入命令 # vi /etc/sysconfig/network-scri ...

  4. (原)Unreal 渲染模块 渲染流程

    @author:白袍小道 浏览分享随缘,评论不喷亦可.     扯淡部分: 在temp中,乱七八糟的说了下大致的UE过程.下面我们还是稍微别那么任性,一步步来吧.     UE渲染模块牵扯到场景遍历. ...

  5. 课时17:函数:Python的乐高积木

    目录: 一.创建和调用函数 二.函数的参数 三.函数的返回值 四.课时17课后习题及答案 为了使得程序得代码变得简单,就需要把程序分解成较小得组成部分.有三种方法可以实现:函数.对象.模块. **** ...

  6. Elasticsearch自定义分析器

    关于分析器 ES中默认使用的是标准分析器(standard analyzer).如果需要对某个字段使用其他分析器,可以在映射中该字段下说明.例如: PUT /my_index { "mapp ...

  7. Struts2+DAO层实现实例02——搭建DAO基本框架并与Struts2组合

    实例内容 创建DAO(Data Access Oject)接口:BaseDAO 创建其实例化类:UserDAO 用于获取数据库struts中的userinfo表中的内容 创建User的Java Bea ...

  8. [洛谷P3805]【模板】manacher算法

    题目大意:给你一个字符串,求出它的最长回文字段 题解:$manacher$算法 卡点:$p$数组未开两倍空间 C++ Code: #include <cstdio> #include &l ...

  9. Statement [倍增+线段树]

    题面 思路 首先,可以确定的是,本题因为每个点只有一条入边,所以整个图肯定是一个基环外向树森林 那么我们首先考虑树上的情况: 我们考虑一个真点,它会对它的子树里面的所有假点产生贡献 一个真点对一个假点 ...

  10. 【BZOJ 5048 塌陷的牧场】

    Time Limit: 25 Sec  Memory Limit: 256 MBSubmit: 77  Solved: 34[Submit][Status][Discuss] Description ...