【bzoj3809】Gty的二逼妹子序列
Description
Input
Output
对每个询问,单独输出一行,表示sl…sr中权值∈[a,b]的权值的种类数。
Sample Input
4 4 5 1 4 1 5 1 2 1
5 9 1 2
3 4 7 9
4 4 2 5
2 3 4 7
5 10 4 4
3 9 1 1
1 4 5 9
8 9 3 3
2 2 1 6
8 9 1 4
Sample Output
0
0
2
1
1
1
0
1
2
HINT
// MADE BY QT666
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<queue>
#include<set>
#include<cstdlib>
#include<cstring>
#include<string>
#include<ctime>
#define lson num<<1
#define rson num<<1|1
using namespace std;
typedef long long ll;
const int N=;
const int M=;
int gi()
{
int x=,flag=;
char ch=getchar();
while(ch<''||ch>''){if(ch=='-') flag=-;ch=getchar();}
while(ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
return x*flag;
}
int n,m,a[N],block,pos[N],blockans[N],l[N],r[N],cnt,ans[M],tong[N];
struct ac
{
int l,r,L,R,id;
}q[M];
bool cmp(const ac &a,const ac &b)
{
if(pos[a.l]==pos[b.l]) return a.r<b.r;
return pos[a.l]<pos[b.l];
}
void pre()
{
for(int i=;i<=cnt;i++) l[i]=(i-)*block+,r[i]=i*block;
r[cnt]=n;
for(int i=;i<=n;i++) pos[i]=(i-)/block+;
}
void update(int x,int val) {tong[x]+=val;}
int query(int x,int y)
{
int sum=;
if(pos[x]==pos[y])
{
for(int i=x;i<=y;i++) if(tong[i]) sum++;
}
else
{
for(int i=x;i<=r[pos[x]];i++) if(tong[i]) sum++;
for(int i=l[pos[y]];i<=y;i++) if(tong[i]) sum++;
for(int i=pos[x]+;i<=pos[y]-;i++) sum+=blockans[i];
}
return sum;
}
void work()
{
for(int i=,l=,r=;i<=m;i++)
{
while(l>q[i].l) {l--;update(a[l],);if(tong[a[l]]==) blockans[pos[a[l]]]++;}
while(r<q[i].r) {r++;update(a[r],);if(tong[a[r]]==) blockans[pos[a[r]]]++;}
while(l<q[i].l) {update(a[l],-);if(tong[a[l]]==) blockans[pos[a[l]]]--;l++;}
while(r>q[i].r) {update(a[r],-);if(tong[a[r]]==) blockans[pos[a[r]]]--;r--;}
ans[q[i].id]=query(q[i].L,q[i].R);
}
}
int main()
{
n=gi(),m=gi();
for(int i=;i<=n;i++) a[i]=gi();
for(int i=;i<=m;i++) q[i].l=gi(),q[i].r=gi(),q[i].L=gi(),q[i].R=gi(),q[i].id=i;
block=(int)sqrt(n);
if(n%block==) cnt=n/block;
else cnt=n/block+;
pre();
sort(q+,q++m,cmp);
work();
for(int i=;i<=m;i++) printf("%d\n",ans[i]);
return ;
}
【bzoj3809】Gty的二逼妹子序列的更多相关文章
- [bzoj3809]Gty的二逼妹子序列/[bzoj3236][Ahoi2013]作业
[bzoj3809]Gty的二逼妹子序列/[bzoj3236][Ahoi2013]作业 bzoj bzoj 题目大意:一个序列,m个询问在$[l,r]$区间的$[x,y]$范围内的数的个数/种类. ...
- [bzoj3809]Gty的二逼妹子序列_莫队_分块
Gty的二逼妹子序列 bzoj-3809 题目大意:给定一个n个正整数的序列,m次询问.每次询问一个区间$l_i$到$r_i$中,权值在$a_i$到$b_i$之间的数有多少个. 注释:$1\le n\ ...
- BZOJ3809: Gty的二逼妹子序列
Description Autumn和Bakser又在研究Gty的妹子序列了!但他们遇到了一个难题. 对于一段妹子们,他们想让你帮忙求出这之内美丽度∈[a,b]的妹子的美丽度的种类数. 为了方 ...
- [BZOJ3809]Gty的二逼妹子序列[莫队+分块]
题意 给出长度为 \(n\) 的序列,\(m\) 次询问,每次给出 \(l,r,a,b\) ,表示询问区间 \([l,r]\) 中,权值在 \([a,b]\) 范围的数的种类数. \(n\leq 10 ...
- bzoj3809 Gty的二逼妹子序列 & bzoj3236 [Ahoi2013]作业 莫队+分块
题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=3809 https://lydsy.com/JudgeOnline/problem.php?id ...
- 2019.01.08 bzoj3809: Gty的二逼妹子序列(莫队+权值分块)
传送门 题意:多组询问,问区间[l,r]中权值在[a,b]间的数的种类数. 看了一眼大家应该都知道要莫队了吧. 然后很容易想到用树状数组优化修改和查询做到O(mnlogamax)O(m\sqrt nl ...
- 【莫队算法】【权值分块】bzoj3809 Gty的二逼妹子序列
如题. #include<cstdio> #include<algorithm> #include<cmath> using namespace std; int ...
- 【BZOJ3809/3236】Gty的二逼妹子序列 [Ahoi2013]作业 莫队算法+分块
[BZOJ3809]Gty的二逼妹子序列 Description Autumn和Bakser又在研究Gty的妹子序列了!但他们遇到了一个难题. 对于一段妹子们,他们想让你帮忙求出这之内美丽度∈[a,b ...
- 【BZOJ-3809】Gty的二逼妹子序列 分块 + 莫队算法
3809: Gty的二逼妹子序列 Time Limit: 80 Sec Memory Limit: 28 MBSubmit: 1072 Solved: 292[Submit][Status][Di ...
- BZOJ 3809: Gty的二逼妹子序列
3809: Gty的二逼妹子序列 Time Limit: 80 Sec Memory Limit: 28 MBSubmit: 1387 Solved: 400[Submit][Status][Di ...
随机推荐
- css一些简单的例子
1.http协议 一:HTTP协议:hypertext transport protocol(超文本传输协议) 特点: 1.请求与响应 2.无状态的协议 请求协议: 请求首行: 请求头信息: Acce ...
- [Machine Learning]学习笔记-Neural Networks
引子 对于一个特征数比较大的非线性分类问题,如果采用先前的回归算法,需要很多相关量和高阶量作为输入,算法的时间复杂度就会很大,还有可能会产生过拟合问题,如下图: 这时就可以选择采用神经网络算法. 神经 ...
- anaconda spyder异常如何重新启动
电脑有一次断电,重新启动后anaconda的spyder就打不开了 重新启动spyder方法: 在anaconda安装目录的Scripts文件夹下,shift+右键在此窗口打开命令行,运行spyder ...
- SpringCloud学习笔记(2)——Ribbon
参考SpringCloud官网第16.17章 16. Client Side Load Balancer: Ribbon Ribbon是一个客户端的负载均衡器,它提供对大量的HTTP和TCP客户端的访 ...
- JavaScript:彻底理解同步、异步和事件循环(Event Loop)
一. 单线程 我们常说"JavaScript是单线程的". 所谓单线程,是指在JS引擎中负责解释和执行JavaScript代码的线程只有一个.不妨叫它主线程. 但是实际上还存在其他 ...
- linux上mysql安装与卸载
以下步骤运行环境是centos6.5 1.查找以前是否装有mysql命令:rpm -qa|grep -i mysql2.删除mysql删除命令:rpm -e --nodeps 包名3.删除老版本m ...
- HDU 1014 Uniform Generator 欧几里得
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1014 解题思路: 1. 把题目意思读懂后,明白会输入两个数,然后根据题中的公式产生一系列伪随机数,看这 ...
- HDU5804--Price List
Price List Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/131072 K (Java/Others) Tot ...
- Hibernate框架进阶(上篇)
导读 前面一片文章介绍了Hibernate框架的入门,主要是讲解Hibernate的环境搭建和简单测试,有兴趣的童鞋出门左转.本文在入门的基础上进行Hibernate的进阶讲解,分为上中下三篇,本篇为 ...
- 【Win 10 应用开发】MIDI 音乐合成——音符消息篇
在上一篇中,老周介绍了一些乐理知识,有了那些常识后,进行 MIDI 编程就简单得多了.尽管微软已经把 API 封装好,用起来也很简单,但是,如果你没有相应的音乐知识基础,你是无法进行 MIDI 编程的 ...