题目为:P4168 [Violet]蒲公英
在洛谷上显示CE+TLE,记录;
在本地运行一开始无法输入,后来出现如下错误反馈:
Failed to execute "C:\Users\师大附中\Documents\未命名1.exe":
Error 0: 操作成功完成。
请按任意键继续. . .
这是蒟蒻第一次碰到这种问题
求助各位大佬,这是什么问题呢?萌新可以关注报答
代码如下:
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
using namespace std;
const int N=1e6+10;
const int BLOCK=510;
int n,m,k,cnt,blo,a[N],b[N];
int times[BLOCK][N],mode[BLOCK][BLOCK];
int be[BLOCK],en[BLOCK],bel[N];
int update(int x){
return lower_bound(b+1,b+k+1,x)-b;
}
void quti(int num,int start,int end){
for(int i=1;i<=k;i++){
times[num][i]=times[num-1][i];
}
for(int i=start;i<=end;i++){
++times[num][a[i]];
if(times[num][a[i]]>times[num][mode[num][num]]||(times[num][a[i]]==times[num][mode[num][num]]&&a[i]<mode[num][num])){
mode[num][num]=a[i];
}
}
}
void cut(){
for(int i=1;i<=n;i++){
++cnt;
if(cnt*blo>=n){
be[cnt]=i;
en[cnt]=n;
quti(cnt,i,n);
for(int j=1;j<=n;j++){
bel[j]=cnt;
}
break;
}
be[cnt]=i;
en[cnt]=cnt*blo;
quti(cnt,i,en[cnt]);
for(int j=i;j<=en[cnt];j++){
bel[j]=cnt;
}
i=en[cnt];
}
for(int i=1;i<=k;i++){
for(int j=i;j<=k;j++){
int tem=mode[i][j-1];
for(int l=be[j];l<=en[j];l++){
int v1=times[j][a[l]]-times[i-1][a[l]];
int v2=times[j][tem]-times[i-1][tem];
if(v1>v2||(v1==v2&&a[l]<tem)){
tem=a[l];
}
}
mode[i][j]=tem;
}
}
}
int solve(int l,int r){
int temcnt[N],temmode=0,blol=bel[l],blor=bel[r],modetime;
memset(temcnt,0,sizeof temcnt);
if(bel[r]-bel[l]<=1){
for(int i=l;i<=r;i++){
++temcnt[a[i]];
if(temcnt[a[i]]>temcnt[temmode]||(temcnt[a[i]]==temcnt[temmode]&&a[i]<temmode)){
temmode=a[i];
}
}
return temmode;
}
temmode=mode[blol][blor];
modetime=times[blor][temmode]-times[blol][temmode]+temcnt[temmode];
if(l>be[bel[l]]){
blol=bel[l]+1;
}
if(r<en[bel[r]]){
blor=bel[r]-1;
}
if(l>be[bel[l]]){
for(int i=l;i<=en[bel[l]];i++){
++temcnt[a[i]];
if(temcnt[a[i]]+(times[blor][a[i]]-times[blol-1][a[i]])>modetime||(temcnt[i]+(times[blor][a[i]]-times[blol-1][a[i]])==modetime&&a[i]<temmode)){
temmode=a[i];
modetime=temcnt[a[i]];
}
}
}
if(r<en[bel[r]]){
for(int i=be[bel[r]];i<=r;i++){
++temcnt[a[i]];
if(temcnt[a[i]]+(times[blor][a[i]]-times[blol-1][a[i]])>modetime||(temcnt[i]+(times[blor][a[i]]-times[blol-1][a[i]])==modetime&&a[i]<temmode)){
temmode=a[i];
modetime=temcnt[a[i]];
}
}
}
return temmode;
}
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
b[i]=a[i];
}
sort(b+1,b+n+1);
k=unique(b+1,b+n+1)-(b+1);
for(int i=1;i<=n;i++){
a[i]=update(a[i]);
}
int l,r,x=0;
blo=floor((double)sqrt(n*1.0));
cut();
/*cout<<blo<<endl;
for(int i=1;i<=cnt;i++){
cout<<be[i]<<" - "<<en[i]<<endl;
}
for(int i=1;i<=n;i++){
cout<<bel[i]<<" ";
}
cout<<endl;*/
for(int i=1;i<=m;i++){
scanf("%d%d",&l,&r);
l=((l+x-1)%n)+1;
r=((r+x-1)%n)+1;
if(l>r){
swap(l,r);
}
//cout<<l<<" - "<<r<<" : "<<endl;
x=b[solve(l,r)];
printf("%d\n",x);
}
return 1;
}