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. [2012-05-31]awk记录分割符RS

    $awk -v RS= '{print $1}' test RS 默认值为\n 换行符. 此处设置RS= 等效于 RS="" 代表一个空行 (若理解有误请指正,在以下例子中符合) ...

  2. java 泛型简单使用

  3. github+hexo搭建自己的博客网站(四)主题之外的一些基本配置(统计配置,网站访问量显示)

    1.百度.谷歌统计配置 百度统计配置 申请账号:https://tongji.baidu.com/web/welcome/login 在代码获取的地方只要填入key即可 注册的时候,填的域名和url, ...

  4. mysql中int(10)与int(11)有什么区别吗?

    先来看下面的图片 声明字段是int类型的那一刻起,int就是占四个字节,一个字节8位,也就是4*8=32,可以表示的数字个数是2的32次方(2^32 = 4 294 967 296个数字). 4 29 ...

  5. JavaSE(十)集合之Set

    今天这一篇把之前没有搞懂的TreeSet中的比较搞得非常的清楚,也懂得了它的底层实现.希望博友提意见! 一.Set接口 1.1.Set集合概述 Set集合:它类似于一个罐子,程序可以依次把多个对象 “ ...

  6. 英语APP体验

    第一部分 1.下载并使用,描述最简单直观的个人第一次上手体验. 感觉不是很好用,可能是个人习惯吧,之前用的都是扇贝单词和有道词典,所以不是特别顺手. 2.找出几个功能性的比较严重的 bug 在口语挑战 ...

  7. 201521123028 《Java程序设计》第5周学习总结

    1. 本周学习总结 2. 书面作业 Q1.代码阅读:Child压缩包内源代码 1.1 com.parent包中Child.java文件能否编译通过?哪句会出现错误?试改正该错误.并分析输出结果. Ch ...

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

    1. 本周学习总结 1.1 尝试使用思维导图总结有关多态与接口的知识点. 2. 书面作业 1.代码阅读:Child压缩包内源代码 1.1 com.parent包中Child.java文件能否编译通过? ...

  9. Java课程设计——猜数游戏(201521123111 陈伟泽)

    Java课程设计--猜数游戏(201521123111 陈伟泽) 1.团队课程设计博客链接 博客作业--猜数游戏 2.个人负责模块或任务说明 Answer:一些基础界面的构造,排行榜的构造,用文件录入 ...

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

    1. 本章学习总结 以你喜欢的方式(思维导图或其他)归纳总结异常与多线程相关内容 线程不是程序 线程必须在程序对应的进程中运行 一个进程中可以同时执行多个线程,这些线程可以完成不同的功能. 2. 书面 ...