Tea Yan Yue color

Tea Yan Yue color

Scan line

WA 4 times the segment tree open space mystery

#include<bits/stdc++.h>
using namespace std;
#define maxn 100005
struct Nod{
   int x,y;
   bool f;///记录左右端点?
}N[200005];
struct Tree{
 int d;
 int lazy;
}T[maxn*7];
vector<int> A;
bool cmp(Nod a,Nod b)
{
    if(a.y==b.y)return a.f==0;
    return a.y<b.y;
}
void pushdown(int x)
{
    T[x<<1].d+=T[x].lazy;
    T[x<<1].lazy+=T[x].lazy;
    T[x<<1|1].d+=T[x].lazy;
    T[x<<1|1].lazy+=T[x].lazy;
    T[x].lazy=0;
}
void pushup(int x)
{
    T[x].d=max(T[x<<1].d,T[x<<1|1].d);
}
void update(int l,int r,int ll,int rr,int v,int x)
{
    if(l>=ll&&r<=rr){
        T[x].d+=v;
        T[x].lazy+=v;
        return;
    }
    int mid=(l+r)>>1;
    pushdown(x);
    if(ll<=mid){
        update(l,mid,ll,rr,v,x<<1);
    }
    if(rr>mid){
        update(mid+1,r,ll,rr,v,x<<1|1);
    }
    pushup(x);
}
int n,k;
int main()
{
    scanf("%d%d",&n,&k);
    int x,y;
    for(int i=0;i<n;i++){
        scanf("%d%d",&x,&y);
        A.push_back(x);
        A.push_back(x+k);
        N[i]=Nod{x,y,1};
        N[i+n]=Nod{x,y+k,0};
    }
    //sort(A,A+n);
    sort(A.begin(),A.end());
    unique(A.begin(),A.end());
    sort(N,N+2*n,cmp);
    int ans=0;
    for(int i=0;i<2*n;i++){
        int l=lower_bound(A.begin(),A.end(),N[i].x)-A.begin()+1;
        int r=lower_bound(A.begin(),A.end(),N[i].x+k)-A.begin()+1;
        if(N[i].f){
           update(1,len,l,r,1,1);
        }
        else { 
             update ( 1 , len, l, r, - 1 , 1 ); 
        } 
        Years = max (years T [ 1 ] .d);
        // cout << endl << years; 
    } 
    Cout << years << ' \ n ' ; 

}

 

Guess you like

Origin www.cnblogs.com/liulex/p/11269249.html
yue