luogu P4688 [Ynoi2016]掉进兔子洞 bitset 莫队
题目链接
题解
莫队维护bitset区间交个数
代码
// luogu-judger-enable-o2
#include<cmath>
#include<bitset>
#include<cstdio>
#include<cstring>
#include<algorithm>
inline int read() {
int x = 0,f = 1;
char c = getchar();
while(c < '0' || c > '9') {if(c == '-')f = -1 ; c = getchar(); }
while(c <= '9' && c >= '0') x = x * 10 + c - '0', c = getchar();
return x * f;
}
const int whattt = 20001;
const int maxn = 100007;
int a[maxn],bel[maxn],b[maxn];
int l1[maxn],r1[maxn],l2[maxn],r2[maxn],l3[maxn],r3[maxn];
int sum[maxn];
int n,m,k;
struct Que {
int l,r,id;
Que(int l = 0,int r = 0,int id = 0) :l (l),r (r),id (id){};
bool operator < (const Que & a) const {
if(bel[l] == bel[a.l]) return r < a.r;
return bel[l] < bel[a.l];
}
} q[33334 * 3 + 7];
std::bitset<100000> F[whattt + 7],f;
bool mark[33334 + 7];
int len;
int cnt[maxn],c[whattt * 3 + 7];
void update(int k,int ty) {
k = a[k]; cnt[k] += ty;
if(ty == 1) f[k + cnt[k] - 2] = 1;
else f[k + cnt[k] - 1] = 0;
}
void solve() {
memset(mark,0,sizeof mark);
memset(cnt,0,sizeof(cnt));
std::sort(q + 1,q + len + 1);
int l = 1,r = 0;
f.reset();
for(int i = 1;i <= len;++ i) {
while(r < q[i].r) update(++ r,1);
while(r > q[i].r) update(r --,-1);
while(l < q[i].l) update(l ++,-1);
while(l > q[i].l) update(-- l,1);
if(mark[q[i].id])F[q[i].id] &= f,c[q[i].id] = F[q[i].id].count();
else F[q[i].id] = f,mark[q[i].id] = 1;
}
}
int main() {
//freopen("xp1.in","r",stdin);
n = read(),m = read();
k = sqrt(n);
for(int i = 1;i <= n;++ i) b[i] = a[i] = read(),bel[i] = (i - 1) / k + 1;
std::sort(b + 1,b + n +1);
len = n;
for(int i = 1;i <= n;++ i) a[i] = std::lower_bound(b + 1,b + len + 1,a[i]) - b;
for(int i = 1;i <= m;i += 1) {
l1[i] = read(),r1[i] = read(),l2[i] = read(),r2[i] = read(),l3[i] = read(),r3[i] = read();
sum[i] = r1[i] - l1[i] + 1 + r2[i] - l2[i] + 1 + r3[i] - l3[i] + 1;
}
for(int i = 1;i <= m;i += whattt) {
len = 0;
for(int j = i;j <= i + whattt - 1; ++ j) {
if(j > m) break;
q[++ len] = Que(l1[j],r1[j],j - i + 1);
q[++ len] = Que(l2[j],r2[j],j - i + 1);
q[++ len] = Que(l3[j],r3[j],j - i + 1);
}
solve();
for(int j = i;j < i + whattt; ++ j) {
if(j > m) break;
printf("%d\n",sum[j] - 3 * c[j - i + 1]);
//return 0;
}
}
return 0;
}
luogu P4688 [Ynoi2016]掉进兔子洞 bitset 莫队的更多相关文章
- luogu P4688 [Ynoi2016]掉进兔子洞
luogu 我们要求的答案应该是三个区间长度\(-3*\)在三个区间中都出现过的数个数 先考虑数列中没有相同的数怎么做,那就是对三个区间求交,然后交集大小就是要求的那个个数.现在有相同的数,考虑给区间 ...
- bzoj千题计划320:bzoj4939: [Ynoi2016]掉进兔子洞(莫队 + bitset)
https://www.lydsy.com/JudgeOnline/problem.php?id=4939 ans= r1-l1+1 + r2-l2+1 +r3-l3+1 - ∑ min(cnt1[i ...
- BZOJ4939 Ynoi2016掉进兔子洞(莫队+bitset)
容易发现要求三个区间各数出现次数的最小值.考虑bitset,不去重离散化后and一发就可以了.于是莫队求出每个区间的bitset.注意空间开不下,做多次即可.输出的东西错了都能调一年服了我了. #in ...
- BZOJ 4939 [Ynoi2016]掉进兔子洞(莫队+bitset)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=4939 [题目大意] 给出一个数列,每个询问给出三个区间,问除去三个区间共有的数字外, ...
- Luogu4688 [Ynoi2016]掉进兔子洞 【莫队,bitset】
题目链接:洛谷 我们知道要求的是\([l_1,r_1],[l_2,r_2],[l_3,r_3]\)的可重集取交的大小,肯定是要用bitset的,那怎么做可重集呢? 那就是要稍微动点手脚,首先在离散化的 ...
- [Luogu 4688] [Ynoi2016]掉进兔子洞 (莫队+bitset)
[Luogu 4688] [Ynoi2016]掉进兔子洞 (莫队+bitset) 题面 一个长为 n 的序列 a.有 m 个询问,每次询问三个区间,把三个区间中同时出现的数一个一个删掉,问最后三个区间 ...
- YNOI2016:掉进兔子洞 (莫队+bitset)
YNOI2016:掉进兔子洞 题意简述: 有 m 个询问,每次询问三个区间,把三个区间中同时出现的数一个一个删掉,问最后三个区间剩下的数的个数和,询问独立. 注意这里删掉指的是一个一个删,不是把等于这 ...
- 【bzoj4939】【YNOI2016】掉进兔子洞(莫队)
题目描述 您正在打galgame,然后突然发现您今天太颓了,于是想写个数据结构题练练手: 一个长为 n 的序列 a. 有 m 个询问,每次询问三个区间,把三个区间中同时出现的数一个一个删掉,问最后三个 ...
- p4688 [Ynoi2016]掉进兔子洞
传送门 分析 我们考虑先将所有数离散化 之后我们对于每个状态用一个bitset来记录 其中第i段表示颜色i的信息 对于每一段信息均是段首若干1,剩余若干0表示这种颜色有多少个 于是我们不难想到莫队 答 ...
随机推荐
- ActiveMQ学习笔记1
1.接口 JMS 公共 点对点域 发布/订阅域 ConnectionFactory QueueConnectionFactory TopicConnectionFactory Connection Q ...
- UML和模式应用5:细化阶段(2)--细化阶段制品之领域模型
1.前言 领域模型是OO分析中最重要和经典的模型.它阐述了领域中的重要概念: 领域模型作为设计某些软件对象的重要来源,也作为案例研究中探讨的几个制品的输入: 领域模型的范围限定于当前迭代开发的用例场景 ...
- (并发编程)全局解释器锁(GIL)-----有了GIL不用给线程加锁了?
一.全局解释器锁 (GIL)运行test.py的流程:a.将python解释器的代码从硬盘读入内存b.将test.py的代码从硬盘读入内存 (一个进程内装有两份代码---一份cpython解释器代码 ...
- (转)eclipse 创建maven web项目
1.新建Maven项目 1.1 File -> New -> Other 1.2 选择Maven Project ,单击Next 1.3 保持默认即可,单击Next 1.4 选择Arche ...
- Python-html css 盒模型
<!DOCTYPE html><html><head> <meta charset="UTF-8"> <title>ht ...
- js对象深拷贝
数组一维深拷贝:slice.concat.Array.from 对象一维深拷贝:Object.assign 一.利用扩展运算符...对数组中嵌套对象进行深拷贝 var arr=[{a:1,b:2},{ ...
- wpf Assembly.LoadFile dll GetType 反射 抛异常 不具有由 URI 识别的资源。
public static void LoadViewFromUri(this Window window, string baseUri) { try { var resourceLocater = ...
- 【ES】学习6-多字段搜索1
本系列的笔记都来自:https://elasticsearch.cn/book/elasticsearch_definitive_guide_2.x/multi-field-search.html 下 ...
- python简单笔记
Remarks:python中注意缩进(Tab键或者4个空格) print(输出) 格式:print(values) 字符串.数字.变量等都可以输出: 实例: print(1)->1 print ...
- python 全栈开发,Day133(玩具与玩具之间的对话,基于jieba gensim pypinyin实现的自然语言处理,打包apk)
先下载github代码,下面的操作,都是基于这个版本来的! https://github.com/987334176/Intelligent_toy/archive/v1.6.zip 注意:由于涉及到 ...