这题是杭电多校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. TensorFlow使用记录 (九): 模型保存与恢复

    模型文件 tensorflow 训练保存的模型注意包含两个部分:网络结构和参数值. .meta .meta 文件以 “protocol buffer”格式保存了整个模型的结构图,模型上定义的操作等信息 ...

  2. JavaWeb_(Hibernate框架)Hibernate中对象的三种状态

    对象的三种状态 瞬时状态: 实体 没有id.没有与session关联 持久化状态: 特点:持久化状态对象的任何改变都会同步到数据库中 游离态[也称作托管态]: 实体 有id,没有与session关联 ...

  3. Linux下Weblogic 11g R1安装和配置

    自己留着好好看看! 文章摘自 :http://blog.163.com/ng_0125@126/blog/static/170162360201311773235995/ 1.  安装前 1  确定w ...

  4. linux线程池thrmgr源码解析

    linux线程池thrmgr源码解析 1         thrmgr线程池的作用 thrmgr线程池的作用是提高程序的并发处理能力,在多CPU的服务器上运行程序,可以并发执行多个任务. 2      ...

  5. 从零开始学习Gradle之三---多项目构建

       随着信息化的快速发展,IT项目变得越来越复杂,通常都是由多个子系统共同协作完成.对于这种多系统.多项目的情况,很多构建工具都已经提供了不错的支持,像maven.ant.Gradle除了借鉴了an ...

  6. light4j轻量级微服务应用

    最近对light-4j轻框架比较感兴趣,于是对现有应用做了一次重构,现将其间的一些点滴所得分享出来. 项目打包 pom.xml配置了两个profile:debug支持mvn exec:exec启动应用 ...

  7. js移动端触屏事件

    移动端触屏滑动的效果其实就是图片轮播,在PC的页面上很好实现,绑定click和mouseover等事件来完成.但是在移动设备上,要实现这种轮播的效果,就需要用到核心的touch事件.处理touch事件 ...

  8. 云服务器 ECS 是什么?

    云服务器 Elastic Compute Service(ECS)是阿里云提供的一种基础云计算服务.使用云服务器 ECS 就像使用水.电.煤气等资源一样便捷.高效.您无需提前采购硬件设备,而是根据业务 ...

  9. 三、SpringBoot启动时JDBC报错:You must configure either the server or JDBC driver (via the serverTimezone configuration property)

    错误提示: Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connectio ...

  10. .net中错误日志的写入

    18 public static void SaveError(Exception ex,HttpContext hc,HttpRequest hr)19   {20    string temp ; ...