expnoi @ 2023-02-05 00:56:33
#include<bits/stdc++.h>
using namespace std;
int n,m,a[100010],b[100010],cnt[39][39][40010],zs[41][41],S,bl[100010],L[100010],R[100010],tot[100010];
inline int query(int l,int r)
{
int p=bl[l],q=bl[r];
if(p==q)
{
for(int i=l;i<=r;i++)
{
tot[a[i]]=0;
}
int ma=0,w=0;
for(int i=l;i<=r;i++)
{
++tot[a[i]];
if(tot[a[i]]>ma)
{
ma=tot[a[i]];
w=a[i];
}
else if(tot[a[i]]==ma&&w>a[i])
{
w=a[i];
}
}
return b[w];
}
int ma=0,w=0;
for(int i=l;i<=R[p];i++)
{
cnt[p+1][q-1][a[i]]++;
if(cnt[p+1][q-1][a[i]]>ma)
{
w=a[i];
ma=cnt[p+1][q-1][a[i]];
}
else if(cnt[p+1][q-1][a[i]]==ma&&a[i]<w)
{
w=a[i];
ma=cnt[p+1][q-1][a[i]];
}
}
for(int i=L[q];i<=q;i++)
{
cnt[p+1][q-1][a[i]]++;
if(cnt[p+1][q-1][a[i]]>ma)
{
w=a[i];
ma=cnt[p+1][q-1][a[i]];
}
else if(cnt[p+1][q-1][a[i]]==ma&&a[i]<w)
{
w=a[i];
ma=cnt[p+1][q-1][a[i]];
}
}
if(cnt[p+1][q-1][zs[p+1][q-1]]>ma)
{
w=zs[p+1][q-1];
ma=cnt[p+1][q-1][zs[p+1][q-1]];
}
else if(cnt[p+1][q-1][zs[p+1][q-1]]==ma&&zs[p+1][q-1]<w)
{
w=zs[p+1][q-1];
ma=cnt[p+1][q-1][zs[p+1][q-1]];
}
for(int i=l;i<=R[p];i++)
{
cnt[p+1][q-1][a[i]]--;
}
for(int i=L[q];i<=q;i++)
{
cnt[p+1][q-1][a[i]]--;
}
return b[w];
}
int main()
{
cin>>n>>m;
S=pow(m,(double(1.0/3)));
for(int i=1;i<=n;i++)cin>>a[i],b[i]=a[i];
for(int i=1;i<=n+1;i++)
{
bl[i]=(i-1)/S+1;
if(bl[i]!=bl[i-1])
{
L[bl[i]]=i;
R[bl[i-1]]=i-1;
}
}
sort(b+1,b+n+1);
int M=unique(b+1,b+n+1)-b-1;
for(int i=1;i<=n;i++)a[i]=lower_bound(b+1,b+M+1,a[i])-b;
for(int i=1;i<=bl[n];i++)
for(int j=i;j<=bl[n];j++)
{
memcpy(cnt[i][j],cnt[i][j-1],sizeof(cnt[i][j]));
for(int k=L[j];k<=R[j];k++)
{
cnt[i][j][a[k]]++;
if(cnt[i][j][a[k]]>cnt[i][j][zs[i][j]])
{
zs[i][j]=a[k];
}
else if(cnt[i][j][a[k]]==cnt[i][j][zs[i][j]]&&a[k]<zs[i][j])
{
zs[i][j]=a[k];
}
}
}
int x=0,l0=0,r0=0;
while(m--)
{
cin>>l0>>r0;
int l=(l0+x-1)%n+1,r=(r0+x-1)%n+1;
if(l>r)swap(l,r);
x=query(l,r);
cout<<x<<"\n";
}
}
by heike305 @ 2023-02-05 21:52:34
@small_rubbish
我想你应该测测测试数据,而不是测样例
by dadaaa @ 2023-03-02 17:22:05
额找到为什么了吗,我也是(恼