Huge Mission

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 <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <stdlib.h>
#include <map>
#define ll long long
using namespace std;
typedef struct abcd
{
int x,y,p;
} abcd;
abcd a[];
int b[<<];
bool cmp(abcd x,abcd y)
{
return x.p<y.p;
}
void build(int l,int r,int t)
{
if(l==r)
{
b[t]=;
return ;
}
int m=(l+r)>>;
build(l,m,t<<);
build(m+,r,t<<|);
b[t]=b[t<<]+b[t<<|];
}
void update(int x,int y,int l,int r,int t)
{
if(b[t]==)return;
if(x<=l&&y>=r)
{
b[t]=;
return;
}
int m=(l+r)>>;
if(x<=m)update(x,y,l,m,t<<);
if(y>m)update(x,y,m+,r,t<<|);
b[t]=b[t<<]+b[t<<|];
}
int query(int x,int y,int l,int r,int t)
{
if(b[t]==)return ;
if(x<=l&&y>=r)
{
return b[t];
}
int m=(l+r)>>;
int sum=;
if(x<=m)sum+=query(x,y,l,m,t<<);
if(y>m)sum+=query(x,y,m+,r,t<<|);
return sum;
}
int main()
{
int n,m,i,j;
while(cin>>n>>m)
{
build(,n,);
for(i=; i<m; i++)
{
scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].p);
a[i].x++;
}
sort(a,a+m,cmp);
int sum=;
for(i=m-; i>=; i--)
{
int r=query(a[i].x,a[i].y,,n,);
update(a[i].x,a[i].y,,n,);
sum+=r*a[i].p;
}
cout<<sum<<endl;
}
}

Huge Mission的更多相关文章

  1. FZU 1608 Huge Mission(线段树)

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

  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 【线段树区间更新】

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

  4. FOJ 1608 Huge Mission 线段树

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

  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. Huge Page 是否是拯救性能的万能良药?

    本文将分析是否Huge Page在任何条件下(特别是NUMA架构下)都能带来性能提升. 本博客已经迁移至: http://cenalulu.github.io/ 为了更好的体验,请通过此链接阅读: h ...

  9. 正则表达式30分钟入门:http://deerchao.net/tutorials/regex/regex.htm#mission

    http://deerchao.net/tutorials/regex/regex.htm#mission

随机推荐

  1. 九天学会Java,第五天,函数定义函数调用

    变量和数据类型,赋值和输出 算术运算 选择结构 循环结构 函数定义,函数调用 变量作用域 栈,程序运行的基石 面向对象 异常处理 语言提供的公用包 什么是函数,为什么有函数,大家可能有这样的疑问. 举 ...

  2. (转载)Java多线程入门理解

    转载出处http://blog.csdn.net/evankaka 写在前面的话:此文只能说是java多线程的一个入门,其实Java里头线程完全可以写一本书了,但是如果最基本的你都学掌握好,又怎么能更 ...

  3. MyBatis框架——关系映射(一对多、多对多、多对一查询)

    关系映射 一.映射(多)对一.(一)对一的关联关系 1).使用列的别名 ①.若不关联数据表,则可以得到关联对象的id属性 ②.若还希望得到关联对象的其它属性.则必须关联其它的数据表 1.创建表: 员工 ...

  4. 正则表达式 提取<A>标签

    功能用途 主要实现了提取html代码中的a标签和url地址. 示例代码 Regex regex = new Regex("href\\s*=\\s*(?:\"(?<1> ...

  5. 在htnl中,<input tyle = "text">除了text外还有几种种新增的表单元素

    input标签新增属性       <input   list='list_t' type="text" name='user' placeholder='请输入姓名' va ...

  6. hdu2546 01背包 重学背包

    题意:给出菜的价钱和自己的余额.使自己余额最少,注意余额大于5的情况可以买任意的菜. 思路:小于5的余额不能买菜,直接输出,大于五的余额,留下5元买最贵的菜,剩下的余额进行01背包,将剩下的余额减去0 ...

  7. PHP初入,for循环使用

    一: 找出100-999之间的所有"水仙花数".所谓水仙花数是指一个三位 数,各位数字的立方和等于该数本身.(如153次方=1的3次方+5的3次方+3的3次方)并输出这些数字 想想 ...

  8. mpls vpn剩余笔记

    将IP地址映射为简单的具有固定长度的标签 用于快速数据包交换 20 3 1 8 在整个转发过程中,交换节点仅根据标记进行转发 标签交换路径(LSP) 多协议标签交换MPLS最初是为了提高转发速度而提出 ...

  9. 201521123016 《Java程序设计》第8周学习总结

    1. 本周学习总结 2. 书面作业 本次作业题集集合 1.List中指定元素的删除(题目4-1) 1.1 实验总结 1.删除元素的时候从最后一个元素开始,避免删除元素后位置发生变化而导致有些元素没有删 ...

  10. 201521123068《Java程序设计》第4周学习总结

    1. 本周学习总结 1.1 尝试使用思维导图总结有关继承的知识点. 点击查看->高清脑图 1.2 使用常规方法总结其他上课内容. 答:学习继承与多态的知识,了解它们之间的关系:super.ext ...