Bzoj 2120: Number of colors

Source: Internet
Author: User

1#include <cstdio>2#include <iostream>3#include <cmath>4#include <algorithm>5 #defineM 10000096 using namespacestd;7 intBlock,n,m,a[m],b[m],pre[m],pos[m],last[m],l[m],r[m],m1;8 intAskintA1,intA2)9 {Ten     intans=0; One     if(pos[a1]==POS[A2]) A       { -          for(inti=a1;i<=a2;i++) -           if(b[i]<A1) theans++; -       } -     Else -       { +          for(inti=a1;i<=r[pos[a1]];i++) -           if(b[i]<A1) +ans++; A          for(inti=l[pos[a2]];i<=a2;i++) at           if(b[i]<A1) -ans++; -          for(inti=pos[a1]+1; i<pos[a2];i++) -Ans+=lower_bound (pre+l[i],pre+r[i]+1, A1)-pre-L[i]; -       } -     returnans;  in } - voidJianinti) to { +l[i]= (I-1) *block+1; -R[i]=min (n,i*block); the      for(intj=l[i];j<=r[i];j++) *pre[j]=B[j]; $Sort (pre+l[i],pre+r[i]+1);Panax Notoginseng } - voidGaiintXinty) the { +      for(intI=1; i<=n;i++) Alast[a[i]]=0; thea[x]=y; +      for(intI=1; i<=n;i++) -       { $         intt=B[i]; $b[i]=Last[a[i]]; -         if(t!=Last[a[i]]) - Jian (pos[i]); thelast[a[i]]=i; -       }Wuyi } the intMain () - { Wuscanf"%d%d",&n,&M1); -      for(intI=1; i<=n;i++) Aboutscanf"%d",&a[i]); $Block= (int) sqrt (N+log (2*n)/log (2)); -m=n/Block; -     if(n%block) -m++; A      for(intI=1; i<=n;i++) +       { theb[i]=Last[a[i]]; -last[a[i]]=i; $pos[i]= (I-1)/block+1; the       } the      for(intI=1; i<=m;i++) the Jian (i); the      for(intI=1; i<=m1;i++) -       { in         Charch[5]; the         inta1,a2; thescanf"%s%d%d",ch,&a1,&A2); About         if(ch[0]=='Q') theprintf"%d\n", Ask (A1,A2)); the         Else the gai (A1,A2); +       } -     return 0; the}

Violent sub-blocks, each point to save a same color with him where, in each block sort, find the time of the end of the violence to judge each point the next color is not outside the interval, not on the answer Gaga, the middle two points. Rebuilds the next point that is stored at each point,

If you change it, rebuild the block.

Bzoj 2120: Number of colors

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.