比赛 20160415x 评测结果 AATATTTTTTTTTTTTTTTT
题目名称 数字查询 最终得分 15
用户昵称 YXH_YXH 运行时间 35.043 s
代码语言 C++ 内存使用 0.45 MiB
提交时间 2016-04-15 16:00:33
显示代码纯文本
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
const int MAXN=40001,oo=(1<<30),DSX=200;
int read(){char ch;	int x=0,f=1;	ch=getchar();
	while('0'>ch||ch>'9'){if(ch=='-')f=-1;	ch=getchar();}
	while('0'<=ch&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';	ch=getchar();}
	return x*f;
}
int N,M,ca[MAXN];
void init(){
	N=read(),M=read();;
	for(int i=1; i<=N; i++)ca[i]=read();
}
bool fl[3001];
void work1(){int ans=0,st,ed;
	for(int i=1; i<=M; i++){
		st=read(),ed=read();
		st=(st+ans-1)%N+1,ed=(ed+ans-1)%N+1;
		if(st>ed){int t=st; st=ed; ed=t;}
		
		memset(fl,0,sizeof(fl));
		int Max=-100,xia;
		for(int j=st; j<=ed; j++){
			int te=ca[j],sum=1;
			if(!fl[j])
				for(int k=j+1; k<=ed; k++)
					if( (!fl[k])&&(ca[k]==te) )
						fl[k]=1,sum++;
			if(sum==Max&&ca[xia]>ca[j])xia=j;
			if(sum>Max)Max=sum,xia=j;
		}
		ans=ca[xia];
		printf("%d\n",ans);
	}
}
/*int b[MAXN];
void job(){int ans=0,st,ed;
	for(int i=1; i<=M; i++){
		st=read(),ed=read();
		st=(st+ans-1)%N+1,ed=(ed+ans-1)%N+1;
		if(st>ed){int t=st; st=ed; ed=t;}
		
		memcpy(b+st,ca+st,(ed-st+1)*sizeof(int));
		std::sort(b+st,b+ed+1);
		
		int num=b[st],Max=-1000;
		int u=std::upper_bound(b+st,b+ed+1,num)-(b+1);
		int v=std::lower_bound(b+st,b+ed+1,num)-b;
		if(b[u]==num)u++;
		if(u-v>Max){Max=u-v;ans=b[v];}
		while(u<ed){
			num=b[u];
			u=std::upper_bound(b+st,b+ed+1,num)-(b+1);
			v=std::lower_bound(b+st,b+ed+1,num)-b;
			if(b[u]==num)u++;
			if(u-v>Max){Max=u-v;ans=b[v];}
		}
		
		printf("%d\n",ans);
	}
}*/
/*int b[MAXN];
void work2();*/
int  main(){
	freopen("numquery.in","r",stdin);
	freopen("numquery.out","w",stdout);
	init();
	/*if(N<=3000)*/
	work1();
	//job();
	/*else	work2();*/
	return 0;
}
/*void work2(){
	memset(b,127,sizeof(b));
	for(int i=1; i<=N; i++)b[i]=ca[i];
	int ku=(N+1)/DSX;
	for(int i=0; i<=ku; i++)
		std::sort(b+i*DSX+1,b+(i+1)*DSX+1);
	///////yu
	int st,ed,ans=0;
	for(int i=1; i<=M; i++){
		st=read(),ed=read();
		st=(st+ans-1)%N+1,ed=(ed+ans-1)%N+1;
		if(st>ed){int t=st; st=ed; ed=t;}
		
		int L=1,R=1000000000,Mid;
		while(L+1<R){
			Mid=(L+R)>>1;
		}
	}
}*/
/*
1.暴力
2.分块+二分 验证		不可行
*/