Codeforces Beta Round #12 D. Ball (line segment tree)

Source: Internet
Author: User

Codeforces Beta Round #12 D. Ball (line segment tree)
Question:

Of the n women, if one of them has a larger 3D Dimension than the other, the female will commit suicide. Ask the number of suicide attempts.


Train of Thought Analysis:

First, sort by the first dimension.

Then, the second-dimensional values are discretely created using the second-dimensional subscript. The value on the tree is the third-dimensional, and the maximum value is obtained during update.

Note that the first dimension is used to enter the line segment tree from large to small.

In addition, it must increase progressively.

Therefore, when processing the first dimension to compare the size, we need to separate the processing. We need to judge the same first, and then update the data into the tree.

Then how can we determine whether this female has committed suicide.

First, you know that the first dimension is from large to small, so the first dimension of the node that comes with the advanced tree must be larger.

Again, we consider the second dimension. We can search for the third dimension in the node area with a large subscript In the second dimension on the tree.

If one dimension is greater than the third dimension, it is satisfied.


#include 
 
  #include 
  
   #include 
   
    #include #define lson num<<1,s,mid#define rson num<<1|1,mid+1,e#define maxn 500005using namespace std;struct node{    int a,b,c;    bool operator < (const node &cmp)const    {        if(a!=cmp.a)return a
    
     >1;    build(lson);build(rson);}void update(int num,int s,int e,int pos,int val){    if(s==e)    {        res[num]=max(res[num],val);        return;    }    int mid=(s+e)>>1;    if(pos<=mid)update(lson,pos,val);    else update(rson,pos,val);    pushup(num);}int query(int num,int s,int e,int l,int r){    if(l<=s  && r>=e)return res[num];    int mid=(s+e)>>1;    if(r<=mid)return query(lson,l,r);    else if(l>mid)return query(rson,l,r);    else return max(query(lson,l,mid),query(rson,mid+1,r));}int main(){    int n;    scanf("%d",&n);    for(int i=1;i<=n;i++)        scanf("%d",&wm[i].a);    for(int i=1;i<=n;i++)    {        scanf("%d",&wm[i].b);        x[i]=wm[i].b;    }    for(int i=1;i<=n;i++)        scanf("%d",&wm[i].c);    sort(wm+1,wm+1+n);    sort(x+1,x+1+n);    int m=unique(x+1,x+1+n)-x;    m--;    int last=wm[n].a;    int r=n;    int l=n;    int ans=0;    wm[0].a=0x3f3f3f3f;    for(int i=n;i>=1;)    {        while(wm[l].a==last)        {            l--;        }        int c=r;        while(c>l)        {            int pos=lower_bound(x+1,x+m+1,wm[c].b)-x;            if(pos+1<=m && query(1,1,m,pos+1,m)>wm[c].c)ans++;            c--;        }        c=r;        while(c>l)        {            int pos=lower_bound(x+1,x+m+1,wm[c].b)-x;            update(1,1,m,pos,wm[c].c);            c--;        }        i=l;r=l;last=wm[i].a;    }    printf("%d\n",ans);    return 0;}
    
   
  
 


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.