Title: https://www.lydsy.com/JudgeOnline/problem.php?id=3781
A very classic piece of the Block routine. So the time space than everyone's team is a lot worse ...
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#definell Long Longusing namespacestd;Const intn=5e4+5, m= the;intN,m,w,Base, A[n],cnt[m][n],ct[n];ll Sm[m][m],ans;intrdn () {intret=0;BOOLfx=1;CharCh=GetChar (); while(ch>'9'|| ch<'0'){if(ch=='-') fx=0; ch=GetChar ();} while(ch>='0'&&ch<='9') ret= (ret<<3) + (ret<<1) +ch-'0', ch=GetChar (); returnfx?ret:-ret;}intBhintA) {return(A-1)/Base+1;}voidinit () {intR=BH (n); for(intI=1; i<=r;i++) { intt=i*Base, j=i; if(t>N) {t= (I-1)*Base; for(intk=t+1; k<=n;k++) Sm[i][i]+ = (cnt[i][a[k]]<<1)+1, cnt[i][a[k]]++; J=i-1; } for(; t;j--) {Sm[i][j]+=sm[i][j+1];// for(intk=1; k<=Base; k++,t--) {Sm[i][j]+ = (cnt[i][a[t]]<<1)+1; Cnt[i][a[t]]++; } } }}intMain () {n=rdn (); M=rdn (); w=RDN (); Base=sqrt (n); for(intI=1; i<=n;i++) a[i]=RDN (); Init (); for(intI=1, l,r,u,v;i<=m;i++) {L=rdn (); R=rdn (); U=BH (l); v=BH (R); if(v-u<=1) {ans=0; for(intj=l;j<=r;j++) ct[a[j]]=0; for(intj=l;j<=r;j++) ans+ = (ct[a[j]]<<1)+1, ct[a[j]]++; printf ("%lld\n", ans);Continue; } ans=sm[v-1][u+1]; intl=u*Base, R= (V-1)*Base; for(intj=l;j<=l;j++) {ans+ = ((cnt[v-1][A[J]]-CNT[U][A[J]]) <<1)+1; Cnt[v-1][a[j]]++; } for(intj=r+1; j<=r;j++) {ans+ = ((cnt[v-1][A[J]]-CNT[U][A[J]]) <<1)+1; Cnt[v-1][a[j]]++; } for(intj=l;j<=l;j++) cnt[v-1][a[j]]--; for(intj=r+1; j<=r;j++) cnt[v-1][a[j]]--; printf ("%lld\n", ans); } return 0;}
Bzoj 3781 Small B's inquiry--chunking