Just a Hook

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

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.
题意:n个数初始值为1,m次操作区间替换,输出总和
 #include<cstdio>
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
const int MAXN = ;
int sum[MAXN<<];
int col[MAXN<<];
int t,n,q;
void putup(int rt)
{
sum[rt] = sum[rt<<]+sum[rt<<|];
}
void putdown(int rt,int m)
{
if (col[rt])
{
col[rt<<] = col[rt<<|] = col[rt];
sum[rt<<] = (m-(m>>))*col[rt];
sum[rt<<|] = (m>>)*col[rt];
col[rt] = ;
}
}
void build(int l,int r,int rt)
{
col[rt] = ;
sum[rt] = ;
if (l==r) return ;
int m = (l+r)>>;
build(lson);
build(rson);
putup(rt);
}
void update(int l,int r,int rt,int L,int R,int c)
{
if (L<=l && r<=R)
{
col[rt] = c;
sum[rt] = c*(r-l+);
return ;
}
putdown(rt,r-l+);
int m = (l+r)>>;
if (L<=m) update(lson,L,R,c);
if (R>m) update(rson,L,R,c);
putup(rt);
}
int main()
{
scanf("%d",&t);
for (int i=; i<=t; ++i)
{
scanf("%d%d",&n,&q);
build(,n,);
while (q--)
{
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
update(,n,,x,y,z);
}
printf("Case %d: The total value of the hook is %d.\n",i,sum[]);
}
return ;
}

1698-Just a Hook 线段树(区间替换)的更多相关文章

  1. HDU 1698 Just a Hook(线段树 区间替换)

    Just a Hook [题目链接]Just a Hook [题目类型]线段树 区间替换 &题解: 线段树 区间替换 和区间求和 模板题 只不过不需要查询 题里只问了全部区间的和,所以seg[ ...

  2. [HDU] 1698 Just a Hook [线段树区间替换]

    Just a Hook Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  3. HDU 1698 Just a Hook(线段树区间替换)

    题目地址:pid=1698">HDU 1698 区间替换裸题.相同利用lazy延迟标记数组,这里仅仅是当lazy下放的时候把以下的lazy也所有改成lazy就好了. 代码例如以下: # ...

  4. HDU.1689 Just a Hook (线段树 区间替换 区间总和)

    HDU.1689 Just a Hook (线段树 区间替换 区间总和) 题意分析 一开始叶子节点均为1,操作为将[L,R]区间全部替换成C,求总区间[1,N]和 线段树维护区间和 . 建树的时候初始 ...

  5. (简单) HDU 1698 Just a Hook , 线段树+区间更新。

    Description: In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of ...

  6. HDU 1698 Just a Hook(线段树区间更新查询)

    描述 In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of the heroes ...

  7. HDU 1698 Just a Hook 线段树区间更新、

    来谈谈自己对延迟标记(lazy标记)的理解吧. lazy标记的主要作用是尽可能的降低时间复杂度. 这样说吧. 如果你不用lazy标记,那么你对于一个区间更新的话是要对其所有的子区间都更新一次,但如果用 ...

  8. hdu1698(线段树区间替换模板)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1698 题意: 第一行输入 t 表 t 组测试数据, 对于每组测试数据, 第一行输入一个 n , 表示 ...

  9. poj2528(线段树区间替换&离散化)

    题目链接: http://poj.org/problem?id=2528 题意: 第一行输入一个 t 表 t 组输入, 对于每组输入: 第一行  n 表接下来有 n 行形如 l, r 的输入, 表在区 ...

  10. Just a Hook 线段树 区间更新

    Just a Hook In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of t ...

随机推荐

  1. Jmeter入门11 使用Simple Controller组织接口测试用例

    接口测试实践中,可以使用Simple Controller来组织测试用例. 官网上说该控制器的主要用途用来组织采样器和其他的逻辑控制器等. 以下为一个接口测试项目结构示例: 1 测试计划 >添加 ...

  2. bootstrap-multiselect.js多选下拉框初始化时默认选中初始值

    bootstrap-multiselect.js多选下拉框默认值设置 一.案例数据格式  二.HTML代码 <select id="msgRoles" multiple=&q ...

  3. Codeforces 385C 线性筛素数

    题意:给定一个数组,求[l,r] 区间,区间里的素数,数组中,能被这个素数整除的个数,再求和. 分析:区间很大,10^9了,找去区间内的素数是不可能的,但是,数组的数很小,而且要能整除区间内的素数,所 ...

  4. POJ 2365【YY水题】

    题目链接:POJ 2365 Rope Rope Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7488   Accepted ...

  5. WPF学习笔记(7):DataGrid中数字自定义格式显示

    DataGrid中数据显示如下图,数据格式比较杂乱.希望达到以下要求:(1)所有数据保留两位小数:(2)超过1000的数字显示千分位:(3)如果数据为0,不显示. 首先想到用StringFormat进 ...

  6. 【luogu P1456 Monkey King】 题解

    题目链接:https://www.luogu.org/problemnew/show/P1456 左偏树并查集不加路径压缩吧... #include <cstdio> #include & ...

  7. Select 语句执行顺序以及如何提高Oracle 基本查询效率

    今天把这几天做的练习复习了一下,不知道自己写得代码执行的效率如何以及要如何提高,于是乎上网开始研究一些材料,现整理如下: 首先,要了解在Oracle中Sql语句运行的机制.以下是sql语句的执行步骤: ...

  8. BigDecimal运算(加、减、乘、除)

    public class BigDecimalOperation { private BigDecimalOperation(){ } public static BigDecimal add(dou ...

  9. 2、开发环境搭建-window平台

    一.搭建ReactNative环境 首先安装node.js和python2.xx版本,不要装python3.xx,这个官方是特别说明的,请注意.NodeJs官方下载:https://nodejs.or ...

  10. jQuery的封装

    封装,最简单的效果就是一个效果你可以重复的去调用   本来前端之路时间不是很长,但是对封装还是有一点点自己个人的理解,曾经踩过的坑也不在少数,最后总结出我个人风格的封装,听一位大神指点过,每个人都有属 ...