复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49#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的全部内容,更多相关hdu内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复