2023广东省赛B Base Station Construction
  YdxfFsjpYokY 2023年11月02日 64 0


2023广东省赛B Base Station Construction_Code
2023广东省赛B Base Station Construction_acm_02个点,每个点有点权,有2023广东省赛B Base Station Construction_ci_03个区间,要选择一些点使得所有区间里都有点,求最小总点权
2023广东省赛B Base Station Construction_Code_04

2023广东省赛B Base Station Construction_dp_05
广东省赛好水啊,感觉单挑都可以至少2023广东省赛B Base Station Construction_Code_06
这题属于一眼题了,不知为何过的很少
2023广东省赛B Base Station Construction_dp_07表示2023广东省赛B Base Station Construction_dp_08这个区间全部满足条件并且选择了2023广东省赛B Base Station Construction_算法_09的最少花费
2023广东省赛B Base Station Construction_Code_10有一个点且点权为2023广东省赛B Base Station Construction_ci_11,则答案就是2023广东省赛B Base Station Construction_dp_12
转移方程2023广东省赛B Base Station Construction_acm_13其中要满足2023广东省赛B Base Station Construction_Code_14之间没有要求区间,考虑2023广东省赛B Base Station Construction_dp_15的合法区间,假设为2023广东省赛B Base Station Construction_dp_16,当2023广东省赛B Base Station Construction_算法_09变为2023广东省赛B Base Station Construction_dp_18时,如果有一个区间以i结尾并且左端点在2023广东省赛B Base Station Construction_ci_19之间,那么对于2023广东省赛B Base Station Construction_dp_18来说,2023广东省赛B Base Station Construction_dp_15的区间会变小,这个过程中,2023广东省赛B Base Station Construction_dp_15的区间只会越来越往右变小,因此可以用单调栈维护这个2023广东省赛B Base Station Construction_算法_23
2023广东省赛B Base Station Construction_Code_24

#include <cstdio>
#include <algorithm>
#define ll long long
using namespace std;
const int maxn = 5e5 + 10;
struct IO {
	template <class T>
	IO operator>>(T &res) {
		res = 0;
		char ch;
		bool flag = false;
		while ((ch = getchar()) > '9' || ch < '0')	flag |= ch == '-';
		while (ch >= '0' && ch <= '9')	res = (res << 3) + (res << 1) + (ch ^ '0'), ch = getchar();
		if (flag)	res = ~res + 1;
		return *this;
	}
} cin;
int T, n, m, hd, ed;
int a[maxn], l[maxn], q[maxn];
ll f[maxn];
void solve ()
{
    cin >> n;
    for (int i = 1; i <= n; ++i)    cin >> a[i], l[i] = 0;
    cin >> m;
    for (int i = 1, lt, rt; i <= m; ++i) {
        cin >> lt >> rt;
        l[rt] = max(l[rt], lt);
    }
    q[hd = ed = 1] = 0;
    a[++n] = 0;
    for (int i = 1; i <= n; ++i) {
        f[i] = f[q[hd]] + a[i];
        while (hd <= ed && f[q[ed]] > f[i])   --ed;
        q[++ed] = i;
        while (q[hd] < l[i])    ++hd;
    }
    printf("%lld\n", f[n]);
}
int main ()
{
    cin >> T;
    while (T--) solve();
    return 0;
}

如有哪里讲得不是很明白或是有错误,欢迎指正
如您喜欢的话不妨点个赞收藏一下吧


【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  anLrwkgbyYZS   2023年12月30日   28   0   0 i++iosi++ioscici
  anLrwkgbyYZS   2023年12月30日   32   0   0 ideciciMaxideMax
YdxfFsjpYokY