#include <iostream>
#include <stdio.h>
#define MAX_N 100001
using namespace std;
struct node{
int left, right, c;
} tt[MAX_N * 4];
void build(int left, int right, int index) {
tt[index].left = left;
tt[index].right = right;
tt[index].c = 1;
if (left == right) return;
int mid = (left + right) / 2;
build(left, mid, index * 2);
build(mid + 1, right, index * 2 + 1);
}
void update(int index, int left, int right, int c) {
if (tt[index].left >= left && tt[index].right <= right) {
tt[index].c = c;
return;
}
if (tt[index].c != -1) {
tt[index * 2].c = tt[index * 2 + 1].c = tt[index].c;
tt[index].c = -1;
}
int mid = (tt[index].left + tt[index].right) / 2;
if (mid >= left) update(index * 2, left, right, c);
if (mid < right) update(index * 2 + 1, left, right, c);
}
int solve(int index) {
if (tt[index].c != -1) return tt[index].c * (tt[index].right - tt[index].left + 1);
return solve(index * 2) + solve(index * 2 + 1);
}
int main() {
int t, icase, n, m, i, a, b, c;
scanf("%d", &icase);
t = 0;
while (icase--) {
scanf("%d%d", &n, &m);
build(1, n, 1);
for (i = 0; i < m; i++) {
scanf("%d%d%d", &a, &b, &c);
update(1, a, b, c);
}
printf("Case %d: The total value of the hook is %d.\n", ++t, solve(1));
}
return 0;
}
hdu 1698
最新推荐文章于 2022-04-01 12:15:40 发布
本文介绍了一种基于段式树的数据结构实现方法,用于高效处理区间更新与查询操作。通过构建初始段式树并定义更新及求解函数,实现了对指定区间内元素值的批量修改,并快速获取整个区间的总价值。
部署运行你感兴趣的模型镜像
您可能感兴趣的与本文相关的镜像
ACE-Step
音乐合成
ACE-Step
ACE-Step是由中国团队阶跃星辰(StepFun)与ACE Studio联手打造的开源音乐生成模型。 它拥有3.5B参数量,支持快速高质量生成、强可控性和易于拓展的特点。 最厉害的是,它可以生成多种语言的歌曲,包括但不限于中文、英文、日文等19种语言
401

被折叠的 条评论
为什么被折叠?



