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 ...
随机推荐
- C++之内部类与外部类(嵌套类)及友元
转载于:http://www.cnblogs.com/qzhforthelife/p/3226885.html 先上代码: class Outer { public: Outer(){m_outerI ...
- hdu 5621
KK's Point Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- XOR and Favorite Number (莫对算法)
E. XOR and Favorite Number time limit per test 4 seconds memory limit per test 256 megabytes input s ...
- nginx 报invalid pid number
/opt/ibis/sbin/nginx -c /opt/ibis/conf/nginx.conf 这是make make install之后生成的文件夹和文件. -c c是configure的缩写 ...
- getQueryString----获取url中得参数
/** * 获取url中得参数 * @param name * @returns {null} */ window.getQueryString = function (name) { var reg ...
- css+vue实现添加购物车效果
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- git设置不需要密码
https方式每次都要输入密码,按照如下设置即可输入一次就不用再手输入密码的困扰而且又享受https带来的极速 设置记住密码(默认15分钟): git config --global credenti ...
- MongoDB入门(2)- MongoDB安装
windows安装 下载文件,解压缩即可.下载地址 每次运行mongod --dbpath D:/MongoDB/data 命令行来启动MongoDB实在是不方便,把它作为Windows服务,这样就方 ...
- Enterprise Architect 13 : 需求建模 自动命名并计数
如何给模型中的需求元素配置计数器以自动设置新创建元素的名称和别名: Configure -> Settings -> Auto Names and Counters 设置好后的效果图:
- 如果你也想写个完整的 Vue 组件项目
1.一个完整的组件项目需要什么? 必要的: 组件构建方式 ( webpack / rollup 之类 ),并提供至少一个主流的输出格式 (ESModule) Demo 及 Demo 源码 文档,可以是 ...