比赛 |
20160415x |
评测结果 |
WWWWWTTTTTTTTTTTTTTT |
题目名称 |
数字查询 |
最终得分 |
0 |
用户昵称 |
mikumikumi |
运行时间 |
31.837 s |
代码语言 |
C++ |
内存使用 |
0.77 MiB |
提交时间 |
2016-04-15 15:33:46 |
显示代码纯文本
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
const int SIZEN=40010;
int a[SIZEN],A[SIZEN];
int tot=0,N,M;
void read()
{
scanf("%d%d",&N,&M);
for(int i=1;i<=N;i++)
{
scanf("%d",&a[i]);
A[i]=a[i];
}
}
/*class miku
{
public:
int l,r;
int ls,rs;
int sum,id;
miku()
{
sum=0;id=0;
}
#define l(x) tr[x].l
#define r(x) tr[x].r
#define ls(x) tr[x].ls
#define rs(x) tr[x].rs
#define sum(x) tr[x].sum
#define id(x) tr[x].id
}tr[SIZEN*40];
int root[SIZEN];
int built(int l,int r)
{
int now=++tot;
l(now)=l;r(now)=r;
id(now)=l;sum(now)=0;
if(l<r)
{
int mid=(l+r)/2;
ls(now)=built(l,mid);
rs(now)=built(mid+1,r);
}
return now;
}
int change(int k,int pos,int t)
{
int now=++tot;
tr[now]=tr[k];
if(l(now)==r(now))
{
sum(pos)+=t;
return now;
}
int mid=(l(now)+r(now))/2;
if(pos<=mid) ls(now)=change(ls(now),pos,t);
else rs(now)=change(rs(now),pos,t);
return now;
}*/
void prepare()
{
sort(A+1,A+1+N);
int n=1;
for(int i=2;i<=N;i++) if(A[i]!=A[i-1]) A[++n]=A[i];
for(int i=1;i<=N;i++) a[i]=lower_bound(A+1,A+1+n,a[i])-A;
}
int ans=0;
int cnt[SIZEN]={0};
void Calc(int L,int R)
{
int now=0;
for(int i=L;i<=R;i++)
{
cnt[a[i]]++;
if(cnt[a[i]]>cnt[now]||a[i]<now)
{
ans=A[a[i]];
now=a[i];
}
//cout<<now<<endl;
}
for(int i=L;i<=R;i++) cnt[a[i]]--;
printf("%d\n",ans);
}
void work()
{
int L,R;
//cout<<N<<" "<<M<<endl;
for(int i=1;i<=M;i++)
{
scanf("%d%d",&L,&R);
L=(L+ans-1)%N+1;R=(R+ans-1)%N+1;
if(R<L) swap(L,R);
//cout<<L<<" "<<R<<endl;
Calc(L,R);
//ans=query(root[R],root[L-1]);
}
}
int main()
{
freopen("numquery.in","r",stdin);
freopen("numquery.out","w",stdout);
read();
prepare();
work();
return 0;
}