Tree array + binary answer query K-Large number (group programming ladder l3-002. Stacks)

Source: Internet
Author: User
Tags strcmp

If the range of numbers is small

1 Data range: O (n)  2 I:log (n) (number of tree array queries less than or equal to i) *log (n) (binary found i) 3 added: Log (n) (tree array) 4 Delete: Log (n) (tree array)

Group Programming Ladder Race l3-002. Stack

1 /*data range: O (n)2 I:log (N) (number of tree array queries less than or equal to i) *log (n) (two points found i)3 Add: Log (n) (tree-like array)4 Delete: Log (n) (tree-like array)5 */ 6#include <cstdio>7#include <cstdlib>8#include <cmath>9#include <cstring>Ten#include <Set> One#include <vector> A#include <stack> -#include <map> -#include <queue> the#include <algorithm> -#include <iostream> - using namespacestd; - #defineMAXN 100000 +  - Longa[100005]; + Longst[100005]; A  at intMain () - { -     LongN,d,l,r,mid,i,g,c=0; -     Chars[ -]; -      for(i=0; i<=maxn;i++) -a[i]=0; inscanf"%ld",&n); -      while(n) to     { +n--; -scanf"%s", s); the         if(strcmp (s),"Pop")==0) *         { $             if(c==0)Panax Notoginseng             { -printf"invalid\n"); the                 Continue; +             }     AD=St[c]; theprintf"%ld\n", d); +              while(d<=MAXN) -             { $a[d]--; $d+= (D & (-d)); -             } -c--; the         } -         Else if(strcmp (s),"Push")==0)Wuyi         { thescanf"%ld",&d); -C++; Wust[c]=D;  -              while(d<=MAXN) About             { $a[d]++; -d+= (D & (-d)); -             } -         } A         Else +         { theD= (c+1) >>1; -             if(c==0) $             { theprintf"invalid\n"); the                 Continue;  the             } theL=1; R=MAXN; -              while(l<=R) in             { theMid= (l+r) >>1; theg=0; AboutI=mid; the                  while(i>=1) the                 { theg+=A[i]; +i-= (I & (-i)); -                 } the                 if(g>=d)Bayir=mid-1; the                 Else theL=mid+1; -             } -printf"%ld\n", L); the         } the     } the     return 0; the}

Tree array + binary answer query K-Large number (group programming ladder l3-002. Stacks)

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.