Huge Mission

Time Limit: 1000ms
Memory Limit: 32768KB

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的更多相关文章

  1. FZU 1608 Huge Mission(线段树)

    Problem 1608 Huge Mission Time Limit: 1000 mSec    Memory Limit : 32768 KB Problem Description Oaiei ...

  2. FOJ 1608 Huge Mission 线段树

    每个节点维护一个最小值,更新发现如果大于最小值,直接向下更新.速度还可以.. #include<cstdio> #include<algorithm> #include< ...

  3. Huge Mission

    Huge Mission Problem Description Oaiei is busy working with his graduation design recently. If he ca ...

  4. FZU_1608 Huge Mission 【线段树区间更新】

    一.题目 Huge Mission 二.分析 区间更新,用线段树的懒标记即可.需要注意的时,由于是在最后才查询的,没有必要每次更新都对$sum$进行求和.还有一点就是初始化的问题,一定记得线段树上每个 ...

  5. FZU-1608 Huge Mission 线段树(更新懒惰标记)

    题目链接: https://cn.vjudge.net/problem/FZU-1608 题目大意: 长度n,m次操作:每次操作都有三个数:a,b,c:意味着(a,b]区间单位长度的价值为c,若某段长 ...

  6. FZU1608(线段树)

    传送门:Huge Mission 题意:给定区间范围[0,N] (2 <= N <= 50000)和M个区间 (1 <= M <= 500000)和这些区间上的权值,求最终并区 ...

  7. Java 性能分析工具 , 第 3 部分: Java Mission Control

    引言 本文为 Java 性能分析工具系列文章第三篇,这里将介绍如何使用 Java 任务控制器 Java Mission Control 深入分析 Java 应用程序的性能,为程序开发人员在使用 Jav ...

  8. FZU 2137 奇异字符串 后缀树组+RMQ

    题目连接:http://acm.fzu.edu.cn/problem.php?pid=2137 题解: 枚举x位置,向左右延伸计算答案 如何计算答案:对字符串建立SA,那么对于想双延伸的长度L,假如有 ...

  9. FZU 1914 单调队列

    题目链接:http://acm.fzu.edu.cn/problem.php?pid=1914 题意: 给出一个数列,如果它的前i(1<=i<=n)项和都是正的,那么这个数列是正的,问这个 ...

随机推荐

  1. POJ2976 Dropping tests(01分数规划)

    题意 给你n次测试的得分情况b[i]代表第i次测试的总分,a[i]代表实际得分. 你可以取消k次测试,得剩下的测试中的分数为 问分数的最大值为多少. 题解 裸的01规划. 然后ans没有清0坑我半天. ...

  2. echarts 绑定事件重复执行问题。

    网上所有,先调用.off 方法后再调用.on 绑定事件. 无效果,查看api未发现off方法,于是采用,先删除原先元素,后重新生成的方式. 场景描述. 用户查询时,每次结果都对应一张饼图.该张饼图绑定 ...

  3. PKU 2528 Mayor's posters

    题意: 一个公告板上面贴海报,宽度都是一样的,长度可能不一样.后面的海报可能把前面的覆盖掉.问最后能看见多少张不同的海报. 思路: 这题原来做过,是用线段树的区间染色写的.记录每个区间是纯色还是杂色. ...

  4. ECNUOJ 2147 字符环

    字符环 Time Limit:1000MS Memory Limit:65536KBTotal Submit:562 Accepted:146 Description  字符环:就是将给定的一个字符串 ...

  5. 坑爹的RockSaw和坑爹的windows7

    坑爹的RockSaw和坑爹的windows7 http://chen4w.iteye.com/blog/1153433

  6. HDOJ 2544 最短路(最短路径 dijkstra算法,SPFA邻接表实现,floyd算法)

    最短路 Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submis ...

  7. vim基础学习之EX命令

    :tabnew -创建新标签 :split(sp)-垂直分割窗口 如果没有打开新的文件,那么会打开原来窗口的文件 :vsplit(vsp)-水平分割窗口 如果没有打开新的文件,那么会打开原来窗口的文件 ...

  8. 直播聊天室,点亮效果,jquery实现

    1.css #like_area img{ width: 30px; height: 30px; position: absolute; bottom: 100px; left: 60%; margi ...

  9. Entity Framework之Model First开发方式

    一.Model First开发方式 在项目一开始,就没用数据库时,可以借助EF设计模型,然后根据模型同步完成数据库中表的创建,这就是Model First开发方式.总结一点就是,现有模型再有表. 二. ...

  10. POJ 1986 裸的LCA

    思路:搞了一发链剖 //By SiriusRen #include <cstdio> #include <cstring> #include <algorithm> ...