听取MLE声一片 @ 2021-02-16 15:21:37
RT,用的离散化+分块,样例能过,结果0分,照不出错/kk,求调。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<complex>
using namespace std;
inline int read(){
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
const int N=40010;
int n,m,a[N],b[N],t,t1,ans,book[N];
int L[N],R[N],pos[N],cnt[50][50][N];
int main()
{
n=read(),m=read();
for(int i=1;i<=n;i++){
a[i]=read();
b[i]=a[i];
}
sort(b+1,b+n+1);
int s=unique(b+1,b+n+1)-b-1;
for(int i=1;i<=n;i++)
a[i]=lower_bound(b+1,b+s+1,a[i])-b;
t=pow(n*1.0,1.0/3);
t1=t*t;
for(int i=1;i<=t;i++){
L[i]=(i-1)*t1+1;
R[i]=i*t1;
}
if(R[t]<n){
t++;
L[t]=R[t-1]+1;
R[t]=n;
}
for(int i=1;i<=t;i++)
for(int j=L[i];j<=R[i];j++){
pos[j]=i;
cnt[i][i][a[j]]++;
}
for(int i=1;i<t;i++)
for(int j=i+1;j<=t;j++)
for(int k=1;k<=n;k++)
cnt[i][j][k]=cnt[i][j-1][k]+cnt[j][j][k];
while(m--){
int l=read(),r=read();
l=(l+ans-1)%n+1,r=(r+ans-1)%n+1;
if(l>r)
swap(l,r);
ans=0;
int p=pos[l],q=pos[r];
if(p==q){
memset(book,0,sizeof(book));
int maxn=0;
for(int i=l;i<=r;i++)
book[a[i]]++;
for(int i=1;i<=n;i++)
if(book[i]>maxn){
maxn=book[i];
ans=i;
}
printf("%d\n",b[ans]);
}
else{
for(int i=l;i<=R[p];i++)
cnt[p+1][q+1][a[i]]++;
for(int i=L[q];i<=r;i++)
cnt[p+1][q+1][a[i]]++;
int maxn=0;
for(int i=1;i<=n;i++)
if(cnt[p+1][q+1][i]>maxn){
maxn=cnt[p+1][q+1][i];
ans=i;
}
for(int i=l;i<=R[p];i++)
cnt[p+1][q+1][a[i]]--;
for(int i=L[q];i<=r;i++)
cnt[p+1][q+1][a[i]]--;
printf("%d\n",b[ans]);
}
}
return 0;
}
by EDqwq @ 2021-02-16 15:22:38
写暴力!
by _5011_ @ 2021-02-16 15:23:01
此题标算O(nm)(确信)
by 听取MLE声一片 @ 2021-02-16 15:23:42
@林深时x见鹿 我傻了q搞错了
by 听取MLE声一片 @ 2021-02-16 15:24:46
就AC了一个/kk
by 听取MLE声一片 @ 2021-02-16 15:25:44
for(int i=l;i<=R[p];i++)
cnt[p+1][q-1][a[i]]++;
for(int i=L[q];i<=r;i++)
cnt[p+1][q-1][a[i]]++;
int maxn=0;
for(int i=1;i<=n;i++)
if(cnt[p+1][q-1][i]>maxn){
maxn=cnt[p+1][q-1][i];
ans=i;
}
for(int i=l;i<=R[p];i++)
cnt[p+1][q-1][a[i]]--;
for(int i=L[q];i<=r;i++)
cnt[p+1][q-1][a[i]]--;
printf("%d\n",b[ans]);
by 听取MLE声一片 @ 2021-02-16 16:24:03
@林深时x见鹿 @w33z8kqrqk8zzzх33 我只AC了一个点,求帮忙看看
by 听取MLE声一片 @ 2021-02-16 16:24:22
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<complex>
using namespace std;
inline int read(){
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
const int N=40010;
int n,m,a[N],b[N],t,t1,ans,book[N];
int L[N],R[N],pos[N],cnt[50][50][N];
int main()
{
n=read(),m=read();
for(int i=1;i<=n;i++){
a[i]=read();
b[i]=a[i];
}
sort(b+1,b+n+1);
int s=unique(b+1,b+n+1)-b-1;
for(int i=1;i<=n;i++)
a[i]=lower_bound(b+1,b+s+1,a[i])-b;
t=pow(n*1.000,1.000/3);
t1=n*1.0/t;
for(int i=1;i<=t;i++){
L[i]=(i-1)*t1+1;
R[i]=i*t1;
}
if(R[t]<n){
t++;
L[t]=R[t-1]+1;
R[t]=n;
}
for(int i=1;i<=t;i++)
for(int j=L[i];j<=R[i];j++){
pos[j]=i;
cnt[i][i][a[j]]++;
}
for(int i=1;i<t;i++)
for(int j=i+1;j<=t;j++)
for(int k=1;k<=n;k++)
cnt[i][j][k]=cnt[i][j-1][k]+cnt[j][j][k];
while(m--){
int l=read(),r=read();
l=(l+ans-1)%n+1,r=(r+ans-1)%n+1;
if(l>r)
swap(l,r);
ans=0;
int p=pos[l],q=pos[r];
if(p==q){
memset(book,0,sizeof(book));
int maxn=0;
for(int i=l;i<=r;i++)
book[a[i]]++;
for(int i=1;i<=n;i++)
if(book[i]>maxn){
maxn=book[i];
ans=i;
}
printf("%d\n",b[ans]);
}
else{
for(int i=l;i<=R[p];i++)
cnt[p+1][q-1][a[i]]++;
for(int i=L[q];i<=r;i++)
cnt[p+1][q-1][a[i]]++;
int maxn=0;
for(int i=1;i<=n;i++)
if(cnt[p+1][q-1][i]>maxn){
maxn=cnt[p+1][q-1][i];
ans=i;
}
for(int i=l;i<=R[p];i++)
cnt[p+1][q-1][a[i]]--;
for(int i=L[q];i<=r;i++)
cnt[p+1][q-1][a[i]]--;
printf("%d\n",b[ans]);
}
}
return 0;
}
by Ephemeroptera @ 2021-02-16 17:09:42
大毒瘤题没人会帮你调的qwq
by TerryGong @ 2021-02-16 18:32:20
@听取MLE声一片 +1
by Deamer @ 2023-08-03 07:30:22
@听取MLE声一片 解密的时候应该是对离散化前的答案解密就是对