zoukankan      html  css  js  c++  java
  • 茶颜悦色

    茶颜悦色

    扫描线

    线段树开4倍空间谜之WA

    #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);
            }
            ans=max(ans,T[1].d);
            //cout<<ans<<endl;
        }
        cout<<ans<<'
    ';
    
    }
  • 相关阅读:
    c# 并行运算二
    c# 并行运算
    Task+http请求
    Task多线程
    SSO系统认证
    web系统权限设计
    AutoMapper的使用
    中间件
    express-middleware
    中间件概念
  • 原文地址:https://www.cnblogs.com/liulex/p/11269249.html
Copyright © 2011-2022 走看看