Title: https://www.lydsy.com/JudgeOnline/problem.php?id=3781
is the MO team, the left end of the block sort, the block in the right end of the sorting, and then directly do.
The code is as follows:
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespaceStd;typedefLong Longll;int Constxn=5e4+5;intN,m,k,cnt[xn],d[xn],blk[xn],a[xn];ll SUM,ANS[XN];structn{intL,r,id;} Q[XN];BOOLCMP (N x,n y) {returnblk[x.l]==blk[y.l]?x.r<y.r:blk[x.l]<BLK[Y.L];}intRd () {intret=0, f=1;CharCh=GetChar (); while(ch<'0'|| Ch>'9'){if(ch=='-') f=0; Ch=GetChar ();} while(ch>='0'&&ch<='9') ret= (ret<<3) + (ret<<1) +ch-'0', ch=GetChar (); returnf?ret:-ret;}voidAddintPS) { intx=A[ps]; Sum-= (LL) cnt[x]*Cnt[x]; CNT[X]++; Sum+ = (LL) cnt[x]*cnt[x];}voidDelintPS) { intx=A[ps]; Sum-= (LL) cnt[x]*Cnt[x]; CNT[X]--; Sum+ = (LL) cnt[x]*cnt[x];}intMain () {n=rd (); M=rd (); K=rd ();intbs=sqrt (n); for(intI=1; i<=n;i++) A[i]=rd (), blk[i]= (i-1)/bs+1; for(intI=1; i<=m;i++) Q[i].l=rd (), Q[i].r=rd (), q[i].id=i; Sort (q+1, q+m+1, CMP); Add1); for(intI=1, l=1, r=1; i<=m;i++) { intQl=q[i].l,qr=Q[I].R; while(L<QL) del (l), l++; while(L>QL) l--, add (l); while(R<QR) r++, add (R); while(R>QR) del (r), r--; Ans[q[i].id]=sum; } for(intI=1; i<=m;i++) printf ("%lld\n", Ans[i]); return 0;}
Bzoj 3781 Little B's inquiry--Mo Team