"bzoj2223/3524" [Coci 2009]patuljci

Source: Internet
Author: User

Description

Input Output

10 3 1 2 1 2 1 2 3 2 3 3 8 1 2 1 3 1 4 1 5 2 5 2 6 6 9 7 10

Sample InputNo
Yes 1
No
Yes 1
No
Yes 2
No
Yes 3Sample Output HINT

Notice: The second integer input is the range of weights in the sequence Lim, i.e. 1<=ai (1<=i<=n) <=lim.

Still Chairman tree template, without discretization.

1<=lim<=10000

Source
1#include <iostream>2#include <cstdio>3#include <algorithm>4 #defineN 100000105 using namespacestd;6 intsum[n],root[500010],ls[n],rs[n];7 intN,m,lim,sz;8 voidUpdata (intLintRintXint&y,intv)9 {Teny=++sz; Onesum[y]=sum[x]+1; ALS[Y]=LS[X]; rs[y]=Rs[x]; -     if(L==R)return; -     intMid= (l+r) >>1; the     if(v<=mid) Updata (l,mid,ls[x],ls[y],v); -     ElseUpdata (mid+1, r,rs[x],rs[y],v); - } -   + intQueryintLintR) - { +     intL=1, r=n,temp= (r-l+1) >>1, x=root[l-1],y=Root[r],mid; A      while(l<R) at     { -         if(sum[y]-sum[x]<=temp)return 0; -Mid= (l+r) >>1; -         if(sum[ls[y]]-sum[ls[x]]>temp) -         { -R=mid; X=LS[X]; y=Ls[y]; in         } -         Else    if(sum[rs[y]]-sum[rs[x]]>temp) to         { +L=mid+1, X=rs[x]; y=Rs[y]; -         } the         Else    return 0; *     }    $     returnl;Panax Notoginseng } -   the intMain () + { Ascanf"%d%d",&n,&m); the      for(intI=1; i<=n;i++)    +     { -         intA; $scanf"%d",&a); $Updata (1, n,root[i-1],root[i],a); -     } - //scanf ("%d", &m); the      for(intI=1; i<=m;i++) -     {Wuyi         intAA,BB; thescanf"%d%d",&aa,&BB); -         intpos=query (AA,BB); Wuprintf"%d\n", POS); -     //if (pos==0) printf ("no\n"); About         //Else printf ("Yes%d\n", POS); $     } -     return 0; -}
View Code

"bzoj2223/3524" [Coci 2009]patuljci

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.