E - Just a Hook - hdu 1698(区间覆盖)
某个英雄有这样一个金属长棍,这个金属棍有很多相同长度的短棍组成,大概最多有10w节,现在这个人有一种魔法,他可以把一段区间的金属棍改变成别的物质,例如金银或者铜, 现在他会有一些操作在这个金属棍上,他想知道这些操作结束后金属棍的质量是多少呢?(PS,一节铜重量1, 银 2 ,金3)。
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define Lson root<<1,L,tree[root].Mid()
#define Rson root<<1|1,tree[root].Mid()+1,R const int maxn = ; struct Hook{int l, r, z;}hook[maxn];
struct Tree{
int L, R;
int isCover;//等于1的时候被覆盖,等于2的时候区间下面有被覆盖的
int Mid(){return (L+R)/;}
int Len(){return (R-L+);}
}tree[maxn*]; void Build(int root, int L, int R)
{
tree[root].L = L, tree[root].R = R;
tree[root].isCover = false; if(L == R)return ; Build(Lson);
Build(Rson);
}
void Up(int root)
{
if(tree[root].L != tree[root].R)
if(tree[root<<].isCover == && tree[root<<|].isCover == )
tree[root].isCover = ;
}
int Insert(int root, int L, int R)
{
if(tree[root].isCover == )return ; if(tree[root].L == L && tree[root].R == R && !tree[root].isCover)
{
tree[root].isCover = ;
return tree[root].Len();
}
tree[root].isCover = ; int ans = ; if(R <= tree[root].Mid())
ans = Insert(root<<, L, R);
else if(L > tree[root].Mid())
ans = Insert(root<<|, L, R);
else
ans = Insert(Lson)+Insert(Rson); Up(root); return ans;
} int main()
{
int i, T, t=; scanf("%d", &T); while(T--)
{
int N, M; scanf("%d%d", &N, &M);
Build(, , N); for(i=; i<=M; i++)
scanf("%d%d%d", &hook[i].l, &hook[i].r, &hook[i].z); int ans = N; for(i=M; i>; i--)
{
int len = Insert(, hook[i].l, hook[i].r);
ans = ans - len + len * hook[i].z;
} printf("Case %d: The total value of the hook is %d.\n", t++, ans);
} return ; }
E - Just a Hook - hdu 1698(区间覆盖)的更多相关文章
- Just a Hook (HDU 1698) 懒惰标记
Just a Hook (HDU 1698) 题链 每一次都将一个区间整体进行修改,需要用到懒惰标记,懒惰标记的核心在于在查询前才更新,比如将当前点rt标记为col[rt],那么此点的左孩子和右孩子标 ...
- HDU 3397 区间覆盖,颠倒,合并(好题)
http://acm.hust.edu.cn/vjudge/problem/14689 三个操作 [a,b]覆盖为0 [a,b]覆盖为1 [a,b]颠倒每项 两个查询 [a,b]间1数量 [a,b]间 ...
- E - Just a Hook HDU - 1698 线段树区间修改区间和模版题
题意 给出一段初始化全为1的区间 后面可以一段一段更改成 1 或 2 或3 问最后整段区间的和是多少 思路:标准线段树区间和模版题 #include<cstdio> #include& ...
- Just a Hook HDU - 1698Just a Hook HDU - 1698 线段树区间替换
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> us ...
- HDU 1698 区间更新
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- hdu 1698区间延迟更新
#include<stdio.h> #define N 100100 struct node { int x,y,yanchi; }a[N*4];//注意数组范围 void build(i ...
- HDU 1698 Just a Hook(线段树区间替换)
题目地址:pid=1698">HDU 1698 区间替换裸题.相同利用lazy延迟标记数组,这里仅仅是当lazy下放的时候把以下的lazy也所有改成lazy就好了. 代码例如以下: # ...
- HDU 1698 Just a Hook (线段树区间更新)
题目链接 题意 : 一个有n段长的金属棍,开始都涂上铜,分段涂成别的,金的值是3,银的值是2,铜的值是1,然后问你最后这n段总共的值是多少. 思路 : 线段树的区间更新.可以理解为线段树成段更新的模板 ...
- HDU 1698——Just a Hook——————【线段树区间替换、区间求和】
Just a Hook Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit ...
随机推荐
- Linux基础系列—Linux体系结构和Linux内核结构
/** ****************************************************************************** * @author 暴走的小 ...
- Linux开发工具之gcc
一.gcc入门(上) 1.gcc相关概念 gcc(GNU C Compiler)编译器,最初支持C语言,现已支持C.C++.Java.Pascal.Ada.COBOL语言等:支持多种硬件平台: ...
- POJ 2007 Scrambled Polygon 凸包
Scrambled Polygon Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 7214 Accepted: 3445 ...
- git 的记住用户名和密码和一些常用
git config --global core.autocrlf falsegit config --global color.ui truegit config --global credenti ...
- html.ex.day01
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- CI 模型的使用M与C之间的调用
CI是PHP一个比较轻,并且好用的一个框架 分层也是分的比较清晰的一个 这里先展示MODEL 放在application/models 目录下面user_model.php <?php clas ...
- Android中使用PullToRefreshListView遇到的问题
1.布局文件中要是设置visible属性为Gone的时候,注意了,这样会有一个bug,在代码中setVisible的时候设置为VISIBLE是不起作用的..这个应该是自身的一个小bug(本人目前没有找 ...
- RoadTrip 学习笔记
#RoadTrip 学习笔记 本篇是在Cmd Markdown中写完粘贴来的. RoadTrip介绍 RoadTrip 项目地址:https://github.com/romainguy/road-t ...
- iOS应用架构谈 开篇 (转)
iOS应用架构谈 开篇 iOS应用架构谈 view层的组织和调用方案 iOS应用架构谈 网络层设计方案 iOS应用架构谈 动态部署方案 iOS应用架构谈 本地持久化方案 缘由 之前安居客iOS ap ...
- 自定义UITableViewCell时, 使用autoLayout, 无法很好的做到屏幕适配
解决方法: 重写cell的setFrame方法即可 - (void)setFrame:(CGRect)frame { frame.size.width = self.window.frame.size ...