这题是杭电多校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. 阿sa

    # jieba库概述 .jieba是优秀的中文分词第三方库.需要额外安装. pip install jieba # jieba库三种分词模式 精确模式:把文本精确的切分开,不存在冗余单词. 全模式:把 ...

  2. Spring——顾问封装通知

    通知(advice)是Spring中的一种比较简单的切面,只能将切面织入到目标类的所有方法中,而无法对指定方法进行增强 顾问(advisor)是Spring提供的另外一种切面,可以织入到指定的方法中  ...

  3. [题解] [bzoj2622] 深入虎穴

    题解 题解 考虑到正着跑不好想, 我们尝试反向跑 以每个终点作为起点, 维护每个点的最小值和次小值(最小的被老虎ban掉了) 转移的时候用当前点的次小值去更新其所连的点的最小值和次小值 由于最小的次小 ...

  4. C与C++ 中 struct和typedef struct

    总体分两块 1 首先://注意在C和C++里不同在C中定义一个结构体类型要用typedef: typedef struct Student { int a; }Stu; 于是在声明变量的时候就可:St ...

  5. 认识git的简单命令

    一.课程目的 教大家学会it的简单命令(老师建议 English 的前后要加空格) 二.认识 git 命令 整篇文章都是用语雀写的. 解释了(使用git)绑定gitee的操作 https://www. ...

  6. 爬取百度网盘资源报user is not authorized, hitcode:119

    爬取百度网盘资源报user is not authorized, hitcode:119 一.总结 一句话总结: 可能是百度网盘禁止非客户端环境下载大文件,所以将请求头改为客户端:'User-Agen ...

  7. Oracle12C SGA PGA UGA

    SGA和PGA简介 1 sga组成: 2b4p1s(记忆) database buffer cache:包括 default pool,keep pool,recycle pool: redo log ...

  8. rocketmq的以集群模式MessageModel.CLUSTERING实现消费者集群消费消息,实现负载均衡

    package com.bfxy.rocketmq.model; import java.util.List; import org.apache.rocketmq.client.consumer.D ...

  9. nginx环境准备

    一.环境调试确认 1.四项确认 确认公网已连通. 确认yum源可用. 确认iptables已经关闭. 确认selinux已经关闭. a.确认是否连通公网. ping www.baidu.com b.确 ...

  10. 在smarty模板中截取指定长度的字符串

    在smarty模板中截取指定长度的字符串,可使用truncate这个插件. 用法: {{$data.value|truncate:28:'...'}} 28个字节14个字数输出,多余部分输出...,一 ...