DYan_Hyaena @ 2021-05-01 11:45:55
RT,附带本地过第5点交上去wa的喜报
#include<bits/stdc++.h>
#define rg register
#define ine inline
#define lowbit(x) x&(~x+1)
#define rge(x) R[x]-L[x]+1
#define ChaBuDuo return//差不多
#define Dele 0;//得了
using namespace std;
typedef long long ll;
typedef unsigned int ut;
typedef const int coi;
typedef unsigned long long ul;
inline int rd(){
int ans=0,f=1;
char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch)){ans=(ans<<3)+(ans<<1)+ch-48;ch=getchar();}
return ans*f;}
coi maxn=44444;
coi sqmx=11111;
int n,m;
vector<int> loc[maxn];
int a[maxn],b[maxn],c[maxn];
int pos[sqmx],zs[sqmx][sqmx],asker[maxn];
int L[sqmx],R[sqmx];
int intemp[maxn];
int findr(int rr,int locc){
int l=0,r=loc[locc].size()-1;
int mid;
while(l<r){
mid=(l+r+1)>>1;
if(loc[locc][mid]<=rr)l=mid;
else r=mid-1;
}
return l;
}
int findl(int ll,int locc){
int l=0,r=loc[locc].size()-1;
int mid;
while(l<r){
mid=(l+r)>>1;
if(loc[locc][mid]>=ll)r=mid;
else l=mid+1;
}
return l;
}
int query(int l,int r){
int resp=0,maxx=0,cnt=0,ccount;
int p=pos[l],q=pos[r];
memset(asker,0,sizeof asker);
if(q-p<=1)
for(int i=l;i<=r;i++)asker[++cnt]=c[i];
else{
asker[++cnt]=zs[p+1][q-1];
for(int i=l;i<=R[p];i++)asker[++cnt]=c[i];
for(int i=L[q];i<=r;i++)asker[++cnt]=c[i];
}
for(int i=1;i<=cnt;i++){
ccount=findr(r,asker[i])-findl(l,asker[i])+1;
if(maxx<ccount){
maxx=ccount;
resp=asker[i];
}
if(maxx==ccount)resp=min(asker[i],resp);
}
return resp;
}
void init(int x){
memset(intemp,0,sizeof intemp);
int maxx=0,manum=0;
for(int i=L[x];i<=n;i++){
intemp[c[i]]++;
if(maxx<intemp[c[i]] || (maxx==intemp[c[i]] && c[i]<manum)){
maxx=intemp[c[i]];
manum=c[i];
}
zs[x][pos[i]]=manum;
}
}
int main(){
freopen("P4168_5.in","r",stdin);
freopen("out3.txt","w",stdout);
n=rd(),m=rd();
for(int i=1;i<=n;i++)a[i]=b[i]=rd();
sort(b+1,b+1+n);
int tot=unique(b+1,b+1+n)-b-1;
int x=0,l,r,t=sqrt(n);
for(int i=1;i<=n;i++)
c[i]=lower_bound(b+1,b+1+tot,a[i])-b;
for(int i=1;i<=t;i++){
L[i]=(i-1)*t+1;
R[i]=i*t;
}
if(R[t]<n){
t++;
L[t]=R[t-1]+1,R[t]=n;
}
for(int i=1;i<=n;i++)loc[c[i]].push_back(i);
for(int i=1;i<=t;i++)
for(int j=L[i];j<=R[i];j++)
pos[j]=i;
for(int i=1;i<=t;i++)init(i);
while(m--){
l=rd(),r=rd();
l=((l+x-1)%n)+1;
r=((r+x-1)%n)+1;
if(l>r)swap(l,r);
x=b[query(l,r)];
cout<<x<<endl;
}
ChaBuDuo Dele;
}
}```
by dying @ 2021-05-01 11:49:36
%%% 蒟蒻只会打暴力