蒟蒻TLE求助
查看原帖
蒟蒻TLE求助
578726
FloisHargriff楼主2024/1/19 17:04
#include <bits/stdc++.h>
using namespace std;
const int N=100005;
struct pr{
	long long l,r,th;
}p[N];
long long a[N],cnt[N],pos[N],ans[N],s,l,r;
long long read(){
    int x=0,f=1;
	char ch=getchar();
    while(ch<'0'||ch>'9'){
		if(ch=='-')
			f=-1;
		ch=getchar();
	}
    while(ch>='0'&&ch<='9'){
		x=x*10+ch-'0';
		ch=getchar();
	}
    return x*f;
}
bool cmp(pr x,pr y){
	if(x.l==y.l)
		return x.r<y.r;
	return x.l<y.l;
}
void add(int x){
	cnt[a[x]]++;
	if(cnt[a[x]]==1)
		s++;
}
void del(int x){
	cnt[a[x]]--;
	if(cnt[a[x]]==0)
		s--;
}
int main(){
	int n,q;
	n=read();
	q=read();
	for(int i=1;i<=n;i++)
		a[i]=read();
	for(int i=1;i<=q;i++){
		p[i].l=read();
		p[i].r=read();
		p[i].th=i;
	}
	sort(p+1,p+1+q,cmp);
	for(int i=1;i<=q;i++){
		while(p[i].l<l)
			add(--l);
		while(p[i].r>r)
			add(++r);
		while(p[i].l>l)
			del(l++);
		while(p[i].r<r)
			del(r--);
		if(s==p[i].r-p[i].l+1)
			ans[p[i].th]=1;
	}
	for(int i=1;i<=q;i++){
		if(ans[i]==1)
			printf("Yes\n");
		else
			printf("No\n");
	}
	return 0;
}

前五个点过了,后五个点TLE

调了许久不知道哪里出错,求助!

2024/1/19 17:04
加载中...