Snowy Smile hdu 6638 segment tree

 

Meaning of the questions: There are some points for each point the right to ask how the value of a selected rectangle take ownership of the rectangle so that the value of this internal weights and the largest in the two-dimensional plane

 

When the game thought out pity  

I have been thinking enumeration enumeration upper and lower boundaries upper and lower boundaries but has spent the rest of a log n2 certainly not enough

 

You can only enumerate the border and then dynamically enumerate the lower boundary  

 

Note that when the update must wait until a [j] .x! = A [j-1] .x

#include<bits/stdc++.h>
using namespace std;
//input by bxd
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define repp(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
#define see(x) (cerr<<(#x)<<'='<<(x)<<endl)
#define pb push_back
#define inf 0x3f3f3f3f
#define CLR(A,v)  memset(A,v,sizeof A)
typedef pair<int,int>pii;
//////////////////////////////////
const int N=2e6+10;

#define lson l,m,pos<<1
#define rson m+1,r,pos<<1|1

ll lmax[N<<2],rmax[N<<2],t[N<<2],maxans[N<<2];

void up(int pos)
{
    t[pos]=t[pos<<1]+t[pos<<1|1];
    maxans[pos]=max( max(maxans[pos<<1],maxans[pos<<1|1]),rmax[pos<<1]+lmax[pos<<1|1]  );
    lmax[pos]=max(lmax[pos<<1],t[pos<<1]+lmax[pos<<1|1]);
    rmax[pos]=max(rmax[pos<<1|1],t[pos<<1|1]+rmax[pos<<1]);
}
void build(int l,int r,int pos)
{
    if(l==r){lmax[pos]=rmax[pos]=t[pos]=maxans[pos]=0;return ;  }
    int m=(l+r)>>1;
    build(lson);build(rson);up(pos);
}
void upnode(int x,ll v,int l,int r,int pos)
{
    if(l==r){t[pos]+=v; lmax[pos]=rmax[pos]=maxans[pos]=max(1ll*0,t[pos]);return ;}
    int m=(l+r)>>1;
    if(x<=m)upnode(x,v,lson);
    else upnode(x,v,rson);
    up(pos);
}
int n,k,b[N],nn;

struct node
{
    int x,y,w;
}a[N];
int main()
{
    int cas;
    cin>>cas;
    while(cas--)
    {
        scanf("%d",&n);
        rep(i,1,n)
        {
            scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].w);
            b[++nn]=a[i].y;
        }
        sort(b+1,b+1+nn);
        nn=unique(b+1,b+1+nn)-b-1;
        rep(i,1,n)
        a[i].y=lower_bound(b+1,b+1+nn,a[i].y)-b;
        sort(a+1,a+1+n,[](node a,node b){return a.x<b.x||a.x==b.x&&a.y<b.y;});
        ll ans=0;
        rep(i,1,n)
        {
            if(i!=1&&a[i].x==a[i-1].x)continue;
            build(1,nn,1);
            rep(j,i,n)
            {
                if(j!=i&&a[j].x!=a[j-1].x)
                    ans=max(ans,maxans[1]);
                upnode(a[j].y,1ll* a [j] .w, 1,nn,1 ); 
            } 
            Years = max (years maxans [ 1 ]); 
        } 
        Cout << age << endl; 
    } 
    Return  0 ; 
}
View Code

 

Guess you like

Origin www.cnblogs.com/bxd123/p/11334187.html