AC日记——Little Elephant and Array codeforces 221d
221D - Little Elephant and Array
思路:
莫队;
代码:
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; #define maxn 100005 struct QueryType {
int l,r,id;
};
struct QueryType qu[maxn]; int n,m,ai[maxn],bi[maxn],ans[maxn],ci[maxn],num[maxn];
int size,now,bel[maxn],blo; 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])
{
if(aa.l==bb.l) return aa.r<bb.r;
else return aa.l<bb.l;
}
else return bel[aa.r]<bel[bb.r];
}
else return bel[aa.l]<bel[bb.l];
} inline void updata(int x,int dis)
{
if(num[ai[x]]==ci[x]) now--;
num[ai[x]]+=dis;
if(num[ai[x]]==ci[x]) now++;
} int main()
{
in(n),in(m);
for(int i=;i<=n;i++) in(ai[i]),bi[i]=ai[i],ci[i]=ai[i];
sort(bi+,bi+n+),size=unique(bi+,bi+n+)-bi-;
for(int i=;i<=n;i++) ai[i]=lower_bound(bi+,bi+size+,ai[i])-bi;
blo=sqrt(n);for(int i=;i<=n;i++) bel[i]=(i+)/blo;
for(int i=;i<=m;i++) in(qu[i].l),in(qu[i].r),qu[i].id=i;
sort(qu+,qu+m+,cmp);int l=,r=;
for(int no=;no<=m;no++)
{
int ll=qu[no].l,rr=qu[no].r;
if(l<ll) for(int i=l;i<ll;i++) updata(i,-);
else for(int i=l-;i>=ll;i--) updata(i,);
if(r<rr) for(int i=r+;i<=rr;i++) updata(i,);
else for(int i=r;i>rr;i--) updata(i,-);
l=ll,r=rr,ans[qu[no].id]=now;
}
for(int i=;i<=m;i++) printf("%d\n",ans[i]);
return ;
}
AC日记——Little Elephant and Array codeforces 221d的更多相关文章
- AC日记——Little Elephant and Shifts codeforces 221e
E - Little Elephant and Shifts 思路: 一次函数线段树(疯狂debug): b不断循环左移,判断每次最小的|i-j|,a[i]=b[j]: 仔细观察发现,每个bi移动时, ...
- AC日记——Little Elephant and Numbers codeforces 221b
221B - Little Elephant and Numbers 思路: 水题: 代码: #include <cmath> #include <cstdio> #inclu ...
- AC日记——Little Elephant and Function codeforces 221a
A - Little Elephant and Function 思路: 水题: 代码: #include <cstdio> #include <iostream> using ...
- AC日记——Little Elephant and Problem codeforces 221c
221C 思路: 水题: 代码: #include <cstdio> #include <cstring> #include <iostream> #include ...
- Little Elephant and Array CodeForces - 220B (莫队)
The Little Elephant loves playing with arrays. He has array a, consisting of npositive integers, ind ...
- Little Elephant and Array CodeForces - 220B(莫队)
给一段长为n的序列和m个关于区间的询问,求出每个询问的区间中有多少种数字是 该种数字出现的次数等于该数字 的. #include <iostream> #include <cstdi ...
- AC日记——Sagheer and Nubian Market codeforces 812c
C - Sagheer and Nubian Market 思路: 二分: 代码: #include <bits/stdc++.h> using namespace std; #defin ...
- AC日记——Red and Blue Balls codeforces 399b
399B - Red and Blue Balls 思路: 惊讶的发现,所有的蓝球的消除都是独立的: 对于在栈中深度为i的蓝球消除需要2^i次操作: 代码: #include <cstdio&g ...
- AC日记——Andryusha and Colored Balloons codeforces 780c
C - Andryusha and Colored Balloons 思路: 水题: 代码: #include <cstdio> #include <cstring> #inc ...
随机推荐
- laravel5.5缓存系统
目录 1 Redis的配置 1.1 安装PRedis 1.2 配置 1.2.1 配置redis数据库 1.2.2 更改session的配置 1.2.3 更改cache配置 1.3 使用redis 2 ...
- cookie不能删除
cookie不仅仅包含一个键值对,还包含域 domain 路径path, 一般domain是请求的地址 www.baidu.com/news.html 那domain就是www.baidu.com ...
- 自动化测试(三)如何用python写个双色球
写一个程序,输入N就产生N条双色球号码 红球 6 01-33 蓝球 1 01-16 产生的双色球号码不能重复,写到一个文件里面,每一行是一条 红球: 01 03 05 07 08 ...
- linux查看80端口占用情况
netstat -anltp|grep 80
- CSU-1986 玄学
题目链接 http://acm.csu.edu.cn:20080/csuoj/problemset/problem?pid=1986 题目 Description 阴阳师子浩君,最近从<初等数论 ...
- 训练caffe:registry.count(type) == 0 (1 vs. 0) Solver type Nesterov already registered
命令:./continue-train.sh 内容:../../caffe-master/build/tools/caffe train -gpu=$1 -solver=solver.prototxt ...
- 游戏开发学习ing
创建工程 python cocos.py new HelloWorld -p com.cocos2dx.org -l cpp -d myprojects 这个命令就是运行python然后编译cos.p ...
- htmlagilitypack解析html
这是个很好的的东西,以前做Html解析都是在用htmlparser,用的虽然顺手,但解析速度较慢,碰巧今天找到了这个,就拿过来试,一切出乎意料,非常爽,推荐给各位使用. 下面是一些简单的使用技巧,希望 ...
- J2EE的十三个技术——EJB之实体Bean
概述: 实体Bean与会话Bean不同,实体Bean是持久的,即使应用程序结束,它仍然存在.它允许共享访问,具有主键. 组成: 1)本地(Local)接口 本地访问EJB,只有在EJB与客户在同一个应 ...
- 基于MPLAB X IDE配置位设置讲解
http://blog.csdn.net/superanters/article/details/8541171 在讲基于MPLAB X IDE 配置位配置前我先讲讲如何配置配置位. 比如PICLF1 ...