Codeforces Beta Round #12 (Div 2 only) D. Ball tree array query suffix, max

Source: Internet
Author: User

Http://codeforces.com/problemset/problem/12/D

The bit query here refers to the maximum value between the query [1, R] or [R, Maxn], which is sufficient.

Set three weights respectively b[1], b[2], b[2];

First, the b[1] value discretization, discrete into a ID, then can only be found in the location of the larger ID. Then the b[2] sort, reverse query, that is, the first query the largest, of course, it is not possible to commit suicide, because it has the largest, and then after the query, put it into a bit, after the bit query, do not need to tube b[2], because in bit inside the b[2] is always the larger, In fact, this is a common method. Hack point is the same value can not be updated in advance, the details see Code + slowly debug

Now talk about the role of bit, bit maintenance is b[3], because we have discretized b[1], then each element of the subscript is equivalent to the discretization of the b[1], so add in the bit when the ID do subscript. The bit maintains the suffix maximum value.

Hack point means, if your a[i].b[2] = = a[j].b[2], then can not be in the query A[j] ahead of the a[i] to join bit, because bit query by default is B[2] established, but in advance to update the words, not set.

#include <cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<algorithm>#include<assert.h>#defineIOS Ios::sync_with_stdio (False)using namespacestd;#defineINF (0X3F3F3F3F)typedefLong Long intLL; #include<iostream>#include<sstream>#include<vector>#include<Set>#include<map>#include<queue>#include<string>#include<bitset>#include<stack>Const intMAXN = 5e5 + -;intC[MAXN], en;intLowbit (intx) {returnX & (-x);}voidUpDate (intPosintval) {     while(POS) {C[pos]=Max (C[pos], Val); POS-=Lowbit (POS); }}intAskintPOS) {    intAns =-1;  while(Pos <=en) {ans=Max (ans, c[pos]); POS+=Lowbit (POS); }    returnans;}structNode {inta[5], id;} A[maxn];stack<int>St;BOOLCmp0 (structNode A,structNode B) {    returna.a[1] < b.a[1];}BOOLCMP1 (structNode A,structNode B) {    returna.a[2] < b.a[2];}voidWork () {intN; scanf ("%d", &N);  for(inti =1; I <= N; ++i) scanf ("%d", &a[i].a[1]);  for(inti =1; I <= N; ++i) scanf ("%d", &a[i].a[2]);  for(inti =1; I <= N; ++i) scanf ("%d", &a[i].a[3]); Sort (a+1, A +1+N, cmp0); En=1; a[1].id =en;  for(inti =2; I <= N; ++i) {if(a[i].a[1] = = A[i-1].a[1]) {a[i].id=en; } ElseA[i].id = + +en; } en+=2; Memset (c,-1,sizeofc); Sort (a+1, A +1+N, CMP1);//for (int i = 1; I <= n; ++i) {//cout << a[i].a[1] << "<< a[i].a[2] <<" "<< a[i].a[3] <<" "<< A[i].id << Endl;//    }St.push (n); intAns =0;  for(inti = n-1; I >=1; --i) {if(a[i].a[2] = = A[i +1].a[2]) {St.push (i); intres = Ask (A[i].id +1); Ans+ = res > a[i].a[3]; } Else {             while(!St.empty ()) {                intres =St.top ();                St.pop (); UpDate (a[res].id, a[res].a[3]); }            intres = Ask (A[i].id +1); Ans+ = res > a[i].a[3]; St.push (i);//upDate (A[i].id, a[i].a[3]);}} cout<< ans <<Endl;}intMain () {#ifdef local freopen ("Data.txt","R", stdin);//freopen ("Data.txt", "w", stdout);#endifWork (); return 0;}
View Code

Codeforces Beta Round #12 (Div 2 only) D. Ball tree array query suffix, max

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.