http://acm.hdu.edu.cn/showproblem.php?pid=1698

Just a Hook

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

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.
 
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define N 100005
#define Lson root<<1, L, tree[root].Mid()
#define Rson root<<1|1, tree[root].Mid() + 1, R using namespace std; struct Tree
{
int L, R, e, sum;
int Mid()
{
return (L + R) / ;
}
} tree[N * ]; void Build(int root, int L, int R)
{
tree[root].L = L, tree[root].R = R;
tree[root].e = ;
if(L == R)
{
tree[root].sum = ;
return ;
} Build(Lson);
Build(Rson); tree[root].sum = tree[root<<].sum + tree[root<<|].sum;
} void Update(int root, int L, int R, int e)
{
if(tree[root].L == L && tree[root].R == R)
{
tree[root].e = e;
tree[root].sum = (tree[root].R - tree[root].L + ) * tree[root].e;
return ;
}
if(tree[root].e != )
{
tree[root<<].sum = (tree[root<<].R - tree[root<<].L + ) * tree[root].e;
tree[root<<|].sum = (tree[root<<|].R - tree[root<<|].L + ) * tree[root].e; tree[root<<].e = tree[root<<|].e = tree[root].e;
tree[root].e = ;
}
if(R <= tree[root].Mid())
Update(root<<, L, R, e);
else if(L > tree[root].Mid())
Update(root<<|, L, R, e);
else
{
Update(Lson, e);
Update(Rson, e);
}
tree[root].sum = tree[root<<].sum + tree[root<<|].sum;
} int main()
{
int t, n, m, a, b, c, x = ;
scanf("%d", &t);
while(t--)
{
x++;
scanf("%d", &n);
Build(, , n);
scanf("%d", &m);
while(m--)
{
scanf("%d%d%d", &a, &b, &c);
Update(, a, b, c);
}
printf("Case %d: The total value of the hook is %d.\n", x, tree[].sum);
}
return ;
}

hdu 1689 Just a Hook的更多相关文章

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

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

  2. hdu - 1689 Just a Hook (线段树区间更新)

    http://acm.hdu.edu.cn/showproblem.php?pid=1698 n个数初始每个数的价值为1,接下来有m个更新,每次x,y,z 把x,y区间的数的价值更新为z(1<= ...

  3. HDU 1689 Just a Hook (线段树区间更新+求和)

    Just a Hook Problem Description In the game of DotA, Pudge's meat hook is actually the most horrible ...

  4. (线段树)Just a Hook -- hdu -- 1689

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=1698 思路: 我的想法很简单,像上一题一样从后面向前面来算,前面已经覆盖的,后面自然不能再来计算了,具体 ...

  5. HDU 1698 Just a Hook (线段树区间更新)

    题目链接 题意 : 一个有n段长的金属棍,开始都涂上铜,分段涂成别的,金的值是3,银的值是2,铜的值是1,然后问你最后这n段总共的值是多少. 思路 : 线段树的区间更新.可以理解为线段树成段更新的模板 ...

  6. HDU 1698 Just a Hook(线段树成段更新)

    题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=1698 题目: Problem Description   In the game of DotA, P ...

  7. HDU 1698 just a hook 线段树,区间定值,求和

    Just a Hook Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1 ...

  8. HDU 1698 Just a Hook(线段树:区间更新)

    http://acm.hdu.edu.cn/showproblem.php?pid=1698 题意:给出1~n的数,每个数初始为1,每次改变[a,b]的值,最后求1~n的值之和. 思路: 区间更新题目 ...

  9. HDU 1698 just a hook - 带有lazy标记的线段树(用结构体实现)

    2017-08-30 18:54:40 writer:pprp 可以跟上一篇博客做个对比, 这种实现不是很好理解,上一篇比较好理解,但是感觉有的地方不够严密 代码如下: /* @theme:segme ...

随机推荐

  1. VS2010中如果忘记函数所在的头文件或者忘记函数的输入输出参数类型怎么办?

    先随便找一个熟悉的函数,右击-转到定义,然后写出目标函数,右击-转到定义

  2. 最大流算法(Edmons-Karp + Dinic 比较) + Ford-Fulkson 简要证明

    Ford-Fulkson用EK实现:483ms #include <cstdio> #include <cstring> #define min(x,y) (x>y?y: ...

  3. 宏buf_pool_struct

    typedef struct buf_pool_struct buf_pool_t; /** @brief The buffer pool structure. NOTE! The definitio ...

  4. Delegate 委托复习(-) 委托的基本概念

    1. 声明一个delegate对象,它应当与你想要传递的方法具有相同的参数和返回值类型.      声明一个代理的例子:     public delegate int MyDelegate(stri ...

  5. Zxing 扫二维码

    1 http://blog.csdn.net/xiaanming/article/details/10163203 2 我会把一个可以运行的Demo云盘:http://pan.baidu.com/s/ ...

  6. memcached 最大连接数及其内存大小的设置

    memcached的基本设置: -p 监听的端口-l 连接的IP地址, 默认是本机-d start 启动memcached服务-d restart 重起memcached服务-d stop|shutd ...

  7. Creating SharePoint 2010 Event Receivers in Visual Studio 2010

    转:http://msdn.microsoft.com/en-us/library/gg252010(v=office.14).aspx Summary:  Learn how to create a ...

  8. linux 下 NetBeans 字体大小设置

    在linux mint 12下安装了 NetBeans7.1.2使用之后,觉得字体不好看,字体普遍特别大,分三个方面改NetBeans的字体. 1. 代码字体大小 点击NetBeans菜单,工具--& ...

  9. Pacman主题下给Hexo增加简历类型

    原文 http://blog.zanlabs.com/2015/01/02/add-resume-type-to-hexo-under-pacman-theme/ 背景 虽然暂时不找工作,但是想着简历 ...

  10. 11g 重建EM 报ORA-20001: SYSMAN already exists

    今天在安装11g(11.1.0.7.0)数据库之后,通过emca -config dbcontrol db -repos create 命令手工创建em的时候报错,查看日志后发现有以下错误 CONFI ...