ZOJ problem Set-3635

Source: Internet
Author: User

Main topic

There are n from 1. n the number of seats, given in chronological order, each guest is seated in the first few empty seats, and finally asks a few questions where the number I guest sits.

Analysis

Segment Tree + two points

1 //Fast Sequence Operations II2 //Rujia Liu3 //Input Format:4 //N m array range is a[1]~a[n], initialized to 0. The operation has a M5 //1 L R v = set A[l]=a[l+1]=...=a[r] = v. where v > 06 //2 L R query a[l]~a[r] sum, min and Max7#include <cstdio>8#include <cstring>9#include <algorithm>Ten using namespacestd; One  A Const intMaxnode =1<< -; -  - int_sum, _min, _max, op, QL, QR, V; the intVist[maxnode]; - structIntervaltree { -   intSumv[maxnode], Minv[maxnode], Maxv[maxnode], Setv[maxnode]; -  +   //Maintenance Information -   voidMaintain (intOintLintR) { +     intLC = o*2, rc = o*2+1; A     if(R >L) { atSumv[o] = SUMV[LC] +SUMV[RC]; -Minv[o] =min (MINV[LC], MINV[RC]); -Maxv[o] =Max (MAXV[LC], MAXV[RC]); -     } -     if(Setv[o] >=0{Minv[o] = Maxv[o] = Setv[o]; Sumv[o] = setv[o] * (r-l+1); } -   } in  -   //Tag Delivery to   voidPushdown (into) { +     intLC = o*2, rc = o*2+1; -     if(Setv[o] >=0) {//This node is marked for delivery. Note that the set value is non-negative in the subject, so-1 means no tag theSETV[LC] = SETV[RC] =Setv[o]; *Setv[o] =-1;//Clear this node marker. $     }Panax Notoginseng   } -  the   voidUpdateintOintLintR) { +     intLC = o*2, rc = o*2+1; A     if(QL <= L && qR >= R) {//Tag Modification theSetv[o] =v; +}Else { - pushdown (o); $       intM = L + (r-l)/2; $       if(QL <= m) Update (LC, L, M);ElseMaintain (LC, L, M); -       if(QR > M) Update (RC, m+1, R);ElseMaintain (RC, m+1, R); -     } the maintain (o, L, R); -   }Wuyi  the   voidQueryintOintLintR) { -     if(Setv[o] >=0) {//recursive boundary 1: A set tag Wu_sum + = setv[o] * (min (R,QR)-max (L,QL) +1); -_min =min (_min, setv[o]); About_max =Max (_max, Setv[o]); $}Else if(QL <= L && qR >= R) {//recursive boundary 2: Boundary interval -_sum + = Sumv[o];//this boundary range is not affected by any set operation -_min =min (_min, minv[o]); -_max =Max (_max, Maxv[o]); A}Else{//Recursive Statistics +       intM = L + (r-l)/2; the       if(QL <= M) query (o*2, L, M); -       if(QR > M) query (o*2+1, m+1, R); $     } the   } the }; the  the Const intINF =1000000000; -  in Intervaltree Tree; the  the intMain () { About   intN, M,num; the    while(SCANF ("%d", &n)! =EOF) { thememset (&tree,0,sizeof(tree)); thememset (Tree.setv,-1,sizeof(Tree.setv)); +tree.setv[1] =0; -v=1; theQl=1;BayiQr=N; theTree.update (1,1, n); theTree.query (1,1, n); -      for(intI=1; i<=n;i++) -     { thescanf"%d",&num); theQl=1; qr=N; the_sum =0; the         intL=1, r=N,mid; -          while(l<R) the         { theMid= (L+R)/2; theQr=mid;94Tree.query (1,1, n); the              if(_sum>=num) theR=mid; the              Else98L=mid+1; About_sum =0; -         }101vist[i]=l;102v=0;103Ql=l;104Qr=l; theTree.update (1,1, n);106     }107scanf"%d",&m);108      for(intI=1; i<=m;i++)109     { thescanf"%d",&num);111printf"%d", Vist[num]); the         if(i!=m)113printf" "); the  the     } theprintf"\ n");117   }118   return 0;119}

ZOJ problem Set-3635

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.