博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU1698_Just a Hook(线段树/成段更新)
阅读量:7238 次
发布时间:2019-06-29

本文共 2523 字,大约阅读时间需要 8 分钟。

解题报告

题意:

原本区间1到n都是1,区间成段改变成一个值,求最后区间1到n的和。

思路:

线段树成段更新,区间去和。

#include 
#include
#include
using namespace std;int sum[500000],lz[500000];void push_up(int root,int l,int r){ sum[root]=sum[root*2]+sum[root*2+1];}void push_down(int root,int l,int r){ if(lz[root]!=-1) { int m=(r-l+1); lz[root*2]=lz[root]; lz[root*2+1]=lz[root]; sum[root*2]=lz[root]*(m-m/2); sum[root*2+1]=lz[root]*(m/2); lz[root]=-1; }}void update(int root,int l,int r,int ql,int qr,int v){ if(ql>r||qr
r||qr

Just a Hook

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 17182    Accepted Submission(s): 8575


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.

转载地址:http://hprfm.baihongyu.com/

你可能感兴趣的文章
myisam MySQL 锁问题
查看>>
为什么获取的System.Web.HttpContext.Current值为null,HttpContext对象为null时如何获取程序(站点)的根目录...
查看>>
告诉你一个真实的OpenStack:都谁在用,用来干什么?
查看>>
在idea中maven项目jdk编译version总是跳到1.5
查看>>
理解与应用css中的display属性
查看>>
升级openssl环境至openssl-1.1.0c
查看>>
javaScript判断浏览器类型
查看>>
SQL注入之SQLmap入门
查看>>
Hibernate缓存研究
查看>>
Cesium原理篇:3D Tiles(1)渲染调度
查看>>
neuroph Perceptron Sample
查看>>
关于navicat连接oracle 报 ORA-12737 set CHS16GBK错误的解决方案
查看>>
MEP自定义参数化风机盘管族
查看>>
(android控件)巧用background属性,实现图片可选择效果
查看>>
获取APK文件的签名信息,反射实现
查看>>
Hive On Spark hiveserver2方式使用
查看>>
如何在Android开发中让你的代码更有效率
查看>>
Visual Studio项目的生成事件代码
查看>>
android的消息处理机制(图文+源码分析)—Looper/Handler/Message[转]
查看>>
lightswitch conditional formatting change color
查看>>