Title.
#include <cstdio> #include <algorithm> #include <cmath>using namespace Std;int num,ch[12],f,c;inline void R (int &x) {c=0;f=1; for (;c< ' 0 ' | | C> ' 9 '; C=getchar ()) if (c== '-') f=-1; for (x=0;c>= ' 0 ' &&c<= ' 9 '; C=getchar ()) (x*=10) + = (c ' 0 '); X*=f;} void P (int x) {if (x<10) putchar (x+ ' 0 '); Else{p (X/10);p Utchar (x%10+ ' 0 ');}} #define N 100001#define M 1000001#define BN 330int sum=1,l[bn],num2[n],num[n],r[bn],a[n],b[n],cnts[bn];int anss[M],n,m ; struct Ask{int l,r,a,b,p;void Read (const int &i) {R (L); R (R); R (a); R (b);p =i;}} Q[m];bool operator < (const ask &a,const ask &b) {return NUM[A.L]!=NUM[B.L]? NUM[A.L]<NUM[B.L]: a.r<b.r; }void Makeblock () {int sz=sqrt (n), if (!sz) sz=1; for (; sum*sz<n;++sum) {l[sum]=r[sum-1]+1; r[sum]=sum*sz; for (int i=l[sum];i<=r[sum];++i) num[i]=sum; } l[sum]=r[sum-1]+1; for (int i=l[sum];i<=n;++i) num[i]=sum;} inline void Query (const int &L,CONST int &r,const int &Amp P) {int res=0;if (Num[l]==num[r]) for (int i=l;i<=r;++i) res+= (b[i]?1:0), else {for (int i=l;i<=r[num[l]];++i) res+= (b[i]?1:0); for (int i=l[num[r]];i<=r;++i) res+= (b[i]?1:0); for (int i=num[l]+1;i<num[r];++i) res+=cnts[i]; }anss[p]=res;} inline void Insert (const int &x) {if (!b[x]) ++cnts[num[x]; ++b[x];} inline void Delete (const int &x) {--b[x]; if (!b[x])--cnts[num[x]];} int main () {R (n); R (M), for (int i=1;i<=n;++i) R (A[i]), for (int i=1;i<=m;++i) q[i]. Read (i); Makeblock (); Sort (q+1,q+m+1); for (int i=q[1].l;i<=q[1].r;++i) Insert (A[i]); Query (Q[1].A,Q[1].B,Q[1].P); for (int i=2;i<=m;++i) {if (Q[I].L<Q[I-1].L) for (int j=q[i-1].l-1;j>=q[i].l;--j) Insert (A[j]); else for (int j=q[i-1].l;j<q[i].l;++j) Delete (A[j]); if (Q[I].R<Q[I-1].R) for (int j=q[i-1].r;j>q[i].r;--j) Delete (A[j]); else for (int j=q[i-1].r+1;j<=q[i].r;++j) Insert (A[j]); Query (Q[I].A,Q[I].B,Q[I].P); } for (int i=1;i<=m;++i)P (Anss[i]), puts (""); return 0;}
"Mo Team Algorithm" "Weight-value block" bzoj3809 Gty's two-forced sister sequence