AC日记——[SDOI2009]HH的项链 洛谷 P1972
思路;
莫队;
代码:
#include <bits/stdc++.h>
#define maxn 100005
#define maxm 400005
#define maxnnum 2000005
using namespace std;
int bel[maxn];
struct QueryType {
int l,r,id;
bool operator <(const QueryType pos)const
{
if(bel[l]==bel[pos.l]) return r<pos.r;
else return bel[l]<bel[pos.l];
}
};
struct QueryType qu[maxm];
int n,m,ai[maxn],ans[maxn],blo,now,num[maxnnum];
inline void in(int &now)
{
char Cget=getchar();now=;
while(Cget>''||Cget<'')Cget=getchar();
while(Cget>=''&&Cget<='')
{
now=now*+Cget-'';
Cget=getchar();
}
}
inline void updata(int x,bool di)
{
x=ai[x];
if(di)
{
if(!num[x]) now++;
num[x]++;
}
else
{
if(num[x]==) now--;
num[x]--;
}
}
int main()
{
in(n),blo=sqrt(n);
for(int i=;i<=n;i++) in(ai[i]),bel[i]=(i+)/blo;
in(m);
for(int i=;i<=m;i++) in(qu[i].l),in(qu[i].r),qu[i].id=i;
sort(qu+,qu+m+);
int l=,r=;
for(int no=;no<=m;no++)
{
while(r<qu[no].r) updata(++r,true);
while(r>qu[no].r) updata(r--,false);
while(l<qu[no].l) updata(l++,false);
while(l>qu[no].l) updata(--l,true);
ans[qu[no].id]=now;
}
for(int i=;i<=m;i++) printf("%d\n",ans[i]);
return ;
}
AC日记——[SDOI2009]HH的项链 洛谷 P1972的更多相关文章
- AC日记——[SDOI2009]HH去散步 洛谷 P2151
[SDOI2009]HH去散步 思路: 矩阵快速幂递推(类似弗洛伊德): 给大佬跪烂-- 代码: #include <bits/stdc++.h> using namespace std; ...
- AC日记——校门外的树 洛谷 P1047
题目描述 某校大门外长度为L的马路上有一排树,每两棵相邻的树之间的间隔都是1米.我们可以把马路看成一个数轴,马路的一端在数轴0的位置,另一端在L的位置:数轴上的每个整数点,即0,1,2,……,L,都种 ...
- AC日记——无线网络发射器选址 洛谷 P2038
题目描述 随着智能手机的日益普及,人们对无线网的需求日益增大.某城市决定对城市内的公共场所覆盖无线网. 假设该城市的布局为由严格平行的129 条东西向街道和129 条南北向街道所形成的网格状,并且相邻 ...
- AC日记——小A的糖果 洛谷七月月赛
小A的糖果 思路: for循环贪心: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 100005 #defi ...
- AC日记——矩阵取数游戏 洛谷 P1005
矩阵取数游戏 思路: dp+高精: 代码: #include <bits/stdc++.h> using namespace std; #define ll long long struc ...
- AC日记——红色的幻想乡 洛谷 P3801
红色的幻想乡 思路: 线段树+容斥原理: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 100005 #de ...
- AC日记——妖梦拼木棒 洛谷 P3799
妖梦拼木棒 思路: 神特么题: 代码: #include <bits/stdc++.h> using namespace std; #define mod 1000000007LL int ...
- AC日记——妖梦斩木棒 洛谷 P3797
妖梦斩木棒 思路: 略坑爹: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 200005 #define m ...
- AC日记——聪明的质监员 洛谷 P1314
聪明的质监员 思路: 二分: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 200005 #define l ...
随机推荐
- MQ对比
转:http://blog.csdn.net/linsongbin1/article/details/47781187 MQ框架非常之多,比较流行的有RabbitMq.ActiveMq.ZeroMq. ...
- apt-get update的hit和ign含义
How do Ign and Hit affect apt-get update? From what I can see in the apt source code, "Ign" ...
- JAVA有关命名规范
包名: xxxyyyzzz 全小写 类名/接口名:XxxYyyZzz 所有单词首字母大写,其他小写 方法名: xxxYyyZzz第一个单词首字母小写,其他单词首字母大写 ...
- 数据结构&图论:LCT
HDU4010 类比静态区间问题->动态区间问题的拓展 我们这里把区间变成树,树上的写改删查问题,最最最常用LCT解决 LCT用来维护动态的森林,对于森林中的每一棵树,用Splay维护. LCT ...
- C11简洁之道:函数绑定
1. 可调用对象 在C++中,有“可调用对象”这么个概念,那么什么是调用对象呢?有哪些情况?我们来看看: 函数指针: 具有operator()成员函数的类对象(仿函数): 可以被转换为函数指针的类对 ...
- MyBatis框架的使用及源码分析(六) MapperRegistry
我们先Mapper接口的调用方式,见<MyBatis框架中Mapper映射配置的使用及原理解析(一) 配置与使用>的示例: public void findUserById() { Sql ...
- JVM-内存回收算法--复制算法
复制算法,它将堆上的内存分为两个大小相等的区域,一个是空闲区域,一个是活动区域.在程序运行中,实际使用的是活动区域,也就是有50%的空间被浪费掉. 复制算法的实现过程:1.找出活动空间中所有存活的对象 ...
- 【BZOJ4373】算术天才⑨与等差数列 [线段树]
算术天才⑨与等差数列 Time Limit: 10 Sec Memory Limit: 128 MB[Submit][Status][Discuss] Description 算术天才⑨非常喜欢和等 ...
- bzoj3172 Ac自动机
根据fail树的性质 我们在建树的时候每建一个串就将他路径上的点全部加1表示这个串的后缀又出现了一次 然后从下到上把sum加起来就可以得到答案了 #include<cstdio> #inc ...
- 【shell】shell编程(六)-shell函数的应用
linux shell 可以用户定义函数,然后在shell脚本中可以随便调用. shell中函数的定义格式如下: [ function ] funname [()] { action; [return ...