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

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.
 
 
题目大意:
 
有一根棍,现在要给他表面镀上一层金属,(本身这根棍是铜的)
铜的价值是1
银得价值是2
金的价值是3
求最后的价值是多少。
 
分析:
用一个变量e表示这一段节点价值
如果这一段节点有两种金属就让e=-1;
 
 
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<iostream>
#include<string.h>
#include<stdlib.h>
using namespace std;
#define N 101000
#define Lson r<<1
#define Rson r<<1|1 struct node
{
int L,R,e;
bool is;
int mid()
{
return (L+R)/;
}
int len()
{
return R-L+;
}
}a[N*]; void BuildTree(int r,int L,int R)
{
a[r].L=L;
a[r].R=R;
a[r].e=;
if(L==R)
{
return;
}
BuildTree(Lson,L,a[r].mid());
BuildTree(Rson,a[r].mid()+,R);
}
int Qurry(int r)
{
if(a[r].e!=-)
return a[r].len()*a[r].e;
else
return Qurry(Lson)+Qurry(Rson);
}
void Update(int r,int L,int R,int e)
{ if(a[r].L==L && a[r].R==R)
{
a[r].e=e;
return;
}
if(a[r].e!=-)
{
a[Lson].e=a[Rson].e=a[r].e;
}
a[r].e=-;
if(R<=a[r].mid())
Update(Lson,L,R,e);
else if(L>a[r].mid())
Update(Rson,L,R,e);
else
{
Update(Lson,L,a[r].mid(),e);
Update(Rson,a[r].mid()+,R,e);
}
}
int main()
{
int T,n,m,i,t,x,y,e;
scanf("%d",&T);
t=;
while(T--)
{
scanf("%d",&n);
BuildTree(,,n);
scanf("%d",&m);
for(i=;i<=m;i++)
{
scanf("%d %d %d",&x,&y,&e);
Update(,x,y,e);
}
printf("Case %d: The total value of the hook is %d.\n",t++,Qurry());
}
return ;
}

Just a Hook-HDU1698(线段树求区间)的更多相关文章

  1. 2016年湖南省第十二届大学生计算机程序设计竞赛---Parenthesis(线段树求区间最值)

    原题链接 http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1809 Description Bobo has a balanced parenthes ...

  2. xdoj-1324 (区间离散化-线段树求区间最值)

    思想 : 1 优化:题意是覆盖点,将区间看成 (l,r)转化为( l-1,r) 覆盖区间 2 核心:dp[i]  覆盖从1到i区间的最小花费 dp[a[i].r]=min (dp[k])+a[i]s; ...

  3. hdu 1754 I Hate It (线段树求区间最值)

    HDU1754 I Hate It Time Limit:3000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u D ...

  4. hdu 1698:Just a Hook(线段树,区间更新)

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

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

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

  6. 【线段树求区间第一个不大于val的值】Lpl and Energy-saving Lamps

    https://nanti.jisuanke.com/t/30996 线段树维护区间最小值,查询的时候优先向左走,如果左边已经找到了,就不用再往右了. 一个房间装满则把权值标记为INF,模拟一遍,注意 ...

  7. poj 3264 线段树 求区间最大最小值

    Description For the daily milking, Farmer John's N cows (1 ≤ N ≤ 50,000) always line up in the same ...

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

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

  9. BZOJ 4127: Abs (树链剖分 线段树求区间绝对值之和 带区间加法)

    题意 给定一棵树,设计数据结构支持以下操作 1 u v d 表示将路径 (u,v) 加d(d>=0) 2 u v 表示询问路径 (u,v) 上点权绝对值的和 分析 绝对值之和不好处理,那么我们开 ...

  10. HDU6447 YJJ's Salesman-2018CCPC网络赛-线段树求区间最值+离散化+dp

    目录 Catalog Solution: (有任何问题欢迎留言或私聊 && 欢迎交流讨论哦 Catalog Problem:Portal传送门  原题目描述在最下面.  1e5个点,问 ...

随机推荐

  1. vue 2.0 路由创建的详解过程

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. 更改ligerui源码实现分页样式修改

    修改后样式: 第一步:实现功能. 更改源码部分ligerui.all.js文件 读源代码,发现ligerui底部工具条是这样实现的(ps:注释部分为源码) _render: function () { ...

  3. servlet 常用指令

    一.设置响应内容类型 response.setContentType("text/html;charset=UTF-8"); 二.设置请求的字符编码 request.setChar ...

  4. jQuery 收缩展开效果

    <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Conten ...

  5. 自动化测试selenium + request + 动态加载页面

    # demo01from selenium import webdriver from time import sleep bro = webdriver.Chrome(executable_path ...

  6. createdb - 创建一个新的 PostgreSQL 数据库

    SYNOPSIS createdb [ option...] [ dbname] [ description] DESCRIPTION 描述 createdb 创建一个新的 PostgreSQL 数据 ...

  7. 使用nsight调试caffe

    首先你需要下载caffe源码,然后先编译好,注意一定要将Makefile.config里的DEBUG := 1注释掉 可以看到注释掉debug后编译会生成的.build_debug目录,调试过程中需要 ...

  8. UTF-8,UTF-16

    UTF是 Unicode Translation Format,即把Unicode转做某种格式的意思. 在Unicode基本多文种平面定义的字符(无论是拉丁字母.汉字或其他文字或符号),一律使用2字节 ...

  9. php使用命名空间时自动加载机制

    命名空间主要为了解决用户编写的代码与PHP内部的类/函数/常量或第三方类/函数/常量之间的名字冲突.不过并不是你定义了使用命名空间的类,就可以在任何地方随意使用了,需要在程序运行时将定义命名空间的类文 ...

  10. Mysql 字符函数详解

    MySql 所有字符串函数函数详解 ASCII(str) 返回str最左边第一位字符的ASCII编码,如果str为空,则返回 0 .如果str为NULL,则返回NULL -- 只返回a的ASCII编码 ...