HDU 1698 Just a Hook(线段树
Just a Hook
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 42724 Accepted Submission(s): 20543
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<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+;
int n,sum;
struct node{
int l,r,s;
}t[maxn<<];
void build(int l,int r,int num){
t[num].l=l;
t[num].r=r;
t[num].s=;
if(l==r) return;
int mid=(l+r)>>;
build(l,mid,num<<);
build(mid+,r,num<<|);
} void update(int l,int r,int m ,int num){
if(t[num].s==m) return;
if(t[num].l==l&&t[num].r==r){
t[num].s=m;
return ;
}
if(t[num].s!=-){
t[num<<].s=t[num<<|].s=t[num].s;
t[num].s=-;
}
int mid=(t[num].l+t[num].r)>>;
if(l>mid) update(l,r,m,num<<|);
else if(r<=mid) update(l,r,m,num<<);
else {
update(l,mid,m,num<<);
update(mid+,r,m,num<<|);
}
} int query(int num){
if(t[num].s!=-){
return (t[num].r-t[num].l+)*t[num].s;
}else{
return query(num<<)+query(num<<|);
}
} int main(){
int x,y,z,T,k;
scanf("%d",&T);
int cas=;
while(T--){
scanf("%d%d",&n,&k);
build(,n,);
while(k--){
scanf("%d%d%d",&x,&y,&z);
update(x,y,z,);
}
printf("Case %d: The total value of the hook is %d.\n",cas++,query());
}
return ;
}
HDU 1698 Just a Hook(线段树的更多相关文章
- 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(线段树 区间替换)
Just a Hook [题目链接]Just a Hook [题目类型]线段树 区间替换 &题解: 线段树 区间替换 和区间求和 模板题 只不过不需要查询 题里只问了全部区间的和,所以seg[ ...
- HDU 1698 Just a Hook(线段树成段更新)
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- HDU 1698 Just a Hook (线段树 成段更新 lazy-tag思想)
题目链接 题意: n个挂钩,q次询问,每个挂钩可能的值为1 2 3, 初始值为1,每次询问 把从x到Y区间内的值改变为z.求最后的总的值. 分析:用val记录这一个区间的值,val == -1表示这 ...
- [HDU] 1698 Just a Hook [线段树区间替换]
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- (简单) HDU 1698 Just a Hook , 线段树+区间更新。
Description: In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of ...
- HDU 1698 Just a Hook 线段树+lazy-target 区间刷新
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- HDU 1698 Just a Hook(线段树区间更新查询)
描述 In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of the heroes ...
- HDU 1698 Just a Hook(线段树区间替换)
题目地址:pid=1698">HDU 1698 区间替换裸题.相同利用lazy延迟标记数组,这里仅仅是当lazy下放的时候把以下的lazy也所有改成lazy就好了. 代码例如以下: # ...
- HDU 1698 Just a Hook 线段树区间更新、
来谈谈自己对延迟标记(lazy标记)的理解吧. lazy标记的主要作用是尽可能的降低时间复杂度. 这样说吧. 如果你不用lazy标记,那么你对于一个区间更新的话是要对其所有的子区间都更新一次,但如果用 ...
随机推荐
- 基于vue来开发一个仿饿了么的外卖商城(二)
一.抽出头部作为一个组件,在底部导航的时候可以相应的显示不同的标题 技术点:使用slot进行组件间的通信:父组件给子组件传值(子组件里面通过props接收父组件传过来的数据) 查看链接:https:/ ...
- 杭电 1003 Max Sum (动态规划)
参考:https://www.cnblogs.com/yexiaozi/p/5749338.html #include <iostream> #include <cstdio> ...
- shell重温---基础篇(printf命令&test命令)
在shell中还有一个输出的命令,那就是printf了.它模仿的是C程序库(library)里的printf()程序,是由POSIX标准所定义,所以嘞,使用printf脚本比echo移植性要好一点,它 ...
- python第一个程序-->hello world
最近在网上看到一个小笑话,一个程序员的自我嘲讽:“我精通所以计算机语言的hello world!” 好了,废话不多说了,开始撸代码: 我本人用的是python3.6版本,各位可以通过官网下载自己喜欢的 ...
- spring boot 入门3 如何在springboot 上使用AOP
Aop是spring的两大核心之一 那么如何在springboot中采用注解的形式实现aop那? 1)首先我们定义一个相关功能的切面类 并 采用@Aspect 注解来声明当前类为切面 同时采用@Com ...
- 你真的了解React吗
https://zhufengzhufeng.github.io/zhufengreact/index.html#t21.%E4%BB%80%E4%B9%88%E6%98%AFReact?
- SVN 使用时的小错误
在使用SVN的时候总是出现一些小问题,今天又出现了一个,诶,分享一下吧! Error:(个人文件夹名http://www.qdjhu.com/anli_xq/f_wancheng.php) is ...
- 「日常训练」Phone Numbers (CFR466D2C)
题意(Codeforces 940C) 给定一字符串,求比它字典序大的字符串.限定其长度,并且只能用原串的字母. 分析 考虑原串长度lorigin与给定的长度lgiven.若给定长度大于原串长度,直接 ...
- 9.0 toast定位+WebDriverWait显示等待
Toast 判断-----基本操作问题 首先基本操作,进入安卓市场的账号密码页面--- from appium import webdriver from selenium.webdriver.su ...
- hdu 1556 Color the ball (区间更新 求某点值)
Problem Description N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的“小飞鸽"牌电动车从气球a ...