当前位置:网站首页>HDU1698_Just a Hook
HDU1698_Just a Hook
2022-07-27 12:27:00 【51CTO】
Just a Hook
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 17125 Accepted Submission(s): 8547
Problem Description
In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of the heroes. The hook is made up of several consecutive metallic sticks which are of the same length.

Now Pudge wants to do some operations on the hook.
Let us number the consecutive metallic sticks of the hook from 1 to N. For each operation, Pudge can change the consecutive metallic sticks, numbered from X to Y, into cupreous sticks, silver sticks or golden sticks.
The total value of the hook is calculated as the sum of values of N metallic sticks. More precisely, the value for each kind of stick is calculated as follows:
For each cupreous stick, the value is 1.
For each silver stick, the value is 2.
For each golden stick, the value is 3.
Pudge wants to know the total value of the hook after performing the operations.
You may consider the original hook is made up of cupreous sticks.
Input
The input consists of several test cases. The first line of the input is the number of the cases. There are no more than 10 cases.
For each case, the first line contains an integer N, 1<=N<=100,000, which is the number of the sticks of Pudge’s meat hook and the second line contains an integer Q, 0<=Q<=100,000, which is the number of the operations.
Next Q lines, each line contains three integers X, Y, 1<=X<=Y<=N, Z, 1<=Z<=3, which defines an operation: change the sticks numbered from X to Y into the metal kind Z, where Z=1 represents the cupreous kind, Z=2 represents the silver kind and Z=3 represents the golden kind.
Output
For each case, print a number in a line representing the total value of the hook after the operations. Use the format in the example.
Sample Input
1 10 2 1 5 2 5 9 3
Sample Output
Case 1: The total value of the hook is 24.
题目大意:
有三种钩子,铜,银,金,价值分别为1,2,3,现有编号1~N个钩子,初始的时候都为铜钩子,之后进行多次操作。
操作可将区间[a,b]的钩子换成铜,银,金的。问:最后1~N个钩子的总价值是多少。
思路:
建立1~N的线段树,因为区间更新每次更新到叶子节点的话比较耗时,所以使用一个暂时标志,用来代表区间要改的值。这样就不必每次更新到叶子节点了。比如线段树区间为1~10,需要更新1~5,那么只需向下更新到区间1~5即可。如果需要更新1~4,则需要再往下走。
边栏推荐
- Bishi journey
- 严控室外作业时间!佛山住建局发文:加强高温期间建筑施工安全管理
- 2021-3-19-byte-face value
- Lonely young people can't quit jellycat
- About offline caching application cache / using manifest file caching
- Chapter 10 enumeration classes and annotations
- Makefile template
- Chapter 13 IO flow
- go语言之sync.Map
- Shell script text three swordsman awk
猜你喜欢
随机推荐
Go Beginner (3)
Guangdong's finance has taken many measures to help stabilize the "ballast stone" of food security
5V boost 9V chip
Switching value input and output module dam-5055
The chess robot "broke" the chess boy's finger...
About the problem that the onapplicationevent method of the custom listener is executed multiple times
Go Introduction (2)
Image segmentation vs Adobe Photoshop (PS)
上半年火灾起数下降27.7%,广东将这样提升全民消防安全素质
Newticker uses
最强分布式锁工具:Redisson
Solution: can not issue executeupdate() or executelargeupdate() for selections
Chapter 7 exception handling
5V升压9V芯片
JS parasitic combinatorial inheritance
【数据库数据恢复】SQL Server数据库所在磁盘分区空间不足报错的数据恢复案例
Unity shader - Laser special effect shader[easy to understand]
@Postconstruct annotations and initializingbean perform some initialization operations after bean instantiation
严控室外作业时间!佛山住建局发文:加强高温期间建筑施工安全管理
V-show失效问题








