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. [转]Ubuntu 配置 Android 开发 环境

    转自:http://blog.csdn.net/shulianghan/article/details/20855541 1. 安装 Android Studio (1) 下载Android Stud ...

  2. ettercap_缺少组件问题

    原因:缺少WinPcap组件解决:安装即可

  3. 八数码(IDA*算法)

    八数码 IDA*就是迭代加深和A*估价的结合 在迭代加深的过程中,用估计函数剪枝优化 并以比较优秀的顺序进行扩展,保证最早搜到最优解 需要空间比较小,有时跑得比A*还要快 #include<io ...

  4. HDU 1210 Eddy's 洗牌问题(找规律,数学)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1210 Eddy's 洗牌问题 Time Limit: 2000/1000 MS (Java/Other ...

  5. 使用redux代码文件的组织方式

    从架构触发,开始一个新应用的时候,代码文件的组织方式一定要考虑好 如果之前使用过mvc的框架那么对按角色组织方式一定不陌生 角色组织方式 reducer/ todoReducer.js filterR ...

  6. Oracle 反向索引(反转建索引) 理解

    一 反向索引 1.1 反向索引的定义 反向索引作为B-tree索引的一个分支,主要是在创建索引时,针对索引列的索引键值进行字节反转,进而实现分散存放到不同叶子节点块的目的. 1.2 反向索引针对的问题 ...

  7. vue.esm.js:578 [Vue warn]: Missing required prop

    问题: 解决: required: true,属性是,这个必须填写

  8. VMware ESXi-6.7——使用

    1: 上传ISO文件 1.1:创建一个新目录,上传ISO 1.2: 在新建虚拟机时,点击DVD,选择数据ISO文件,选择要安装的ISO文件.并把连接打钩. 2:新建虚拟机 按照需求填写 硬盘的三种置备 ...

  9. Django中ORM常用字段类型及参数

    常用字段: <1> CharField 字符串字段, 用于较短的字符串. CharField 要求必须有一个参数 maxlength, 用于从数据库层和Django校验层限制该字段所允许的 ...

  10. 关系型数据库设计——E-R图

    一.数据管理技术的三个发展阶段: 1)人工管理阶段(20世纪50年代中期) 特点:数据不保存:应用程序管理数据:数据不共享:数据没有独立性: 2)文件系统阶段(20世纪50年代后—60年代)特点:数据 ...