Orz POPOQQQ.
Originally Konjac Konjac thought that this discretization after the corresponding problem can not be the right value of the sub-block said.
...... As a result, >n's weight does not actually contribute to the answer.
#include <cstdio> #include <cmath> #include <algorithm>using namespace std; #define N 200002#define BN 452int n,m,num[n],a[n],l[bn],size[bn],anss[n],b[n],sumv[bn];struct ask{int l,r,p;} Q[n];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 Insert (const int &x) {if (x<=n) {if (!b[x]) ++sumv[num[x]];++b[x];}} void Delete (const int &x) {if (x<=n) {--b[x];if (!b[x])--sumv[num[x]];}} int Query () {for (int i=1;; ++i) if (Sumv[i]<size[i]) for (int j=l[i];; ++J) if (!b[j]) return J;} int main () {scanf ("%d%d", &n,&m), int sz=sqrt (n), blo=0, if (!SZ) sz=1;for (int i=1;i<=n;++i) {scanf ("%d",& A[i]); if (i%sz==1| | Sz==1) l[++blo]=i; Num[i]=blo; ++size[blo]; }l[1]=0; Num[0]=1; ++size[1];for (int i=1;i<=m;++i) {scanf ("%d%d", &Q[I].L,&Q[I].R); Q[i].p=i;} Sort (q+1,q+m+1); for (int i=q[1].l;i<=q[1].r;++i) Insert (A[i]); Anss[q[1].p]=query (); 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]); Anss[q[i].p]=query (); } for (int i=1;i<=m;++i) printf ("%d\n", Anss[i]); return 0;}
"Mo Team Algorithm" "Weights chunked" bzoj3585 Mex