![[Luogu 3901]Difference [Luogu 3901]Difference](https://image.shishitao.com:8440/aHR0cHM6Ly9ia3FzaW1nLmlrYWZhbi5jb20vdXBsb2FkL2NoYXRncHQtcy5wbmc%2FIQ%3D%3D.png?!?w=700&webp=1)
Description
Input
Output
Sample Input
4 2
1 2 3 2
1 3
2 4
Sample Output
Yes
No
HINT
题解
莫队。加个标记数组维护该数在区间中出现了几次,再加个变量统计有几个数是重复的。
#include<map>
#include<set>
#include<ctime>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
#define RE register
#define IL inline
using namespace std;
const int N=1e5; int n,q,lim;
int cnt[N+],a[N+];
struct tt
{
int l,r,id;
}query[N+];
bool keep[N+]; IL bool comp(const tt &a,const tt &b) {return a.l/lim==b.l/lim ? a.r<b.r : a.l<b.l;} int main()
{
scanf("%d%d",&n,&q);
lim=sqrt(n);
for (RE int i=;i<=n;i++) scanf("%d",&a[i]);
for (RE int i=;i<=q;i++) scanf("%d%d",&query[i].l,&query[i].r),query[i].id=i;
sort(query+,query++q,comp);
int curl=,curr=,ans=,l,r;
for (RE int i=;i<=q;i++)
{
l=query[i].l,r=query[i].r;
while (curl<l) cnt[a[curl]]--,ans-=(cnt[a[curl++]]==);
while (curl>l) cnt[a[--curl]]++,ans+=(cnt[a[curl]]==);
while (curr<r) cnt[a[++curr]]++,ans+=(cnt[a[curr]]==);
while (curr>r) cnt[a[curr]]--,ans-=(cnt[a[curr--]]==);
if (!ans) keep[query[i].id]=;
}
for (RE int i=;i<=q;i++) printf(keep[i] ? "Yes\n":"No\n");
return ;
}