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. note04-计算机网络

    4.WLAN无线局域网(wareless local area network) IEEE802.11无线以太网协议标准 基础服务集合BSS 基站AP 服务服务集合标识SSID 即wifi名 分配系统 ...

  2. 类型系统(type system)是一门编程语言最核心也是最基础的部分---编程语言最终的目标,本质上无非是回答两个问题:如何表示信息、如何处理信息

    https://www.cnblogs.com/feng9exe/p/9712059.html 类型系统(type system)是一门编程语言最核心也是最基础的部分.无论该语言基于何种编程范式,都必 ...

  3. 2018.11.13 Hibernate 中数据库查询中的Criteria查询实例

    Criteria是面向对象的无语句查询 Demo.java package com.legend.b_criteria; import java.util.List; import org.hiber ...

  4. 【转】Java类加载原理解析

    原链接 1 基本信息 每个java开发人员对java.lang.ClassNotFoundExcetpion这个异常肯定都不陌生,这背后就涉及到了java技术体系中的类加载. Java的类加载机制是j ...

  5. 用selenium爬动态网页

    0-安装 我用python2.7,用pip安装selenium即可,phantomjs到官网下载安装,也不难. 1-主要参考的几篇文章 Python爬虫利器四之PhantomJS的用法 Python爬 ...

  6. 【luogu P3372 线段树1】 模板

    线段树的模板题 题目链接:https://www.luogu.org/problemnew/show/P3372 update区间修改,query区间求和 #include <iostream& ...

  7. css块元素的 display 属性 inline-block 的应用

    <%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> < ...

  8. Java to Kotlin (1) - 就决定是你了

    2017年,Kotlin的发展可谓十分迅猛,稍微关注it界的人都知道谷歌宣布kotlin成为安卓的一级语言,不过那时候我并没有关注,因为我不是搞安卓的... 哈哈开个玩笑,其实之前也有听说过这个语言的 ...

  9. 如何对Project Proffesional设置预警灯

    Project Proffesional没法一目了然地看到,为了实时看到任务延迟情况,我们必须设置预警灯. 1.添加两个新列“文本1”.“文本2”,重命名为“完成预警”.“进度预警”. 2.右键点击“ ...

  10. Java基础知识(持续更新中...)

    1.成员变量:全局变量/字段(Field),不要称之为属性(错误)直接定义在类中,方法外面 1.类成员变量    使用static修饰的变量 2.实例成员变量 没用使用static修饰的变量 局部变量 ...