这题是杭电多校2019第六场的题目

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6638

题意:给你平面上n个点,每个点都有权值(有负权),让你计算一个矩阵可能的最大覆盖权值和;

思路:用  连续最大子段-线段树  枚举上界,按行一行行更新线段树中的点,每插完一行就更新答案(类似枚举上下界),时间复杂度:O( n^2*log(n) ) ;

 #define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#include <cstdio>//sprintf islower isupper
#include <cstdlib>//malloc exit strcat itoa system("cls")
#include <iostream>//pair
#include <fstream>
#include <bitset>
#include <map>
//#include<unordered_map> http://acm.hdu.edu.cn/showproblem.php?pid=6638
#include <vector>
#include <stack>
#include <set>
#include <string.h>//strstr substr
#include <string>
#include <time.h>//srand(((unsigned)time(NULL))); Seed n=rand()%10 - 0~9;
#include <cmath>
#include <deque>
#include <queue>//priority_queue<int, vector<int>, greater<int> > q;//less
#include <vector>//emplace_back
//#include <math.h>
//#include <windows.h>//reverse(arr,arr+len);// ~ ! ~ ! floor
#include <algorithm>//sort + unique : sz=unique(b+1,b+n+1)-(b+1);+nth_element(first, nth, last, compare)
using namespace std;//next_permutation(arr+1,arr+1+n);//prev_permutation
#define fo(arr,b,c) for(register int arr=b;arr<=c;++arr)
#define fr(arr,b,c) for(register int arr=b;arr>=c;--arr)
#define mem(arr,b) memset(arr,b,sizeof(arr))
#define pr printf
#define sc scanf
#define ls rt<<1
#define rs rt<<1|1
void swapp(int &arr,int &b);
double fabss(double arr);
int maxx(int arr,int b);
int minn(int arr,int b);
int Del_bit_1(int n);
int lowbit(int n);
int abss(int arr);
//const long long INF=(1LL<<60);
const double E=2.718281828;
const double PI=acos(-1.0);
const int inf=(<<);
const double ESP=1e-;
const int mod=(int)1e9+;
const int N=(int); int b[N];
struct node_
{
int x,y;
long long v;
friend bool operator<(node_ a,node_ b)
{
if(a.y==b.y)
return a.x<b.x;
return a.y>b.y;
}
}arr[N];
struct vnode
{
int x;
long long v;
};
//=================================================离散化;
int LSx(int n)
{
int m=;
for(int i=;i<=n;++i)
b[++m]=arr[i].x;
sort(b+,b++m);
m=unique(b+,b++m)-b-;
for(int i=;i<=n;++i)
arr[i].x=lower_bound(b+,b++m,arr[i].x)-b;
return m;
}
int LSy(int n)
{
int m=;
for(int i=;i<=n;++i)
b[++m]=arr[i].y;
sort(b+,b++m);
m=unique(b+,b++m)-b-;
for(int i=;i<=n;++i)
arr[i].y=lower_bound(b+,b++m,arr[i].y)-b;
return m;
}
//===========================================连续子段线段树;
struct node
{
long long Sum,Lsum,Rsum,ans;
}tr[N<<]; void up(int rt)
{
tr[rt].Sum=tr[ls].Sum+tr[rs].Sum;
tr[rt].ans=max(max(tr[ls].ans,tr[rs].ans),tr[ls].Rsum+tr[rs].Lsum);
tr[rt].Lsum=max(tr[ls].Lsum,tr[ls].Sum+tr[rs].Lsum);
tr[rt].Rsum=max(tr[rs].Rsum,tr[rs].Sum+tr[ls].Rsum);
}
void Build(int l,int r,int rt)
{
if(l==r)
{
tr[rt].Sum=tr[rt].Lsum=tr[rt].Rsum=tr[rt].ans=;
return;
}
int mid=(l+r)>>;
Build(l,mid,ls);
Build(mid+,r,rs);
up(rt);
}
void update_dot(int pos,long long v,int l,int r,int rt)
{
if(l==r)
{
tr[rt].Sum+=v;
tr[rt].Lsum=tr[rt].Rsum=tr[rt].ans=tr[rt].Sum;
return;
}
int mid=(l+r)>>;
if(pos<=mid)
update_dot(pos,v,l,mid,ls);
else
update_dot(pos,v,mid+,r,rs);
up(rt);
}
vector<vector<vnode> >v(N); int main()
{
int T;
sc("%d",&T);
while(T--)
{
int n;
sc("%d",&n);
for(int i=;i<=n;++i)
sc("%d%d%lld",&arr[i].x,&arr[i].y,&arr[i].v);
int L=LSx(n);
int H=LSy(n);
fo(i,,H)v[i].clear();
for(int i=;i<=n;++i)
v[arr[i].y].push_back({arr[i].x,arr[i].v});
long long ans=;
for(int i=H;i>=;--i)
{
Build(,L,);
for(int j=i;j>=;--j)
{
int sz=v[j].size();
for(int k=;k<sz;++k)
{
vnode t=v[j][k];
update_dot(t.x,t.v,,L,);
}
ans=max(ans,tr[].ans);//每增加一层就更新答案;
}
}
pr("%lld\n",ans);
}
return ;
} /**************************************************************************************/ int maxx(int arr,int b)
{
return arr>b?arr:b;
} void swapp(int &arr,int &b)
{
arr^=b^=arr^=b;
} int lowbit(int n)
{
return n&(-n);
} int Del_bit_1(int n)
{
return n&(n-);
} int abss(int arr)
{
return arr>?arr:-arr;
} double fabss(double arr)
{
return arr>?arr:-arr;
} int minn(int arr,int b)
{
return arr<b?arr:b;
}

最大矩阵覆盖权值--(静态连续最大子段 (线段树) )-HDU(6638)Snowy Smile的更多相关文章

  1. HDU 6464 权值线段树 && HDU 6468 思维题

    免费送气球 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submi ...

  2. 区间第k大问题 权值线段树 hdu 5249

    先说下权值线段树的概念吧 权值平均树 就是指区间维护值为这个区间内点出现次数和的线段树 用这个加权线段树 解决第k大问题就很方便了 int query(int l,int r,int rt,int k ...

  3. Codeforces 527C Glass Carving (最长连续0变形+线段树)

    Leonid wants to become a glass carver (the person who creates beautiful artworks by cutting the glas ...

  4. HDU1255 覆盖的面积 —— 求矩形交面积 线段树 + 扫描线 + 离散化

    题目链接:https://vjudge.net/problem/HDU-1255 给定平面上若干矩形,求出被这些矩形覆盖过至少两次的区域的面积. Input输入数据的第一行是一个正整数T(1<= ...

  5. POJ 3264:Balanced Lineup(区间最值查询ST表&线段树)

      Balanced Lineup Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 75294   Accepted: 344 ...

  6. LA 3938 动态最大连续和(线段树)

    https://vjudge.net/problem/UVALive-3938 题意:给出一个长度为n的整数序列D,你的任务是对m个询问作出回答.对于询问(a,b),需要找到两个下标x和y,使得a≤x ...

  7. codedecision P1112 区间连续段 题解 线段树

    题目描述:https://www.cnblogs.com/problems/p/P1112.html 题目链接:http://codedecision.com/problem/1112 线段树区间操作 ...

  8. 区间连续长度的线段树——洛谷P2894 [USACO08FEB]酒店Hotel

    https://www.luogu.org/problem/P2894 #include<cstdio> #include<iostream> using namespace ...

  9. 权值线段树&&可持久化线段树&&主席树

    权值线段树 顾名思义,就是以权值为下标建立的线段树. 现在让我们来考虑考虑上面那句话的产生的三个小问题: 1. 如果说权值作为下标了,那这颗线段树里存什么呢? ----- 这颗线段树中, 记录每个值出 ...

随机推荐

  1. Fire Game (FZU 2150)(BFS)

    题解:一开始想错了,以为只要烧完就是那个答案,但是这不是最优的结果,需要每两个点都bfs一遍,找到如果能够全部烧完,找到花费时间最小的,如果不能return -1.在bfs的时候,记录答案的方法参考了 ...

  2. 7.6 T1 深度优先搜索(dfs)

    深度优先搜索(dfs) [题目描述] sol:50pts随便写写,就是大众分了,直接n2dpOK,100分要找点规律,需要数学头脑 官方题解 //#include <bits/stdc++.h& ...

  3. JavaWeb-SpringSecurity记住我功能

    系列博文 项目已上传至guthub 传送门 JavaWeb-SpringSecurity初认识 传送门 JavaWeb-SpringSecurity在数据库中查询登陆用户 传送门 JavaWeb-Sp ...

  4. JavaWeb-SpringSecurity图片验证ImageCode

    系列博文 项目已上传至guthub 传送门 JavaWeb-SpringSecurity初认识 传送门 JavaWeb-SpringSecurity在数据库中查询登陆用户 传送门 JavaWeb-Sp ...

  5. iPhone 6 Plus 分辨率问题

    苹果官方开发者文档说iPhone6的分辨率是1920x1080的,但是在xcode6下用函数 [[UIScreen mainScreen] currentMode].size 打印出来的是{750, ...

  6. Caused by: java.lang.IllegalStateException: Unable to complete the scan for annotations for web application [/Cppcc] due to a StackOverflowError. Possible root causes include a too low setting for -Xs

    解决办法:(1)修改D:\Java\apache-tomcat-7.0.88\conf\catalina.properties (122line) (2)如org.apache.catalina.st ...

  7. TCP输入 之 tcp_prequeue

    在未开启tcp_low_latency的情况下,软中断将skb送上来,加入到prequeue中,然后 在未启用tcp_low_latency且有用户进程在读取数据的情况下,skb入队到prequeue ...

  8. Python中列表操作进阶及元组

    列表高级操作 一.遍历列表 >>> ls=['a','d','it'] >>> for val in ls: ... print (val) ... a d it ...

  9. 2019-8-13未命名文件 sdfsdfsdfsdfsdfsdf

    2019-8-13未命名文件 sdfsdfsdfsdfsdfsdf 新建模板小书匠 欢迎使用 小书匠(xiaoshujiang)编辑器,您可以通过 小书匠主按钮>模板 里的模板管理来改变新建文章 ...

  10. ServiceStatusUtils判断服务是否运行

    import android.app.ActivityManager; import android.app.Service; import android.content.Context; impo ...