Vijos1507 [NOI2004] Depressed Teller

Source: Internet
Author: User

Title Link: https://vijos.org/p/1507

Orz Huang Seniors ... But think that the Huang long code will be the same value of the elements open to multiple points is a bit unscientific, so you change the value of the same element in a node to record the number of times.

Handed three times yellow seniors code average 2306ms, their own 1209ms.

1#include <iostream>2#include <cstdio>3#include <algorithm>4#include <cstring>5#include <ctime>6 #defineRep (i,l,r) for (int i=l; i<=r; i++)7 #defineCLR (x, y) memset (x,y,sizeof (×))8 using namespacestd;9typedefLong Longll;Ten Const intINF =0x3f3f3f3f; One Const intMAXN =100010; A structnode{ -     intl,r,v,w,size,rnd; - }T[MAXN]; the intN,low,x,root,cnt=0, tot=0, Delta=0;Charch; -InlineintRead () { -     intAns =0, F =1; -     Charc =GetChar (); +      while(!IsDigit (c)) { -         if(c = ='-') F =-1; +c =GetChar (); A     } at      while(IsDigit (c)) { -Ans = ans *Ten+ C-'0'; -c =GetChar (); -     } -     returnAns *F; - } in voidUpdateintW) { -T[w].size = t[t[w].l].size + t[t[w].r].size +T[W].W; to } + voidRotl (int&W) { -     intK = T[W].R; T[W].R = T[K].L; T[K].L =W; theUpdate (w); Update (k); W =K; * } $ voidROTR (int&W) {Panax Notoginseng     intK = T[W].L; T[W].L = T[K].R; T[K].R =W; -Update (w); Update (k); W =K; the } + voidInsertintXint&W) { A     if(!W) { theW = ++tot; T[W].V = x; T[W].W = T[w].size =1; +T[w].rnd =rand (); -         return; $     } $t[w].size++;if(T[W].V = = x) t[w].w++; -     Else if(X <t[w].v) { - Insert (X,T[W].L); the         if(T[t[w].l].rnd <t[w].rnd) ROTR (w); -     }Wuyi     Else{ the Insert (X,T[W].R); -         if(T[t[w].r].rnd <t[w].rnd) Rotl (w); Wu     } - } About intLeaveintXint&W) { $     intret; -     if(!W)return 0; -     if(T[W].V <x) { -ret = t[t[w].l].size + t[w].w; W =T[W].R; ARET + =leave (x,w); +     } the     Else{ -RET =leave (X,T[W].L); $T[w].size-=ret; the     } the     returnret; the } the intQueryintXintW) { -     if(!W)return 0; in     if(x <= t[t[w].l].size)returnquery (X,T[W].L); the     Else if(x > t[t[w].l].size + t[w].w)returnQuery (x-t[w].w-T[T[W].L].SIZE,T[W].R); the     Else returnT[W].V +Delta; About } the intMain () { theSrand (Time (0)); then = read (); Low =read (); +Rep (I,1, N) { -scanf"%c", &ch); x =read (); the         Switch(CH) {Bayi              Case 'I':if(x >= Low) insert (x-delta,root); Break; the              Case 'A': Delta + = x; Break; the              Case 'S': Delta-= x; CNT + = Leave (low-delta,root); Break; -              Case 'F': -                 if(T[root].size < x) printf ("-1\n"); the                 Elseprintf"%d\n", Query (t[root].size-x+1, Root)); the              Break; the         } the     } -printf"%d\n", CNT); the     return 0; the}
View Code

Vijos1507 [NOI2004] Depressed Teller

Related Keywords:

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.