Codeforces 12D Ball Multilevel sorting + discrete + segment tree

Source: Internet
Author: User

Given the b,i,r, for Pi, if the presence of PJ satisfies Bi < Bj && Ii < Ij && Ri < Rj, the pi is called probable self-murderers. Ask how many pi there are.

First, it is sorted in ascending order, with a priority of B > I > R.

Then found that for i < J, there must be bi <= Bj, so this layer can basically be ignored.

Then, due to the large data range, I is discrete, establish a segment tree record is greater than the maximum number of r in the interval, of course, at this time to scan from the back, edge update edge count.

#include <algorithm> #include <iostream> #include <cstring> #include <cstdlib> #include < cstdio> #include <queue> #include <cmath> #include <stack> #include <map> #include <ctime > #include <iomanip> #pragma comment (linker, "/stack:1024000000"); #define EPS (1e-6) #define LL Long Long#define ULL unsigned long long#define _ll __int64#define INF 0x3f3f3f3f#define Mod 1000000007using namespace std;struct n{int B,s,r;}    Sta[500010];bool cmp (N n1,n n2) {if (n1.b! = n2.b) return n1.b < n2.b;    if (n1.s! = N2.S) return N1.s < N2.S; return N1.R < N2.R;}    int num[500010];int delsame (int *num,int Top) {int i,j;    for (i = 2,j = 1; I <= Top; ++i) if (num[i]! = Num[j]) num[++j] = Num[i]; return J;}    int BS (int *num,int l,int r,int x) {int mid;        while (L <= r) {mid = (l+r) >>1;        if (num[mid] = = x) return mid; if (Num[mid] < x) L = mid+1;        else R = mid-1; } return-1;} int st[2000010];int updata (int site,int l,int r,int x,int D) {if (L = = r && r = = x) return St[site] = max    (ST[SITE],D);    int mid = (l+r) >>1;    if (x <= mid) return st[site] = max (St[site],updata (site<<1,l,mid,x,d)); return St[site] = max (St[site],updata (site<<1|1,mid+1,r,x,d));}    int Query (int site,int l,int r,int l,int R) {if (L = = L && r = r) return St[site];    int mid = (l+r) >>1;    if (R <= mid) return Query (SITE&LT;&LT;1,L,MID,L,R);    if (Mid < L) return Query (SITE&LT;&LT;1|1,MID+1,R,L,R); Return max (query (site<<1,l,mid,l,mid), query (Site<<1|1,mid+1,r,mid+1,r));}    int main () {int n,i,j;    scanf ("%d", &n);    for (i = 0; i < n; ++i) scanf ("%d", &sta[i].b);    for (i = 0; i < n; ++i) scanf ("%d", &AMP;STA[I].R);    for (i = 0; i < n; ++i) scanf ("%d", &AMP;STA[I].S);  Sort (sta,sta+n,cmp);  int Top = 0;    for (i = 0; i < n; ++i) num[++top] = STA[I].R;    Sort (num+1,num+top+1); Top = Delsame (num,top),//for (i = 1;i <= Top; ++i)//printf ("%d%d\n", i,num[i]);/for (i = 0; i < n; + +)    i)//printf ("I =%d%d%d\n", I,STA[I].B,STA[I].R,STA[I].S);    memset (st,0,sizeof (ST));    int site,ans = 0,tmp;    int R = N-1,val = sta[n-1].b;        for (i = n-1; I >= 0; i.) {if (sta[i].b = = val) continue;            for (j = i+1; J <= R; ++j) {site = BS (NUM,1,TOP,STA[J].R);        if (site! = Top && (tmp = Query (1,1,top,site+1,top)) > Sta[j].s) ans++;            } for (j = i+1; J <= R; ++j) {site = BS (NUM,1,TOP,STA[J].R);        Updata (1,1,TOP,SITE,STA[J].S);        } R = i;    val = sta[i].b;        } for (j = i+1; J <= R; ++j) {site = BS (NUM,1,TOP,STA[J].R); if (site! = Top && (tmp = Query (1,1,top,site+1,top)) > sta[J].S) ans++;    } printf ("%d\n", ans); return 0;}

Codeforces 12D Ball Multilevel sorting + discrete + segment tree

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.