Huge Mission
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
Sample Output
#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的更多相关文章
- FZU 1608 Huge Mission(线段树)
Problem 1608 Huge Mission Time Limit: 1000 mSec Memory Limit : 32768 KB Problem Description Oaiei ...
- FZU 1608 Huge Mission
Huge Mission Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on FZU. Original I ...
- FZU_1608 Huge Mission 【线段树区间更新】
一.题目 Huge Mission 二.分析 区间更新,用线段树的懒标记即可.需要注意的时,由于是在最后才查询的,没有必要每次更新都对$sum$进行求和.还有一点就是初始化的问题,一定记得线段树上每个 ...
- FOJ 1608 Huge Mission 线段树
每个节点维护一个最小值,更新发现如果大于最小值,直接向下更新.速度还可以.. #include<cstdio> #include<algorithm> #include< ...
- 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 ...
- Huge Page 是否是拯救性能的万能良药?
本文将分析是否Huge Page在任何条件下(特别是NUMA架构下)都能带来性能提升. 本博客已经迁移至: http://cenalulu.github.io/ 为了更好的体验,请通过此链接阅读: h ...
- 正则表达式30分钟入门:http://deerchao.net/tutorials/regex/regex.htm#mission
http://deerchao.net/tutorials/regex/regex.htm#mission
随机推荐
- Mybatis映射文件完整模板参照
Mybatis映射文件完整模板参照 <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE map ...
- DES、3DES、AES加密方式
详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt165 DES 支持8位加密解密,3Des支持24位,Aes支持32位.3De ...
- 日期时间范围选择插件:daterangepicker使用总结
分享说明: 项目中要使用日期时间范围选择对数据进行筛选;精确到年月日 时分秒;起初,使用了layui的时间日期选择插件;但是在IIE8第一次点击会报设置格式错误;研究了很久没解决,但能确定不是layu ...
- 网络编程:基于C语言的简易代理服务器实现(proxylab)
本文记录了一个基于c socket的简易代理服务器的实现.(CS:APP lab 10 proxy lab) 本代理服务器支持keep-alive连接,将访问记录保存在log文件. Github: h ...
- [[NSBundle mainBundle] pathForResource:fileName ofType:]获取文件路径不成功
目标文件明明已经加入项目了,但是使用[[NSBundle mainBundle] pathForResource:fileName ofType:]来获取文件路径的时候却为nil: 遇到这个问题大家需 ...
- Jenkins关于tomcat地址和端口映射的配置
<?xml version='1.0' encoding='utf-8'?><!-- Licensed to the Apache Software Foundation (ASF) ...
- 垂直居中小记 line-height table vertical-align:middle
垂直居中分两种情况:1.父元素高度确定的单行文本 2.以及父元素高度确定的多行文本. 1.垂直居中-父元素高度确定的单行文本的竖直居中的方法是通过设置父元素的 height 和 line ...
- C++ Primmer 学习笔记
一.开始 (一)输入输出 1.endl的作用 endl操纵符用于结束当前行,将与设备关联的缓冲区内容刷新到设备中.如果没有这个字符,一旦程序突然崩溃,就可能导致输出还停留在缓冲区里,而不显示到设备. ...
- 转:【Java并发编程】之十六:深入Java内存模型——happen-before规则及其对DCL的分析(含代码)
转载请注明出处:http://blog.csdn.net/ns_code/article/details/17348313 happen-before规则介绍 Java语言中有一个"先行发生 ...
- 学习目标或者作业的制定(SMART原则)
以下文字摘自邹欣老师的博客 很高兴看到学生们都写了自己的目标: http://www.cnblogs.com/deng201421123059/p/6435346.html 不得不说,有些同学的目标太 ...