全部RE求调
查看原帖
全部RE求调
701254
Mu_leaf楼主2023/12/26 15:10

RT.

#include <bits/stdc++.h>
#define rand_(l,r) rand()%(r-l+1)+l;
using namespace std;
const int N=5e5+5;
int n,m;
int a[N],lstans,b[N];
vector<int> V[N];
signed main(){
//	freopen("data.in","r",stdin);
//	freopen("1.out","w",stdout);
	srand(time(NULL));
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]),b[i]=a[i];
	sort(b+1,b+n+1);
	int tot=unique(b+1,b+n+1)-b;
	for(int i=1;i<=n;i++) a[i]=lower_bound(b+1,b+tot+1,a[i])-b,V[a[i]].push_back(i);
	
	for(int i=1,l,r;i<=m;i++){
		scanf("%d%d",&l,&r);
		int fl=1,mx=0;
		for(int s=1;s<=20;s++){
			int p=rand_(l,r);
			int col=a[p];
			int v=upper_bound(V[col].begin(),V[col].end(),r)-lower_bound(V[col].begin(),V[col].end(),l);
			mx=max(mx,v);
			if(mx>(r-l+1)/2) break;
		}
		cout << (mx^lstans) << "\n";
	}
	return 0 ;
}


2023/12/26 15:10
加载中...