题目大意:给定一个长度为n的数组,m次询问某个区间内的mex值
怒写莫队233
将权值分成√n块,记录每个权值的出现次数以及每块内有多少权值出现过
修改O(1)即可完成 查询时首先扫一遍找到第一个块内有没有覆盖的点的块 然后在块内暴力查找 时间复杂度O(√n)
套个莫队 总时间复杂度O(m√n)
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define M 200200
using namespace std;
struct abcd{
int l,r,id;
bool operator < (const abcd &x) const;
}queries[M];
int n,m,b;
int a[M],belong[M],l[M],r[M];
int L=1,R=0,f[M],block_ans[M],ans[M];
bool abcd :: operator < (const abcd &x) const
{
if(belong[l]!=belong[x.l])
return l<x.l;
return r<x.r;
}
void Update(int x)
{
if(x>n) return ;
if(!f[x]++)
block_ans[belong[x]]++;
}
void Downdate(int x)
{
if(x>n) return ;
if(!--f[x])
block_ans[belong[x]]--;
}
int Query()
{
int i;
if(!f[0]) return 0;
for(i=1;l[i];i++)
if(block_ans[i]!=r[i]-l[i]+1)
break;
int temp=i;
for(i=l[temp];i<=r[temp];i++)

该博客介绍了如何使用莫队算法结合分块技术来解决BZOJ 3585问题,即在长度为n的数组上处理m次区间mex值查询。博主分享了如何实现修改操作的常数时间复杂度,并解释了在查询时如何通过扫描和块内暴力查找实现O(√n)的时间复杂度,最终达成总时间复杂度O(m√n)的解决方案。
最低0.47元/天 解锁文章
598

被折叠的 条评论
为什么被折叠?



