不会待补
思路:莫队算法,离线给所有区间排序,然后按顺序求答案即可,复杂度n^1.5
// res[ i ]=x 含义为有x个数出现了 i 次
#include<bits/stdc++.h>
#define db double
using namespace std;
const int maxn=1e5+10;
int a[maxn],b[maxn],vis[maxn],ans[maxn],block;
int res[maxn],mx;
struct node
{
int l,r,id;
bool operator<(const node&t)const
{
if(l/block==t.l/block)
return r<t.r;
return l/block<t.l/block;
}
}c[maxn];
void up(int i,int v)
{
res[vis[a[i]]]--;
if(v==1)
{
vis[a[i]]++;
res[vis[a[i]]]++;
mx=max(mx,vis[a[i]]);
}
else
{
vis[a[i]]--;
res[vis[a[i]]]++;
if(res[mx]==0)mx--;
}
}
int main()
{
int n,Q,l,r;
scanf("%d%d",&n,&Q);
block=int(sqrt(n));
for(int i=1;i<=n;i++)
scanf("

最低0.47元/天 解锁文章

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



