Problem 1608 Huge Mission

Time Limit: 1000 mSec    Memory Limit : 32768 KB

Problem Description

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
 
 #include <cstdio>
#include <algorithm>
using namespace std; #define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define root 1,N,1
const int maxn=;
int col[maxn<<]; void PushDown(int rt)//向下更新
{
if(col[rt])
{
int ls=rt<<;
int rs=ls+;
col[ls]=max(col[ls],col[rt]);
col[rs]=max(col[rs],col[rt]);
col[rt]=;
}
} void build(int l,int r,int rt)
{
col[rt]=;
if(l==r) return ;
int m=(l+r)>>;
build(lson);
build(rson);
} void update(int L,int R,int c,int l,int r,int rt)
{
if(L<=l&&R>=r)
{
col[rt]=max(col[rt],c);
return ;
}
PushDown(rt);//down
int m=(l+r)>>;
if(L<=m)
update(L,R,c,lson);
if(R>m)
update(L,R,c,rson);
} int get_ans(int l,int r,int rt)
{
if(l==r) return col[rt];
PushDown(rt);
int m=(l+r)>>;
return get_ans(lson)+get_ans(rson);
} int solve()
{
int N,M;
while(~scanf("%d%d",&N,&M))
{
build(root);
while(M--)
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
if(c) update(a+,b,c,root);
}
printf("%d\n",get_ans(root));
}
return ;
} int main()
{
return solve();
}

FZU 1608 Huge Mission(线段树)的更多相关文章

  1. FOJ 1608 Huge Mission 线段树

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

  2. FZU 1608 Huge Mission

    Huge Mission Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on FZU. Original I ...

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

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

  4. FZU 2105 Digits Count(线段树)

    Problem 2105 Digits Count Accept: 302 Submit: 1477 Time Limit: 10000 mSec Memory Limit : 262144 KB P ...

  5. fzu 2105 Digits Count ( 线段树 ) from 第三届福建省大学生程序设计竞赛

    http://acm.fzu.edu.cn/problem.php?pid=2105 Problem Description Given N integers A={A[0],A[1],...,A[N ...

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

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

  7. ACM: FZU 2105 Digits Count - 位运算的线段树【黑科技福利】

     FZU 2105  Digits Count Time Limit:10000MS     Memory Limit:262144KB     64bit IO Format:%I64d & ...

  8. F - Change FZU - 2277 (DFS序+线段树)

    题目链接: F - Change FZU - 2277 题目大意: 题意: 给定一棵根为1, n个结点的树. 有q个操作,有两种不同的操作 (1) 1 v k x : a[v] += x, a[v ' ...

  9. FZU 2105 Digits Count(按位维护线段树)

    [题目链接] http://acm.fzu.edu.cn/problem.php?pid=2105 [题目大意] 给出一个序列,数字均小于16,为正数,每次区间操作可以使得 1. [l,r]区间and ...

随机推荐

  1. 重构第8天:使用委托代替继承(Replace Inheritance with Delegation)

    理解:根本没有父子关系的类中使用继承是不合理的,可以用委派的方式来代替. 详解:我们经常在错误的场景使用继承.继承应该在仅仅有逻辑关系的环境中使用,而很多情况下却被使用在达到方便为目的的环境中. 看下 ...

  2. .net中以传引用的方式 向方法中传参数

    CLR(CommonLanguageRuntime)公共语言运行时,允许以传引用而非传值的方式传递参数.在C#中,这是用关键字 out 和ref来做到的. 从CLR角度来看,这两个关键字没什么区别,生 ...

  3. 在C#后端处理一些结果然传给前端Javascript或是jQuery

    在C#后端处理一些结果然传给前端Javascript或是jQuery,以前Insus.NET有做过一个例子<把CS值传给JS使用 >http://www.cnblogs.com/insus ...

  4. wpf 下面用MVVC的RelayCommand命令引发的一个异常

    具体解决方法参见我的博问:https://q.cnblogs.com/list/myquestion

  5. bootstrap glyphicon图标无法显示

    如果不注意bootstrap引入css和fonts的规范,则可能会导致bootstrap 在显示glyphicon图标时无法正常显示,显示为方框. 此时可搜索bootstrap.css中的.glyph ...

  6. 操作iframe

    iframe是在页面中嵌套的子页,当前页面(这里称为父页)和嵌套页面(这里称为子页)可以相互控制: 当父页控制子页用contentWindow,用法为 对象.contentWindow.documen ...

  7. EntityFramework嵌套查询的五种方法

    这样的双where的语句应该怎么写呢: var test=MyList.Where(a => a.Flows.Where(b => b.CurrentUser == “”) 下面我就说说这 ...

  8. 基于MATLAB实现的云模型计算隶属度

    ”云”或者’云滴‘是云模型的基本单元,所谓云是指在其论域上的一个分布,可以用联合概率的形式(x, u)来表示 云模型用三个数据来表示其特征 期望:云滴在论域空间分布的期望,一般用符号Εx表示. 熵:不 ...

  9. Sharepoint学习笔记—习题系列--70-573习题解析 -(Q104-Q106)

    Question 104You plan to create a workflow that has the following three activities: CreateTask OnTask ...

  10. Android自动更新安装后显示‘完成’‘打开’按钮

    /** * 安装apk * * @param url */ private void installApk() { File apkfile = new File(apkFilePath); if ( ...