_Freedom_ @ 2021-02-02 15:52:43
rt,谷上的数据中太多重复的数字了,导致离散化后的 n^2暴力能过,建议加上一组序列中无重复数字的测试点。
(以下是我之前以为的正解,今天在另一个oj上被卡了)
# include <iostream>
# include <cstdio>
# include <cmath>
# include <algorithm>
using namespace std;
void read(int &x) {
static char c=getchar();
int f=1;
x=0;
while(!isdigit(c)) {
if(c=='-') f=-1;
c=getchar();
}
while(isdigit(c)) {
x=x*10+(c^'0');
c=getchar();
}
x*=f;
}
const int N=40010,K=210;
int L[K],R[K],pos[N];
int s[K][N];//s[i][j]?°i?é?DóD????j
int cnt[N];
int a[N];
int p[N],tot;
int x;
void print() {
int maxx=0;
for(int i=1; i<=tot; i++) {
if(cnt[i]>maxx) {
maxx=cnt[i];
x=i;
}
}
printf("%d\n",p[x]);
}
int main() {
// freopen("1.in","r",stdin);
// freopen("1.out","w",stdout);
int n,m,t,i,j,k,l,r;
read(n),read(m);
t=sqrt(n);
for(i=1; i<=n; i++) {
read(a[i]);
p[i]=a[i];
}
sort(p+1,p+1+n);
tot=unique(p+1,p+1+n)-p-1;
for(i=1; i<=n; i++) a[i]=lower_bound(p+1,p+1+tot,a[i])-p;
for(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(i=1; i<=t; i++) {
for(j=L[i]; j<=R[i]; j++) {
pos[j]=i;
}
}
for(i=1; i<=t; i++) {
for(j=1; j<=tot; j++) s[i][j]=s[i-1][j];
for(j=L[i]; j<=R[i]; j++) s[i][a[j]]++;
}
while(m--) {
read(l),read(r);
l=(l+p[x]-1)%n+1;
r=(r+p[x]-1)%n+1;
if(l>r) swap(l,r);
if(pos[l]==pos[r]) {
for(i=1; i<=tot; i++) cnt[i]=0;
for(i=l; i<=r; i++) cnt[a[i]]++;
print();
} else {
//pos[l]+1~pos[r]-1
for(i=1; i<=tot; i++) cnt[i]=s[pos[r]-1][i]-s[pos[l]][i];
for(i=l; i<=R[pos[l]]; i++) cnt[a[i]]++;
for(i=L[pos[r]]; i<=r; i++) cnt[a[i]]++;
print();
}
}
// fclose(stdin);
// fclose(stdout);
return 0;
}
by _Freedom_ @ 2021-02-02 15:53:12
@kkksc03
by hytmnt @ 2021-02-02 15:54:05
qp %%%
by _Life_ @ 2021-02-02 15:56:26
帮你 @BFqwq
by A_Đark_Horcrux @ 2021-02-02 15:56:57
%%%
by 福州W_C @ 2021-02-02 16:34:38
%%%
by QAQQWQ @ 2021-07-25 15:05:42
%%%