莫队不明原因T掉了6~10的点,求助
查看原帖
莫队不明原因T掉了6~10的点,求助
85142
socoolly楼主2021/1/9 17:20
#include <bits/stdc++.h>
using namespace std;
inline int read()
{
	register int x=0,f=0;
	register char ch=getchar();
	while(ch<'0' || ch>'9')
		f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9')
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
const int maxn=1e5+7;
int n,m;
int a[maxn];
int b[maxn];
struct sequences
{
	int l,r;
	int id;
};
sequences s[maxn];
bool cmp(sequences x, sequences y)
{
	return b[x.l]==b[y.l]?x.r<y.r:b[x.l]<b[y.l];
}
int cnt[maxn];
int add(int x)
{
	return cnt[a[x]]++?0:1;
}
int sub(int x)
{
	return --cnt[a[x]]?0:-1;
}
int res;
bool ans[maxn];
int main()
{
	n=read(),m=read();
	int len=sqrt(n);
	int bn=ceil((double)n/len);
	for(int i=1;i<=bn;i++)
		for(int j=(i-1)*len;j<=i*len;j++)
			b[i]=j;
	for(int i=1;i<=n;i++)
		a[i]=read();
	for(int i=1;i<=m;i++)
	{
		s[i].l=read(),s[i].r=read();
		s[i].id=i;
	}
	sort(s+1,s+m+1,cmp);
	int l=1,r=0;
	for(int i=1;i<=m;i++)
	{
		while(l<s[i].l) res+=sub(l++);
		while(l>s[i].l) res+=add(--l);
		while(r<s[i].r) res+=add(++r);
		while(r>s[i].r) res+=sub(r--);
		ans[s[i].id]=(res==s[i].r-s[i].l+1?true:false);
	}
	for(int i=1;i<=m;i++)
		puts(ans[i]?"Yes":"No");
}
2021/1/9 17:20
加载中...