Necklace of "SDOI2009" hh

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.