Submission #13741

#TimeUsernameProblemLanguageResultExecution timeMemory
13741gs13068역사적 조사 (JOI14_historical)C++98
5 / 100
38 ms147784 KiB
#include<cstdio> #include<algorithm> int a[111111]; int t[111111],tn; int c[111111][333]; long long d[333][333]; int p[111111]; int main() { long long res; int i,j,k,s,e,n,m,l,r; scanf("%d%d",&n,&m); for(i=0;i<n;i++) { scanf("%d",&a[i]); t[i]=a[i]; } std::sort(t,t+n); tn=std::unique(t,t+n)-t; for(i=0;i<n;i++)a[i]=std::lower_bound(t,t+tn,a[i])-t; for(i=0;i<n;i++) { if(!(i&511))for(j=0;j<tn;j++)c[j][(i>>9)+1]=c[j][i>>9]; d[a[i]][(i>>9)+1]++; } for(i=0;i<(n>>9);i++) { for(j=i+1;j<=(n>>9);j++) { d[i][j]=d[i][j-1]; for(k=(j-1)<<9;k<(j<<9);k++)if(1LL*t[a[k]]*(c[a[k]][j]-c[a[k]][i])>d[i][j])d[i][j]=1LL*t[a[k]]*(c[a[k]][j]-c[a[k]][i]); } } while(m--) { scanf("%d%d",&s,&e); s--; l=(s+511)>>9; r=e>>9; if(l<r) { res=d[l][r]; for(i=s;i<(l<<9);i++)p[a[i]]++; for(i=r<<9;i<e;i++)p[a[i]]++; for(i=s;i<(l<<9);i++)if(1LL*t[a[i]]*(p[a[i]]+c[a[i]][r]-c[a[i]][l])>res)res=1LL*t[a[i]]*(p[a[i]]+c[a[i]][r]-c[a[i]][l]); for(i=r<<9;i<e;i++)if(1LL*t[a[i]]*(p[a[i]]+c[a[i]][r]-c[a[i]][l])>res)res=1LL*t[a[i]]*(p[a[i]]+c[a[i]][r]-c[a[i]][l]); for(i=s;i<(l<<9);i++)p[a[i]]--; for(i=r<<9;i<e;i++)p[a[i]]--; } else { res=0; for(i=s;i<e;i++)p[a[i]]++; for(i=s;i<e;i++)if(1LL*t[a[i]]*p[a[i]]>res)res=1LL*t[a[i]]*p[a[i]]; for(i=s;i<e;i++)p[a[i]]--; } printf("%lld\n",res); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...