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 ...
随机推荐
- 统计大写字母个数&压缩和去重(过滤)
找出给定字符串中大写字符(即'A'-'Z')的个数 接口说明 原型:int CalcCapital(String str); 返回值:int 知识点 字符串 运行时间限制 10M 内存限制 128 输 ...
- Win Server 8中的利器:微软在线备份服务
微软在Windows Server 8中添加在线备份服务了?你一定以为我在开玩笑,是吧?但是微软确实这么做了. 微软在Windows Server 8中添加在线备份服务了?你一定以为我在开玩笑 ...
- adb logcat 日志过滤
方法 1.采用wpa_supplicant:s *:v 排除wpa_supplicant标签 adb -s 01d32e89cb94d599 logcat -v time -s wpa_suppl ...
- VS Extension+NVelocity系列(一)——构建一个简单的NVelocity解析环境
一.前言 本节我们将实际实现一个简单的NVelocity解析环境,以便为以后的实例做一些基本工作,虽然NVelocity如何使用已经属于老掉牙的话题,但我只能专门挑出来一章来做铺垫.人生就是这样无奈啊 ...
- python学习笔记十三:Flask demo
一.Flask简介 Flask 是一个 Python 实现的 Web 开发微框架.官网:http://flask.pocoo.org/ 二.Demo 1.代码结构 . ├── blog.py ├── ...
- PL/SQL 循环语句
1.基本 LOOP 循环语句 语法: LOOP 语句序列; END LOOP; 其中,语句序列中需要一个EXIT语句或一个EXIT WHEN语句来中断循环. 实例: DECLARE x ) :; BE ...
- CentOS下创建和root权限完全相同用户
新建用户 [root@bagon ~]# useradd newroot 修改密码 [root@bagon ~]# passwd newroot 编辑/etc/passwd,找到新建用户那一行 new ...
- 201621123034 《Java程序设计》第13周学习总结
作业13-网络 1. 本周学习总结 以你喜欢的方式(思维导图.OneNote或其他)归纳总结多网络相关内容. 2. 为你的系统增加网络功能(购物车.图书馆管理.斗地主等)-分组完成 为了让你的系统可以 ...
- 基于MPLAB X IDE配置位设置讲解
http://blog.csdn.net/superanters/article/details/8541171 在讲基于MPLAB X IDE 配置位配置前我先讲讲如何配置配置位. 比如PICLF1 ...
- vi - vim的一些遗忘点
1. vi 供分为三种模式:一般模式.编辑模式和命令行模式.i / Esc + :wq :q :q! 使vi在一般模式与编辑模式中来回转换. /word 向下寻找一个名称为word的字符串: ?wor ...