传送门

本来打算用主席树

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

于是用了莫队加树状数组

然后竟然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. Android——ListView优化

    1.ListView基本概念 列表显示需要三个元素: ListView:用来展示列表的View. 适配器:用来把数据映射到ListView上 数据:具体的将被映射的字符串,图片或基本组件 适配器类型分 ...

  2. Katalon

    Katalon---一款好用的selenium自动化测试插件 selenium框架是目前使用较广泛的开源自动化框架,一款好的.基于界面的录制工具对于初学者来说可以快速入门:对于老手来说可以提高开发自动 ...

  3. ime-mode:disabled (用css实现关闭文本框输入法)

    css 之 ime-mode语法:ime-mode : auto | active | inactive | disabled取值:auto : 默认值.不影响ime的状态.与不指定 ime-mode ...

  4. 【iOS开发系列】cell切割线置顶

    废话不多说,直接上代码: /** * tableViewCell切割线左側置顶 < 1 > */ -(void)viewDidLayoutSubviews { if ([_tableVie ...

  5. openwrt - squashfs-sysupgrade.bin 的生成过程

    squashfs-sysupgrade.bin 生成过程图 路径变量 $(KERNEL_BUILD_DIR)="/home/sam/Projects/openwrt-mt7620n/buil ...

  6. php利用cookie防止重复提交解决办法

    原理:如果数据通过了上边的两次验证,说明数据是合法有效的数据,这时候我们把提交的数据串接为一个字符串,并用MD5加密后得到一个MD5的值. 接着我们把这个值通过Cookie放进客户端,当用户下一次提交 ...

  7. 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 ...

  8. 用Qt编写的计算文件MD5值的Demo

    Dialog.ui <?xml version="1.0" encoding="UTF-8"?> <ui version="4.0& ...

  9. C# 软件实现远程桌面调用

    1.https://www.codeproject.com/Articles/19836/Palantir-Remote-Desktop-Manager codeproject项目 2.http:// ...

  10. Hive Metastore

    metastore:实际保存表信息的地方.     包括: 数据库,表的基本信息:权限信息:存储格式信息:                 各种属性信息:                 权限信息: ...