HDU 2665 Kth Number Chairman Tree nude title

Source: Internet
Author: User

Topic links

Chairman Tree Detailed

Every time you insert a logn point, you don't need to rebuild.


#pragma COMMENT (linker, "/stack:1024000000,1024000000") #include <iostream> #include <fstream> #include <string> #include <time.h> #include <vector> #include <map> #include <queue> #include < algorithm> #include <stack> #include <cstring> #include <cmath> #include <set> #include < Vector>using namespace Std;template <class t>inline BOOL Rd (T &ret) {char c; int sgn;if (c = GetChar (), c = = EOF) return 0;while (c! = '-' && (c< ' 0 ' | | c> ' 9 ')) C = GetChar (); sgn = (c = = '-')? -1:1;ret = (c = = '-')? 0: (C-' 0 '); while (c = GetChar (), C >= ' 0 ' &&c <= ' 9 ') ret = ret * + (C-' 0 '); ret *= Sgn;return 1;} Template <class t>inline void pt (T x) {if (x < 0) {Putchar ('-'); x =-X;} if (x > 9) pt (X/10);p Utchar (x% 10 + ' 0 ');} typedef long Long Ll;typedef pair<int, int> pii;const int N = 100000 + +; #define L (x) tree[x].lson#define R (x) Tre E[x].rson#define S (x) tree[x].sumstruct NOde {int Lson, rson;int sum;} Tree[n << 5];int top;vector<int>hash;int gethash (int val) {return Lower_bound (Hash.begin (), Hash.end (), Val )-Hash.begin () + 1;} int build (int l, int r) {int id = ++top; S (id) = 0;if (L < r) {int mid = (L + r) >> 1; L (ID) = Build (L, mid); R (ID) = Build (mid + 1, r);} return ID;} int update (int pre, int l, int r, int val) {int id = ++top; L (id) = L (pre); R (ID) = R (pre); s (id) = s (pre) + 1;if (L < r) {int mid = (L + R) >> 1;if (Val <= mid) L (id) = Update (L (pre), L, Mid, Val); Elser (id) = Update (R (pre), Mid + 1, R, Val);} return ID;} int query (int old, int cur, int l, int r, int k) {if (L >= R) return l;int mid = (L + R) >> 1;int siz = S (L (cur)) -S (L (old)), if (Siz < K) return query (R (old), R (cur), mid + 1, R, K-siz), Elsereturn query (L (old), L (cur), L, Mid, k);} int N, q;int a[n];int t[n];int main () {int cas; rd (CAs); while (cas--) {rd (n); Rd (Q); Hash.clear (); top = 0;for (int i = 1; I <= n; i++) {rd (a[i]); Hash.push_back (A[i]);}Sort (Hash.begin (), Hash.end ()); Hash.erase (Unique (Hash.begin (), Hash.end ()), Hash.end ()); T[0] = Build (1, hash.size ()), for (int i = 1; I <= n; i++) {T[i] = Update (t[i-1], 1, hash.size (), Gethash (A[i]));} while (q--) {int L, R, K;rd (l); Rd (R); Rd (k); int id = query (t[l-1], t[r], 1, hash.size (), K);p T (hash[id-1]); puts (""); }}return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

HDU 2665 Kth Number Chairman Tree nude title

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.