这题是杭电多校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. java中如何根据函数查询引用的jar包

    选中函数,按Ctrl+Shift+T,就可以弹出对应的jar包地址 例如:

  2. React 的 DOM 添加多个点击事件

    第一直觉代码如下:后果是写在后面的事件函数覆盖前面的事件函数,只执行第二条(弹出 222). import React, { Component, Fragment } from 'react' ex ...

  3. js判断是否是app,及版本号

    判断是否是android,ios,qq,wetchat export const Config = {}; Config.ua = navigator.userAgent.toLowerCase(); ...

  4. JavaWeb_ Servlet API(中文)

       Java Servlet 中文API Java Servlet API由两个软件包组成:一个是对应HTTP的软件包,另一个是不对应HTTP的通用的软件包.这两个软件包的同时存在使得Java Se ...

  5. ARTS打卡计划第一周

    Algorithms: https://leetcode-cn.com/problems/two-sum/ Review: https://www.infoq.cn/article/EafgGJEtq ...

  6. 【Python】模块学习之locust性能测试

    背景 locust是一个python的第三方库,用于做性能测试,可使用多台机器同时对一台服务器进行压测,使用其中一台机器作为主节点,进行分布式管理 博主测试接口的时候一直是使用python脚本,后来有 ...

  7. 理解MVC/MVP/MVVM的区别

    转载至[http://www.ruanyifeng.com/blog/2015/02/mvcmvp_mvvm.html] MVC 所有的通信都是单向的. M(Model)V(View)C(Contro ...

  8. spring 过滤器- 过滤登陆请求路径(过滤静态资源跳转到登陆页面)

    public class LoginedFilter implements Filter { /** * 排除的地址 */ private Map<String, Boolean> ign ...

  9. H3C 模拟器 防火墙开启Web功能

    最近在搞运维的一些事情,由于缺少实体的机器来进行操作,先在模拟器里面进行 环境 windows 10,模拟器 HCL_V2.1.1 防火墙 1 在windows添加虚拟网卡 我的电脑--管理--设备管 ...

  10. 强大的BeautifulSoup

    Beautiful Soup 是一个可以从HTML或XML文件中提取数据的Python库·它能够通过你喜欢的转换器实现惯用的文档导航 安装BeautifulSoup 推荐使用Beautiful Sou ...