Just a Hook-HDU1698(线段树求区间)
http://acm.hdu.edu.cn/showproblem.php?pid=1698
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<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(线段树求区间)的更多相关文章
- 2016年湖南省第十二届大学生计算机程序设计竞赛---Parenthesis(线段树求区间最值)
原题链接 http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1809 Description Bobo has a balanced parenthes ...
- xdoj-1324 (区间离散化-线段树求区间最值)
思想 : 1 优化:题意是覆盖点,将区间看成 (l,r)转化为( l-1,r) 覆盖区间 2 核心:dp[i] 覆盖从1到i区间的最小花费 dp[a[i].r]=min (dp[k])+a[i]s; ...
- hdu 1754 I Hate It (线段树求区间最值)
HDU1754 I Hate It Time Limit:3000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u D ...
- hdu 1698:Just a Hook(线段树,区间更新)
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- hdu1698线段树的区间更新区间查询
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- 【线段树求区间第一个不大于val的值】Lpl and Energy-saving Lamps
https://nanti.jisuanke.com/t/30996 线段树维护区间最小值,查询的时候优先向左走,如果左边已经找到了,就不用再往右了. 一个房间装满则把权值标记为INF,模拟一遍,注意 ...
- poj 3264 线段树 求区间最大最小值
Description For the daily milking, Farmer John's N cows (1 ≤ N ≤ 50,000) always line up in the same ...
- HDU1698 线段树(区间更新区间查询)
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...
- BZOJ 4127: Abs (树链剖分 线段树求区间绝对值之和 带区间加法)
题意 给定一棵树,设计数据结构支持以下操作 1 u v d 表示将路径 (u,v) 加d(d>=0) 2 u v 表示询问路径 (u,v) 上点权绝对值的和 分析 绝对值之和不好处理,那么我们开 ...
- HDU6447 YJJ's Salesman-2018CCPC网络赛-线段树求区间最值+离散化+dp
目录 Catalog Solution: (有任何问题欢迎留言或私聊 && 欢迎交流讨论哦 Catalog Problem:Portal传送门 原题目描述在最下面. 1e5个点,问 ...
随机推荐
- javax.xml.bind.UnmarshalException: 意外的元素 (uri:"", local:"xml")。所需元素为(none)
将xml转换为object时候报错:javax.xml.bind.UnmarshalException: 意外的元素 (uri:"", local:"xml") ...
- git ---匿名分支和checkout命令
git checkout -b //创建一个匿名分支
- git ---查看工作状态和历史提交
1.git查看状态 -git status 2.版权声明 版权声明:新建一个 LICENSE.txt 文件 开源协议:MIT //开源许可里面的最宽松的一个协议,别人可以随便用你的代码,但 ...
- idea 2018 解决 双击shift 弹出 search everywhere 搜索框的方法
https://youtrack.jetbrains.com/issue/IDEA-161094
- Scala基础篇-01变量,数据类型
一.Scala变量 共有3种变量修饰符: val: 可变 var: 不可变 lazy val: 第一次应用时才计算 二.Scala的数据类型 1)类型不匹配:高精度数值赋给低精度数据类型. 2)Uni ...
- Java多线程编程核心技术---Lock的基本概念和使用
Lock接口: ReentrantLock的基本功能: ReentrantLock的lock和unlock方法进行加锁,解锁.可以起到和synchronized关键字一样的效果: 选择性通知!!!: ...
- 玩一把redis源码(一):为redis添加自己的列表类型
2019年第一篇文档,为2019年做个良好的开端,本文档通过step by step的方式向读者展示如何为redis添加一个数据类型,阅读本文档后读者对redis源码的执行逻辑会有比较清晰的认识,并且 ...
- 说说C#中list与IList中的区别(转载)
首先IList 泛型接口是 ICollection 泛型接口的子代,并且是所有泛型列表的基接口. 但是它仅仅是所有泛型类型的接口,并没有太多方法可以方便实用,如果仅仅是作为集合数据的承载体,确实,IL ...
- XP禁用了U盘和移动硬盘方法
会不会是你XP禁用了U盘和移动硬盘下面这些是任何禁用U盘的!你自己反着试下嘛!方法一,BIOS设置法(快刀斩乱麻法) 进入BIOS设置,选择“Integrated Peripherals”选项,展开后 ...
- getDate() 获取时间 如2018年09月21日 11:32:11
function p(s) { return s < 10 ? '0' + s: s;} function getDate() { var myDate = new Date(); //获取当前 ...