Rokua Topic Links
Test instructions
Given a long 5w static sequence, ask for 20w times, each time ask to find the number of elements in a range
Dyeing problem God, I've just been able to do it, and I feel like we can use a unified approach.
The first is to figure out the position of the nearest previous element, which is the same as an element, so that only the last position within the interval is less than the lower bound is the number of elements
It's a very reasonable look, but I can't see it for the first time.
Therefore, the problem of the number of numbers in the range of the color type problem is realized.
And then it's simple, give it to the Chairman tree.
The second chairman of the tree exercises.
Deep well ice error: Construct weight segment tree forget to put 0 in, mdzz
1#include <cstdio>2 #defineMid (L+r)/23 structnode{intSize,ls,rs;} t[4000000];4 intCnt=0, n,m,x,y,a[50001],p[50001],c[1000001],root[50001];5 intAddintNowintLintRintx)6 {7 intpo=++CNT;8T[po]= (node) {t[now].size+1, (L<r && x<=mid)? Add (t[now].ls,l,mid,x): T[now].ls, (L<r && x>mid)? Add (t[now].rs,mid+1, r,x): t[now].rs};9 returnPo;Ten } One intQueintXintYintLintRintz) A { - if(L==R)returnt[y].size-t[x].size; - return(Z<=mid) que (t[x].ls,t[y].ls,l,mid,z): T[t[y].ls].size-t[t[x].ls].size+que (t[x].rs,t[y].rs,mid+1, r,z); the } - intMain () - { -scanf"%d",&n); + for(intI=1; i<=n;i++) -scanf"%d", &a[i]), P[i]=c[a[i]],c[a[i]]=i,root[i]=add (root[i-1],0, N,p[i]); +scanf"%d",&m); A for(intI=1; i<=m;i++) atscanf"%d%d", &x,&y), printf ("%d\n", Que (root[x-1],root[y],0, n,x-1)); - return 0; -}
Boss Niang You also my code style!!!
Necklace of "SDOI2009" hh