hdu 1689 Just a Hook
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
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.
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.
10
2
1 5 2
5 9 3
#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的更多相关文章
- HDU.1689 Just a Hook (线段树 区间替换 区间总和)
HDU.1689 Just a Hook (线段树 区间替换 区间总和) 题意分析 一开始叶子节点均为1,操作为将[L,R]区间全部替换成C,求总区间[1,N]和 线段树维护区间和 . 建树的时候初始 ...
- hdu - 1689 Just a Hook (线段树区间更新)
http://acm.hdu.edu.cn/showproblem.php?pid=1698 n个数初始每个数的价值为1,接下来有m个更新,每次x,y,z 把x,y区间的数的价值更新为z(1<= ...
- HDU 1689 Just a Hook (线段树区间更新+求和)
Just a Hook Problem Description In the game of DotA, Pudge's meat hook is actually the most horrible ...
- (线段树)Just a Hook -- hdu -- 1689
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1698 思路: 我的想法很简单,像上一题一样从后面向前面来算,前面已经覆盖的,后面自然不能再来计算了,具体 ...
- HDU 1698 Just a Hook (线段树区间更新)
题目链接 题意 : 一个有n段长的金属棍,开始都涂上铜,分段涂成别的,金的值是3,银的值是2,铜的值是1,然后问你最后这n段总共的值是多少. 思路 : 线段树的区间更新.可以理解为线段树成段更新的模板 ...
- HDU 1698 Just a Hook(线段树成段更新)
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=1698 题目: Problem Description In the game of DotA, P ...
- 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 ...
- HDU 1698 Just a Hook(线段树:区间更新)
http://acm.hdu.edu.cn/showproblem.php?pid=1698 题意:给出1~n的数,每个数初始为1,每次改变[a,b]的值,最后求1~n的值之和. 思路: 区间更新题目 ...
- HDU 1698 just a hook - 带有lazy标记的线段树(用结构体实现)
2017-08-30 18:54:40 writer:pprp 可以跟上一篇博客做个对比, 这种实现不是很好理解,上一篇比较好理解,但是感觉有的地方不够严密 代码如下: /* @theme:segme ...
随机推荐
- C#中默认的修饰符
参考自Default visibility for C# classes and members (fields, methods, etc)? Classes and structs that ar ...
- uva live 6170
Esspe-Peasee Esspe-Peasee is an ancient game played by children throughout the land of Acmania. The ...
- HighCharts 饼图
@{ ViewBag.Title = "Index"; Layout = "~/Views/Shared/_Layout.cshtml"; } @section ...
- EF之MSSQL分布式部署一:EFContext自定义数据库链接
不废话,上代码: 来源:http://bbs.csdn.net/topics/390823046 原文地址:EF之MSSQL分布式部署一:EFContext自定义数据库链接 /// <sum ...
- Oracle中job的使用详解
我们在项目开发中,常常会有一些复杂的业务逻辑.使用oracle的存储过程,可以大大减少java程序代码的编写工作量,而且存储过程执行在数据库上,这样可以利用oracle的良好性能支持,极大地提高程序执 ...
- 在linux设置环境变量
1.直接用export命令:#export PATH=$PATH:/opt/au1200_rm/build_tools/bin查看是否已经设好,可用命令export查看: [root@localhos ...
- 【转】android布局属性详解
LinearLayout布局: 线性版面配置,在这个标签中,所有元件都是按由上到下的排队排成的.在这个界面中,我们应用了一个 LinearLayout的布局,它是垂直向下扩展的 ,所以创建的布局XML ...
- 一步一步ITextSharp 低级操作函数使用
首先说一下PDF文档的结构: 分为四层,第一层和第四层由低级操作来进行操作,第二层.第三层由高级对象操作 第一层操作只能使用PdfWriter.DirectContent操作,第四层使用DirectC ...
- 基于Spring AOP实现对外接口的耗时监控
AOP是Spring的核心,Spring不但自身对多种框架的集成是基于AOP,并且以非常方便的形式暴露给普通使用者.以前用AOP不多,主要是因为它以横截面的方式插入到主流程中,担心导致主流程代码不够清 ...
- centos软件环境
1,保持能链接外网和yum的可用性. 注意:yum配置项中最好:keepcache=1 2,yum install gcc, gcc-c++, make, cmake, 3, ntfs-3g wget ...