【BZOJ-3809】Gty的二逼妹子序列 分块 + 莫队算法
3809: Gty的二逼妹子序列
Time Limit: 80 Sec Memory Limit: 28 MB
Submit: 1072 Solved: 292
[Submit][Status][Discuss]
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
Source
Solution
分块+莫队
很好想,一开始看错题,没写莫队,直接分块+lower_bound然后发现过不了样例...
其实挺好想,对权值分块,带上莫队搞搞就好...
启发:
序列操作统计颜色,可以优先往分块+莫队上搞
莫队的时候,询问的排序很关键..(手误打反了第1,2关键字,居然能过3组..)
Code
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdio>
using namespace std;
int read()
{
int x=,f=; char ch=getchar();
while (ch<'' || ch>'') {if (ch=='-') f=-; ch=getchar();}
while (ch>='' && ch<='') {x=x*+ch-''; ch=getchar();}
return x*f;
}
#define maxn 100010
#define maxm 1000100
int n,m,a[maxn],pos[maxn],num[maxn],an[maxn],bll,bln;
struct Asknode
{
int l,r,a,b,id;
bool operator < (const Asknode & A) const
{
if (pos[l]==pos[A.l]) return r<A.r;
return l<A.l;
}
}q[maxm];
int ans[maxm],qn;
int Query(int l,int r)
{
int ans=;
if (pos[l]==pos[r])
for (int i=l; i<=r; i++) if (num[i]) ans++; else continue;
else
{
for (int i=l; i<=pos[l]*bll; i++) if (num[i]) ans++;
for (int i=(pos[r]-)*bll+; i<=r; i++) if (num[i]) ans++;
}
for (int i=pos[l]+; i<=pos[r]-; i++) ans+=an[i];
return ans;
}
void move1(int x)
{
num[a[x]]--; if (num[a[x]]==) an[pos[a[x]]]--;
}
void move2(int x)
{
num[a[x]]++; if (num[a[x]]==) an[pos[a[x]]]++;
}
int nl=,nr=;
void work(int x)
{
int L=q[x].l,R=q[x].r,id=q[x].id;
while (nl<L) move1(nl),nl++;
while (nr>R) move1(nr),nr--;
while (nl>L) nl--,move2(nl);
while (nr<R) nr++,move2(nr);
ans[id]=Query(q[x].a,q[x].b);
// printf("%d %d %d %d %d\n",x,L,R,id,ans[id]);
}
int main()
{
n=read(),m=read(); bll=sqrt(n/); if (n%bll) bln=n/bll+; else bln=n/bll;
// printf("%d %d\n",bll,bln);
for (int i=; i<=n; i++) a[i]=read(),pos[i]=(i-)/bll+;
// for (int i=1; i<=n; i++) printf("%d\n",pos[i]);
for (int i=; i<=m; i++)
q[i].l=read(),q[i].r=read(),q[i].a=read(),q[i].b=read(),q[i].id=i;
sort(q+,q+m+);
for (int i=; i<=m; i++) work(i);
for (int i=; i<=m; i++) printf("%d\n",ans[i]);
return ;
}
%%%Gty大哥,%%%块爷,%%%Basker学长
前排围观自己的傻逼错误:

【BZOJ-3809】Gty的二逼妹子序列 分块 + 莫队算法的更多相关文章
- bzoj 3809 Gty的二逼妹子序列(莫队算法,块状链表)
[题意] 回答若干个询问,(l,r,a,b):区间[l,r]内权值在[a,b]的数有多少[种]. [思路] 考虑使用块状链表实现莫队算法中的插入与删除. 因为权值处于1..n之间,所以我们可以建一个基 ...
- BZOJ.3809.Gty的二逼妹子序列(分块 莫队)
题目链接 /* 25832 kb 26964 ms 莫队+树状数组:增加/删除/查询 都是O(logn)的,总时间复杂度O(m*sqrt(n)*logn),卡不过 莫队+分块:这样查询虽然变成了sqr ...
- BZOJ 3809 Gty的二逼妹子序列(莫队+分块)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3809 [题目大意] 给定一个长度为n(1<=n<=100000)的正整数序 ...
- 【BZOJ 3809】 3809: Gty的二逼妹子序列 (莫队+分块)
3809: Gty的二逼妹子序列 Time Limit: 80 Sec Memory Limit: 28 MBSubmit: 1728 Solved: 513 Description Autumn ...
- BZOJ 3809: Gty的二逼妹子序列
3809: Gty的二逼妹子序列 Time Limit: 80 Sec Memory Limit: 28 MBSubmit: 1387 Solved: 400[Submit][Status][Di ...
- Bzoj 3809: Gty的二逼妹子序列 莫队,分块
3809: Gty的二逼妹子序列 Time Limit: 35 Sec Memory Limit: 28 MBSubmit: 868 Solved: 234[Submit][Status][Dis ...
- [bzoj3809]Gty的二逼妹子序列_莫队_分块
Gty的二逼妹子序列 bzoj-3809 题目大意:给定一个n个正整数的序列,m次询问.每次询问一个区间$l_i$到$r_i$中,权值在$a_i$到$b_i$之间的数有多少个. 注释:$1\le n\ ...
- BZOJ 3809 Gty的二逼妹子序列 莫队算法+分块
Description Autumn和Bakser又在研究Gty的妹子序列了!但他们遇到了一个难题. 对于一段妹子们,他们想让你帮忙求出这之内美丽度∈[a,b]的妹子的美丽度的种类数. 为了方便,我们 ...
- [ AHOI 2013 ] 作业 & [ BZOJ 3809 ] Gty的二逼妹子序列
\(\\\) Description 给出一个长为 \(n\) 的数列 \(A\) 和 \(k\),多次询问: 对于一个区间 \([L_i,R_i]\),问区间内有多少个数在 \([a_i,b_i]\ ...
随机推荐
- Nginx 启用 https
在nginx.conf中增加新server配置 server { listen ; server_name www.some.com; ssl on; ssl_certificate sslkey/s ...
- Linux下命令行安装配置android sdk
首先, 你得有个VPN 参考以下三篇完成Android SDK的安装 https://www.digitalocean.com/community/tutorials/how-to-build-and ...
- 假设检验:p-value,FDR,q-value
来源:http://blog.sina.com.cn/s/blog_6b1c9ed50101l02a.html,http://wenku.baidu.com/link?url=3mRTbARl0uPH ...
- Openjudge 3.9-3339
3339:List 总时间限制: 4000ms 内存限制: 65536kB 描述 写一个程序完成以下命令:new id --新建一个指定编号为id的序列(id<10000)add id num- ...
- mongodb.conf配置文件详解
mongod --config /etc/mongodb.conf 配置如下:verbose:日志信息冗余.默认false.提高内部报告标准输出或记录到logpath配置的日志文件中.要启用verbo ...
- echo使用说明,参数详解
简介 echo [OPTION]... [STRING]... 描述 -n 末尾不加换行 -e 开启输出字串中对反斜杠的转译 -E 禁用反斜杠转译 只有开启-e参数的时候,下面的命令才能起作用: \0 ...
- 开发备忘:AngularJS Syntax error, unrecognized expression in template file
在写基于Angular的项目过程中,运行 grunt test的时候,一直给我蹦出这个错误,导致我的test一直跑不过,怎么试都是失败,经过重复排查,发现是因为template file中的html元 ...
- DOM Element节点类型详解
上文中我们讲解了 DOM 中最重要的节点类型之一的 Document 节点类型,本文我们继续深入,谈谈另一个重要的节点类型 Element . 1.概况 Element 类型用于表现 HTML 或 X ...
- 用canvas画简单的“我的世界”人物头像
前言:花了4天半终于看完了<Head First HTML5>,这本书的学习给我最大的感受就是,自己知识的浅薄,还有非常多非常棒的技术在等着我呢.[熊本表情]扶朕起来,朕还能学! H5新增 ...
- React Native 在现有项目中的探路
移动开发中,native开发性能和效果上无疑是最好的. 但是在众多的情况下,native开发并不是最优的选择.当需求经常改动的时候,当预算有限的时候,当deadline很近的时候,native开发的成 ...