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)项和都是正的,那么这个数列是正的,问这个 ...
随机推荐
- apache(XAMPP)禁止IP访问的httpd-vhosts.conf设置
httpd-vhosts.conf <virtualhost *:80> ServerName 123.123.123.123 ServerAlias 123.123.123.123 ...
- Object-C,循环语句for,while,do-while
演示循环语句,for,while,do-while,和C系列的语言,语法基本一致1到10,求和 // // main.m // for-while // // Created by fansunion ...
- STM32中断名词
1.NVIC的优先级概念 占先式优先级 (pre-emption priority): 高占先式优先级的中断事件会打断当前的主程序/中断程序运行— —抢断式优先响应,俗称中断嵌套. ...
- Java基础学习总结(29)——浅谈Java中的Set、List、Map的区别
就学习经验,浅谈Java中的Set,List,Map的区别,对JAVA的集合的理解是想对于数组: 数组是大小固定的,并且同一个数组只能存放类型一样的数据(基本类型/引用类型),JAVA集合可以存储和操 ...
- ECNUOJ 2615 会议安排
会议安排 Time Limit:1000MS Memory Limit:65536KB Total Submit:451 Accepted:102 Description 科研人员与相关领域的国内外同 ...
- LDAP实现企业异构平台的统一认证
LDAP实现企业异构平台的统一认证 技术是为应用服务的,没有应用,技术就无用武之地.同样光配置完LDAP服务器没有任何意义,只有把所有需要认证的环节,只有纳入LDAP系统中,才能使它发挥应有 ...
- Sql Server通用分页存储过程
Sql Server2005通用分页存储过程 CREATE PROCEDURE [dbo].[Common_GetPagedList] ( @TableName nvarchar(100), --表名 ...
- sql中使用正则查询
- 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 (B,F,L,M)
B. Train Seats Reservation You are given a list of train stations, say from the station 1 to the sta ...
- SQL传数组到存储过程中
方法一 CREATE PROC D_t_Base_Employee @str varchar(100) as declare @sql varchar(1000) set @sql='DELETE E ...