FZU 1608 Huge Mission(线段树)

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
 
 1 #include <cstdio>
 2 #include <algorithm>
 3 using namespace std;
 4 
 5 #define lson l,m,rt<<1
 6 #define rson m+1,r,rt<<1|1
 7 #define root 1,N,1
 8 const int maxn=55555;
 9 int col[maxn<<2];
10 
11 void PushDown(int rt)//向下更新
12 {
13     if(col[rt])
14     {
15         int ls=rt<<1;
16         int rs=ls+1;
17         col[ls]=max(col[ls],col[rt]);
18         col[rs]=max(col[rs],col[rt]);
19         col[rt]=0;
20     }
21 }
22 
23 void build(int l,int r,int rt)
24 {
25     col[rt]=0;
26     if(l==r) return ;
27     int m=(l+r)>>1;
28     build(lson);
29     build(rson);
30 }
31 
32 void update(int L,int R,int c,int l,int r,int rt)
33 {
34     if(L<=l&&R>=r)
35     {
36         col[rt]=max(col[rt],c);
37         return ;
38     }
39     PushDown(rt);//down
40     int m=(l+r)>>1;
41     if(L<=m)
42         update(L,R,c,lson);
43     if(R>m)
44         update(L,R,c,rson);
45 }
46 
47 int get_ans(int l,int r,int rt)
48 {
49     if(l==r) return col[rt];
50     PushDown(rt);
51     int m=(l+r)>>1;
52     return get_ans(lson)+get_ans(rson);
53 }
54 
55 int solve()
56 {
57     int N,M;
58     while(~scanf("%d%d",&N,&M))
59     {
60         build(root);
61         while(M--)
62         {
63             int a,b,c;
64             scanf("%d%d%d",&a,&b,&c);
65             if(c) update(a+1,b,c,root);
66         }
67         printf("%d\n",get_ans(root));
68     }
69     return 0;
70 }
71 
72 int main()
73 {
74     return solve();
75 }
View Code

 

转载于:https://www.cnblogs.com/zyx1314/p/3568166.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
疫情居家办公系统管理系统按照操作主体分为管理员和用户。管理员的功能包括办公设备管理、部门信息管理、字典管理、公告信息管理、请假信息管理、签到信息管理、留言管理、外出报备管理、薪资管理、用户管理、公司资料管理、管理员管理。用户的功能等。该系统采用了MySQL数据库,Java语言,Spring Boot框架等技术进行编程实现。 疫情居家办公系统管理系统可以提高疫情居家办公系统信息管理问题的解决效率,优化疫情居家办公系统信息处理流程,保证疫情居家办公系统信息数据的安全,它是一个非常可靠,非常安全的应用程序。 管理员权限操作的功能包括管理公告,管理疫情居家办公系统信息,包括外出报备管理,培训管理,签到管理,薪资管理等,可以管理公告。 外出报备管理界面,管理员在外出报备管理界面中可以对界面中显示,可以对外出报备信息的外出报备状态进行查看,可以添加新的外出报备信息等。签到管理界面,管理员在签到管理界面中查看签到种类信息,签到描述信息,新增签到信息等。公告管理界面,管理员在公告管理界面中新增公告,可以删除公告。公告类型管理界面,管理员在公告类型管理界面查看公告的工作状态,可以对公告的数据进行导出,可以添加新公告的信息,可以编辑公告信息,删除公告信息
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值