51nod 1611 金牌赛事
被亮亮D飞啦!!QWQ
这题明明是最大权闭合子图+线段树优化构图好不好
被迫考虑DP,并且考虑f[i]表示到第i个位置的最大值(第i个位置可选可不选)
对于最终的答案,我们可以分割成一段一段的,也就是多段区间
枚举这个断点,断点以后的全选,前面的就通过继承得到,f[i]=f[j]-(sc[i]-sc[j])+(j+1到i这个区间中可以承办的比赛的价值和)
用数据结构优化的话,前面就可以nlogn了
而后面这一个,我们可以弄一个指针扫区间,看看当前是不是已经完全覆盖了,然后选取区间起始到这个区间的左界-1作为决策,后面的价值和就会加上这个区间的价值
区间修改也是线段树搞
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL; struct node
{
int l,r,lc,rc;LL c,lazy;
}tr[];int trlen;
void bt(int l,int r)
{
int now=++trlen;
tr[now].l=l;tr[now].r=r;
tr[now].lc=tr[now].rc=-;
tr[now].c=;tr[now].lazy=;
if(l<r)
{
int mid=(l+r)/;
tr[now].lc=trlen+;bt(l,mid);
tr[now].rc=trlen+;bt(mid+,r);
}
}
void change(int now,int l,int r,LL k)
{
if(tr[now].l==l&&tr[now].r==r)
{
tr[now].c+=k;tr[now].lazy+=k;
return ;
} int mid=(tr[now].l+tr[now].r)/;
int lc=tr[now].lc,rc=tr[now].rc; if(tr[now].lazy!=)
{
tr[lc].c+=tr[now].lazy;
tr[rc].c+=tr[now].lazy;
tr[lc].lazy+=tr[now].lazy;
tr[rc].lazy+=tr[now].lazy;
tr[now].lazy=;
} if(r<=mid) change(lc,l,r,k);
else if(mid+<=l)change(rc,l,r,k);
else change(lc,l,mid,k),change(rc,mid+,r,k);
tr[now].c=max(tr[lc].c,tr[rc].c);
}
LL getmax(int now,int l,int r)
{
if(tr[now].l==l&&tr[now].r==r)return tr[now].c; int mid=(tr[now].l+tr[now].r)/;
int lc=tr[now].lc,rc=tr[now].rc; if(tr[now].lazy!=)
{
tr[lc].c+=tr[now].lazy;
tr[rc].c+=tr[now].lazy;
tr[lc].lazy+=tr[now].lazy;
tr[rc].lazy+=tr[now].lazy;
} if(r<=mid) return getmax(lc,l,r);
else if(mid+<=l)return getmax(rc,l,r);
else return max(getmax(lc,l,mid),getmax(rc,mid+,r));
} LL sc[];
struct game{int l,r;LL v;}g[];
bool cmp(game g1,game g2){return g1.r==g2.r?g1.l<g2.l:g1.r<g2.r;}
LL f[];
int main()
{
int n,m;
scanf("%d%d",&n,&m);sc[]=;
for(int i=;i<=n;i++)
scanf("%lld",&sc[i]), sc[i]+=sc[i-];
g[].r=;
for(int i=;i<=m;i++)
scanf("%d%d%lld",&g[i].l,&g[i].r,&g[i].v);
sort(g+,g+m+,cmp); trlen=;bt(,n);
f[]=;
for(int i=,j=;i<=n;i++)
{
while(j<=m&&g[j].r<=i)change(,,g[j].l-,g[j].v),j++;
f[i]=max(f[i-],getmax(,,i-)-sc[i]);
change(,i,i,f[i]+sc[i]);
}
printf("%lld\n",f[n]);
return ;
}
51nod 1611 金牌赛事的更多相关文章
- NOIP2018提高组金牌训练营——动态规划专题
NOIP2018提高组金牌训练营——动态规划专题 https://www.51nod.com/Live/LiveDescription.html#!#liveId=19 多重背包 二进制优化转化成01 ...
- NOIP2018提高组金牌训练营——字符串专题
NOIP2018提高组金牌训练营——字符串专题 1154 回文串划分 有一个字符串S,求S最少可以被划分为多少个回文串. 例如:abbaabaa,有多种划分方式. a|bb|aabaa - 3 个 ...
- 【51Nod 1244】莫比乌斯函数之和
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1244 模板题... 杜教筛和基于质因子分解的筛法都写了一下模板. 杜教筛 ...
- 51Nod 1268 和为K的组合
51Nod 1268 和为K的组合 1268 和为K的组合 基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题 给出N个正整数组成的数组A,求能否从中选出若干个,使 ...
- 51Nod 1428 活动安排问题
51Nod 1428 活动安排问题 Link: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1428 1428 活 ...
- 51Nod 1278 相离的圆
51Nod 1278 相离的圆 Link: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1278 1278 相离的圆 基 ...
- .NET足球赛事资料数据库平台SmartLottery开源发布——全球足球联赛应有尽有
本博客所有文章分类的总目录:[总目录]本博客博文总目录-实时更新 开源C#彩票数据资料库系列文章总目录:[目录]C#搭建足球赛事资料库与预测平台与彩票数据分析目录 前2个月,我的系列文 ...
- Autodesk正在招聘Civil、Infraworks金牌支持工程师(Premium Support Specialist)
Civil Infraworks金牌支持工程师,也不知道中文这么翻对不对,反正很牛的,地点优选上海,不过其他地区也没问题啊,感兴趣的,赶紧扔简历过来,我当你内线,帮你内推 :) Autodesk是全球 ...
- 【51Nod 1501】【算法马拉松 19D】石头剪刀布威力加强版
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1501 dp求出环状不连续的前缀和,剩下东西都可以算出来,比较繁琐. 时间 ...
随机推荐
- MFC_2.8 使用状态栏工具栏
使用状态栏工具栏 1.资源-添加-TOOLBAR 画图标.画了一个,第二个会出来. 2.头文件添加成员 CToolBar m_ToolBar; CStatusBar m_StatusBar; 3.初始 ...
- 如何在mybatis中引用java中的常量和方法
转自:http://www.68idc.cn/help/jiabenmake/qita/20140821125261.html 在mybatis的映射xml文件调用java类的方法: 1. SELEC ...
- 在添加新内容时,creatat没有数据
首先找到controller中的add方法,然后是执行了Service.insert()方法 然后找到service对应的impl方法, impl方法中的 public void insert(Cus ...
- moongoTemplate使用
添加依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifact ...
- 07Html、CSS
07Html.CSS-2018/07/17 1.HTML是用来描述网页的一种标记语言,是一套标记标签.HTML用使用标记标签来描述网页.超文本 标记语言. 2.格式 <html> < ...
- java学习日志---File实例:实现复制整个文件夹、解决listFiles()为null问题
需求:将H盘下的所有文件复制到H:/All 文件夹中 思路:使用递归遍历整个目标目录 传入目标路径 判断是否是文件夹 是:调用listFiles()方法,得到File数组,重点内容接着执行1 否:复制 ...
- Qt 给QWidget添加工具栏
在Qt中,给主窗口(QMainWindow类)添加工具栏非常方便,直接使用addToolBar 即可,如下所示: fileToolBar = addToolBar(tr("&File ...
- UVA-1368 DNA Consensus String(思路)
题目: 链接 题意: 题目虽然比较长,但读完之后题目的思路还是比较容易想出来的. 给出m个长度为n的字符串(只包含‘A’.‘T’.‘G’.‘C’),我们的任务是得出一个字符串,要求这个字符串与给出的m ...
- CSC
CSC CSC Table of Contents 1. account 2. Contacts 3. <国家公派留学人员预订回国机票说明> 4. 回国手续 4.1. 申办及开具<留 ...
- Codeforces Round #232 (Div. 2) On Sum of Fractions
Let's assume that v(n) is the largest prime number, that does not exceed n; u(n) is the smallest pri ...