Just a Hook

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

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.
题意:区间和为多少?
收获:tre[num],lazy[num]代表什么很重要。
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <set>
using namespace std; const int INF=0x3f3f3f3f;
const double eps=1e-;
const double PI=acos(-1.0);
#define maxn 110000
int tre[maxn*];
int lazy[maxn*];
void build(int num, int le, int ri)
{
if(le == ri)
{
tre[num] = ;
return;
}
int mid = (le+ri)/;
build(num*, le, mid);
build(num*+, mid+, ri);
tre[num] = tre[num*] + tre[num*+];
}
void pushdown(int num, int le, int mid, int ri)
{
if(lazy[num]!=)
{
lazy[num*] = lazy[num];
lazy[num*+] = lazy[num];
tre[num*] = (mid-le+)*lazy[num*];
tre[num*+] = (ri-mid)*lazy[num*+];
lazy[num] = ;
}
} void update(int num, int le, int ri, int x, int y, int val)
{
if(x<=le && y>=ri)
{
tre[num] = (ri-le+)*val;
lazy[num] = val;
return;
}
int mid = (le+ri)/;
pushdown(num,le,mid,ri);
if(x<=mid)
update(num*,le,mid,x,y,val);
if(y>mid)
update(num*+,mid+,ri,x,y,val);
tre[num] = tre[num*] + tre[num*+];
}
int main()
{
int t;
scanf("%d", &t);
int cas = ;
while(t--)
{
int n;
scanf("%d", &n);
build(,,n);
memset(lazy, , sizeof lazy);
int m;
scanf("%d", &m);
for(int i = ; i < m; i++)
{
int a,b,c;
scanf("%d%d%d", &a, &b, &c);
update(,,n,a,b,c);
}
printf("Case %d: The total value of the hook is %d.\n", ++cas, tre[]);
}
return ;
}
 

HDU1698 Just a Hook (区间更新)的更多相关文章

  1. hdu1698线段树的区间更新区间查询

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

  2. hdu1698 线段树(区间更新~将区间[x,y]的值替换为z)

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

  3. HDU 1698 Just a Hook 区间更新 lazy标记

    lazy标记 #include <iostream> #include <cstdio> #include <cstring> #include <sstre ...

  4. HDU1698 线段树(区间更新区间查询)

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

  5. 【原创】hdu1698 Just a Hook(线段树→区间更新,区间查询)

    学习线段树第二天,这道题属于第二简单的线段树,第一简单是单点更新,这个属于区间更新. 区间更新就是lazy思想,我来按照自己浅薄的理解谈谈lazy思想: 就是在数据结构中,树形结构可以线性存储(线性表 ...

  6. HDU1698:Just a Hook(线段树区间更新)

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

  7. hdu1698 Just a hook 线段树区间更新

    题解: 和hdu1166敌兵布阵不同的是 这道题需要区间更新(成段更新). 单点更新不用说了比较简单,区间更新的话,如果每次都更新到底的话,有点费时间. 这里就体现了线段树的另一个重要思想:延迟标记. ...

  8. hdu1698 线段树区间更新

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

  9. 线段树---成段更新hdu1698 Just a Hook

    hdu1698 Just a Hook 题意:O(-1) 思路:O(-1) 线段树功能:update:成段替换 (由于只query一次总区间,所以可以直接输出1结点的信息) 题意:给一组棍子染色,不同 ...

随机推荐

  1. openStack kilo 手动Manual部署随笔记录

    一 ,基于neutron网络资源主机(控制节点,网络节点,计算节点)网络规划配置 1, controller.cc 节点 网络配置截图

  2. [iOS] Baritem 添加一项

    不是拖拽,而是在设计栏的属性设置里面.

  3. swift 自定义导航栏颜色

    func setNavigationApperance(){ //自定义导航栏颜色 [self.navigationController?.navigationBar.barTintColor = U ...

  4. read(),write() 读/写文件

    read read()是一个系统调用函数.用来从一个文件中,读取指定长度的数据到 buf 中. 使用read()时需要包含的头文件: <unistd.h> 函数原型: ssize_t re ...

  5. Linux文件 I/O 介绍

    Linux文件 I/O 介绍 1. Linux系统调用 Linux系统调用(system call)是指操作系统提供给用户程序的一组"特殊接口",用户程序可以通过这组"特 ...

  6. iOS平台下cookie的使用

    iOS平台下cookie的使用 首先,先介绍下iOS对cookie的操作的两个类: 帖子来源于:http://blog.csdn.net/chun799/article/details/1720690 ...

  7. JS高级程序设计学习笔记之数组

    数组创建的方式 var str = new Array();放入数字即为设置数组长度 var str = []; 数组的length可读可写 监测数组 Array.isArray()方法确定某个值是不 ...

  8. CSS基础知识笔记(一)

    css 样式由选择符和声明组成,而声明又由属性和值组成: 选择符: 又称选择器,指明网页中要应用样式规则的元素,如本例中是网页中所有的段(p)的文字将变成蓝色,而其他的元素(如ol)不会受到影响. 声 ...

  9. FineUI上传控件

    文件上传 现在就简单多了,并且也漂亮多了,参考这个示例. 1: <ext:SimpleForm ID="SimpleForm1" BodyPadding="5px& ...

  10. Winform 无边框随意拖动【转载】

    本篇技术内容转载自:http://www.cnblogs.com/ap0606122/archive/2012/10/23/2734964.html using System; using Syste ...