传送门

本来打算用主席树

然后发现没办法维护颜色数

于是用了莫队加树状数组

然后竟然A了……

 //minamoto
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
#define getc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
char buf[<<],*p1=buf,*p2=buf;
inline int read(){
#define num ch-'0'
char ch;bool flag=;int res;
while(!isdigit(ch=getc()))
(ch=='-')&&(flag=true);
for(res=num;isdigit(ch=getc());res=res*+num);
(flag)&&(res=-res);
#undef num
return res;
}
char sr[<<],z[];int C=-,Z;
inline void Ot(){fwrite(sr,,C+,stdout),C=-;}
inline void print(int x){
if(C><<)Ot();if(x<)sr[++C]=,x=-x;
while(z[++Z]=x%+,x/=);
while(sr[++C]=z[Z],--Z);sr[++C]='\n';
}
const int N=1e5+,M=1e6+;
int cnt[N],a[N],ans[M],c[N],rt[N],n,m,res,l,r,s;
struct node{
int l,r,ql,qr,id;
node(){}
node(int l,int r,int ql,int qr,int id):l(l),r(r),ql(ql),qr(qr),id(id){}
inline bool operator <(const node &b)const
{return rt[l]==rt[b.l]?rt[l]&?r<b.r:r>b.r:l<b.l;}
}q[M];
inline void change(int x,int y){
for(;x<=n;x+=x&-x) c[x]+=y;
}
inline int query(int x){
int res=;
for(;x;x-=x&-x) res+=c[x];
return res;
}
inline void add(int x){
if(++cnt[x]==) change(x,);
}
inline void del(int x){
if(--cnt[x]==) change(x,-);
}
int main(){
// freopen("testdata.in","r",stdin);
n=read(),m=read(),s=sqrt(n);
for(int i=;i<=n;++i) a[i]=read(),rt[i]=(i-)/s+;
for(int i=,l,r,ql,qr;i<=m;++i)
l=read(),r=read(),ql=read(),qr=read(),q[i]=node(l,r,ql,qr,i);
sort(q+,q++m);
l=,r=,res=;
for(int i=;i<=m;++i){
while(l>q[i].l) add(a[--l]);
while(r<q[i].r) add(a[++r]);
while(l<q[i].l) del(a[l++]);
while(r>q[i].r) del(a[r--]);
ans[q[i].id]=query(q[i].qr)-query(q[i].ql-);
}
for(int i=;i<=m;++i) print(ans[i]);
Ot();
return ;
}

洛谷P4867 Gty的二逼妹子序列(莫队+树状数组)的更多相关文章

  1. 洛谷 P4867 Gty的二逼妹子序列

    链接: P4867 题意: 给出长度为 \(n(1\leq n\leq 10^5)\) 的序列 \(s\),保证\(1\leq s_i\leq n\).有 \(m(1\leq m\leq 10^6)\ ...

  2. [AHOI2013]作业 & Gty的二逼妹子序列 莫队

    ---题面--- 题解: 题目要求统计一个区间内数值在[a, b]内的数的个数和种数,而这个是可以用树状数组统计出来的,所以可以考虑莫队. 考虑区间[l, r]转移到[l, r + 1],那么对于维护 ...

  3. Bzoj 3809: Gty的二逼妹子序列 莫队,分块

    3809: Gty的二逼妹子序列 Time Limit: 35 Sec  Memory Limit: 28 MBSubmit: 868  Solved: 234[Submit][Status][Dis ...

  4. BZOJ 3809 Gty的二逼妹子序列 莫队算法+分块

    Description Autumn和Bakser又在研究Gty的妹子序列了!但他们遇到了一个难题. 对于一段妹子们,他们想让你帮忙求出这之内美丽度∈[a,b]的妹子的美丽度的种类数. 为了方便,我们 ...

  5. 【BZOJ3809】Gty的二逼妹子序列 莫队 分块

    题目描述 给你一个长度为\(n\)的数列,还有\(m\)个询问,对于每个询问\((l,r,a,b)\),输出区间\([l,r]\)有多少范围在\([a,b]\)的权值. \(n\leq 100000, ...

  6. [BZOJ3809]Gty的二逼妹子序列[莫队+分块]

    题意 给出长度为 \(n\) 的序列,\(m\) 次询问,每次给出 \(l,r,a,b\) ,表示询问区间 \([l,r]\) 中,权值在 \([a,b]\) 范围的数的种类数. \(n\leq 10 ...

  7. bzoj 3809 Gty的二逼妹子序列——莫队+分块

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3809 容易想到树状数组维护值域.但修改和查询都是 log 太慢. 考虑有 nsqrt(n) ...

  8. bzoj 3809 Gty的二逼妹子序列 —— 莫队+分块

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3809 据说一开始应该想到莫队+树状数组,然而我想的却是莫队+权值线段树... 如果用权值线段 ...

  9. P4867 Gty的二逼妹子序列

    题目描述 Autumn和Bakser又在研究Gty的妹子序列了!但他们遇到了一个难题. 对于一段妹子们,他们想让你帮忙求出这之内美丽度∈[a,b]的妹子的美丽度的种类数. 为了方便,我们规定妹子们的美 ...

随机推荐

  1. 使用 C# 开发智能手机软件:推箱子(四)

    这是"使用 C# 开发智能手机软件:推箱子"系列文章的第四篇. 在这篇文章中,介绍 Common/FindPath.cs 源程序文件. using System; using Sy ...

  2. numpy - 数组索引

    numpy 数组索引 一.单个元素索引 一维数组索引 >>> x = np.arange(10) >>> x[2] 2 >>> x[-2] 8 二 ...

  3. 李洪强iOS开发之 - 指定刷新tableview的某一组

    李洪强iOS开发之 - 指定刷新tableview的某一组

  4. maven优化依赖

    maven-dependency-plugin最大的用途是帮助分析项目依赖,dependency:list能够列出项目最终解析到的依赖列表,dependency:tree能进一步的描绘项目依赖树,de ...

  5. 项目Beta冲刺(团队5/7)

    项目Beta冲刺(团队5/7) 团队名称: 云打印 作业要求: 项目Beta冲刺(团队) 作业目标: 完成项目Beta版本 团队队员 队员学号 队员姓名 个人博客地址 备注 221600412 陈宇 ...

  6. scrollTo(String text) and scrollToExact(String text) method of Android Driver not working

    Using the scrollTo(String text) and scrollToExact(String text) method of Android Driver. However the ...

  7. Android — 长按ListView 利用上下文菜单(ActionMode) 进行批量事件处理

    好久没写博客拉``````` 近期最终略微闲一点了``````` 无聊拿手机清理短信.发现批量事件的处理还是挺管用的`````` 那么自己也来山寨一记看看效果吧````` 闲话少说,首先,我们来看下手 ...

  8. 【bzoj3210】花神的浇花集会

    将(x,y)转化成(x+y,x-y)可以将切比雪夫距离转化成曼哈顿距离(自己推一推) A.B的切比雪夫距离就是A‘.B‘曼哈顿距离的一半. 那么可以将x.y分离处理,排序中位数即可. 注意如果最后选的 ...

  9. SDUT 周赛 神奇的树(简单题 注意数据类型的溢出 )

    神奇的树 Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 SDUT有一颗神奇的苹果树.假如某天早上这树上有x个苹果,那么这树这一天 ...

  10. HDU1532 Drainage Ditches —— 最大流(sap算法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1532 Drainage Ditches Time Limit: 2000/1000 MS (Java/ ...