FZU 1608 Huge Mission (线段数区间更新求和)

本文深入探讨了如何通过优化时间分配和利用不同的工作效率矩阵,实现个人或团队的工作效率最大化。通过案例分析,展示了如何灵活调整工作强度以适应不同时间段的效率变化,从而在有限的时间内完成更多任务。特别强调了通过合理安排工作时段,选择最适合自身的工作状态和任务特性的时间段进行高效工作,以及如何通过调整工作强度来应对任务难度和截止日期的挑战。

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 <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int maxn = 50000 + 5;
struct tree {
    int max_val;
    int lh, rh;
    void exp_max(int val) {
        max_val = max(max_val, val);
    }
} T[maxn<<2];

void Build(int root, int l, int r)
{
    T[root].max_val = 0;
    T[root].lh = l;
    T[root].rh = r;
    if(l + 1 >= r) return;
    int mid = (l + r) >> 1;
    Build(root<<1, l, mid);
    Build(root<<1|1, mid, r);
}

void Insert(int root, int l, int r, int val)
{
    if(T[root].rh <= l || T[root].lh >= r) return;
    if(T[root].lh >= l && T[root].rh <= r) {
        T[root].exp_max(val);
        return;
    }
    Insert(root<<1, l, r, val);
    Insert(root<<1|1, l, r, val);
}

int Query(int root, int l, int r)
{
    if(l + 1 >= r) return T[root].max_val;
    T[root<<1].exp_max(T[root].max_val);
    T[root<<1|1].exp_max(T[root].max_val);
    int mid = (l + r) >> 1;
    return Query(root<<1, l, mid) + Query(root<<1|1, mid, r);
}

int main()
{
//    freopen("in", "r", stdin);
    int n, m;
    while(~scanf("%d%d", &n, &m)) {
        memset(T, 0, sizeof(T));
        Build(1, 0, n);
        int s, t, p;
        for(int i = 0; i < m; ++i) {
            scanf("%d%d%d", &s, &t, &p);
            Insert(1, s, t, p);
        }
        printf("%d\n", Query(1, 0, n));
    }
    return 0;
}


评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值