FZU 1608 Huge Mission
Huge Mission
This problem will be judged on FZU. Original ID: 1608
64-bit integer IO format: %I64d Java class name: Main
Oaiei is busy working with his graduation design recently. If he can not complete it before the end of the month, and he can not graduate! He will be very sad with that, and he needs your help. There are 24 hours a day, oaiei has different efficiency in different time periods, such as from 0 o’clock to 8 o'clock his working efficiency is one unit per hour, 8 o'clock to 12 o'clock his working efficiency is ten units per hour, from 12 o'clock to 20 o'clock his working efficiency is eight units per hour, from 20 o'clock to 24 o'clock his working efficiency is 5 units per hour. Given you oaiei’s working efficiency in M periods of time and the total time N he has, can you help him calculate his greatest working efficiency in time N.
Input
There are multiple tests. In each test the first line has two integer N (2 <= N <= 50000) and M (1 <= M <= 500000), N is the length of oaiei’s working hours; M is the number of periods of time. The following M lines, each line has three integer S, T, P (S < T, 0 < P <= 200), represent in the period of time from S to T oaiei’s working efficiency is P units per hour. If we do not give oaiei’s working efficiency in some periods of time, his working efficiency is zero. Oaiei can choose part of the most effective periods of time to replace the less effective periods of time. For example, from 5 o’clock to 10 o’clock his working efficiency is three units per hour and from 1 o’clock to 7 o’clock his working efficiency is five units per hour, he can choose working with five units per hour from 1 o’clocks to 7 o’clock and working with three units per hour from 7 o’clock to 10 o’clock.
Output
You should output an integer A, which is oaiei’s greatest working efficiency in the period of time from 0 to N.
Sample Input
24 4
0 8 1
8 12 10
12 20 8
20 24 5
4 3
0 3 1
1 2 2
2 4 5
10 10
8 9 15
1 7 5
5 10 3
0 7 6
5 8 2
3 7 3
2 9 12
7 8 14
6 7 2
5 6 16
Sample Output
132
13
108
Source
#include <iostream>
#include <cstdio>
using namespace std;
const int maxn = ;
struct node{
int lt,rt,sum,val,maxV;
}tree[maxn<<];
void build(int lt,int rt,int v){
tree[v].lt = lt;
tree[v].rt = rt;
tree[v].sum = tree[v].val = tree[v].maxV = ;
if(lt + == rt) return;
int mid = (lt + rt)>>;
build(lt,mid,v<<);
build(mid,rt,v<<|);
}
void pushdown(int v){
tree[v<<].val = tree[v<<|].val = tree[v].val;
tree[v<<].maxV = tree[v<<|].maxV = tree[v].val;
tree[v<<].sum = tree[v].val*(tree[v<<].rt - tree[v<<].lt);
tree[v<<|].sum = tree[v].val*(tree[v<<|].rt - tree[v<<|].lt);
}
void pushup(int v){
if(tree[v<<].val == tree[v<<|].val) tree[v].val = tree[v<<].val;
else tree[v].val = -;
tree[v].sum = tree[v<<].sum + tree[v<<|].sum;
tree[v].maxV = max(tree[v<<].maxV,tree[v<<|].maxV);
}
void update(int lt,int rt,int val,int v){
if(val <= tree[v].val) return;//纯色
if(lt <= tree[v].lt && tree[v].rt <= rt &&(tree[v].val >= || tree[v].maxV < val)){
tree[v].val = val;
tree[v].maxV = val;
tree[v].sum = val*(tree[v].rt - tree[v].lt);
return;
}
if(tree[v].val > ) pushdown(v);
if(lt < tree[v<<].rt) update(lt,rt,val,v<<);
if(rt > tree[v<<|].lt) update(lt,rt,val,v<<|);
pushup(v);
}
int main(){
int n,m,s,t,p;
while(~scanf("%d %d",&n,&m)){
build(,n,);
while(m--){
scanf("%d %d %d",&s,&t,&p);
update(s,t,p,);
}
printf("%d\n",tree[].sum);
}
return ;
}
FZU 1608 Huge Mission的更多相关文章
- FZU 1608 Huge Mission(线段树)
Problem 1608 Huge Mission Time Limit: 1000 mSec Memory Limit : 32768 KB Problem Description Oaiei ...
- FOJ 1608 Huge Mission 线段树
每个节点维护一个最小值,更新发现如果大于最小值,直接向下更新.速度还可以.. #include<cstdio> #include<algorithm> #include< ...
- Huge Mission
Huge Mission Problem Description Oaiei is busy working with his graduation design recently. If he ca ...
- FZU_1608 Huge Mission 【线段树区间更新】
一.题目 Huge Mission 二.分析 区间更新,用线段树的懒标记即可.需要注意的时,由于是在最后才查询的,没有必要每次更新都对$sum$进行求和.还有一点就是初始化的问题,一定记得线段树上每个 ...
- FZU-1608 Huge Mission 线段树(更新懒惰标记)
题目链接: https://cn.vjudge.net/problem/FZU-1608 题目大意: 长度n,m次操作:每次操作都有三个数:a,b,c:意味着(a,b]区间单位长度的价值为c,若某段长 ...
- FZU1608(线段树)
传送门:Huge Mission 题意:给定区间范围[0,N] (2 <= N <= 50000)和M个区间 (1 <= M <= 500000)和这些区间上的权值,求最终并区 ...
- Java 性能分析工具 , 第 3 部分: Java Mission Control
引言 本文为 Java 性能分析工具系列文章第三篇,这里将介绍如何使用 Java 任务控制器 Java Mission Control 深入分析 Java 应用程序的性能,为程序开发人员在使用 Jav ...
- FZU 2137 奇异字符串 后缀树组+RMQ
题目连接:http://acm.fzu.edu.cn/problem.php?pid=2137 题解: 枚举x位置,向左右延伸计算答案 如何计算答案:对字符串建立SA,那么对于想双延伸的长度L,假如有 ...
- FZU 1914 单调队列
题目链接:http://acm.fzu.edu.cn/problem.php?pid=1914 题意: 给出一个数列,如果它的前i(1<=i<=n)项和都是正的,那么这个数列是正的,问这个 ...
随机推荐
- Mysql 主从主主复制总结(详细)
环境:Centos 6.9,Mysql 8.0 配置准备:1.为Centos配置好网络,使用远程工具连接. 2.安装mysql,途径不限.mysql8.0和5.7区别不大,8.0在配置主从的时候默认开 ...
- JS由Number与new Number的区别引发的思考
在回答园子问题的时候发现了不少新东西,写下来分享一下 == 下面的图就是此篇的概览,另外文章的解释不包括ES6新增的Symbol,话说这货有包装类型,但是不能new... 基于JS是面向对象的,所以我 ...
- 【APP自动化】Appium Android 元素定位方法 原生+H5
参考资料: http://blog.csdn.net/vivian_ljx/article/details/54410024
- 如何解决本地仓库和远程仓库的冲突(Conflict)
Background: 我有一个github仓库管理我的代码,我将这个仓库的代码clone到我的工作电脑和私人电脑本地方便我上班和在家时都可以对我的代码进行更新. 一天,我在家修改过代码之后并未提交, ...
- POJ——T 1470 Closest Common Ancestors
http://poj.org/problem?id=1470 Time Limit: 2000MS Memory Limit: 10000K Total Submissions: 20830 ...
- SharePoint Search之(五)Query spelling correction— 查询拼写纠正
Query spelling correction 在使用搜索引擎的时候.假设一不小心输入错误,或者对于某个词语记得不太清楚,搜索引擎会自己主动纠正: 这个功能可以缩短用户的时间,很好用.在Sh ...
- [LeetCode]Single Number 异或的妙用
1.数组中仅仅有一个元素仅仅出现一次,其余出现偶数次. 利用异或中同样元素相互抵消的方式求解. 2.数组中仅仅有2个元素仅仅出现一次.其余出现偶数次. class Solution { public: ...
- URAL 1823. Ideal Gas(数学啊 )
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1823 1823. Ideal Gas Time limit: 0.5 second Me ...
- thinkphp跨模块调用
thinkphp跨模块调用 跨模块调用模板 return $view->fetch('admin@user/add'); 全路径模板调用: return $view->fetch(APP_ ...
- 关于在天机项目中遇到的常用git 命令
1. 本地分支和远程分支 1>我们在本地创建分支,第一次push到远程是没有分支存在,执行git push 会有提示,按照提示的内容操作即可,当然我们也可以 git push origin fe ...