线段树——HDU - 1698
题目含义
就是初始化一堆数为1
可以经过操作把一个区间的数都改变
并求这堆数的总大小
题目分析
有一个
#include<iostream> #include<stdio.h> #include<string.h> #include<algorithm> using namespace std; typedef long long LL; const int maxn=1e5+7; int sum[maxn<<2],lazy[maxn<<2]; int t,len,n,l,r,d; void build(int l,int r,int rt){lazy[rt]=0;if(l==r){sum[rt]=1;return;}int mid=(l+r)>>1;build(l,mid,rt<<1);build(mid+1,r,rt<<1|1);sum[rt]=sum[rt<<1]+sum[rt<<1|1]; } void pushdown(int l,int r,int rt){if(lazy[rt]){int mid=(l+r)>>1;lazy[rt<<1]=lazy[rt];lazy[rt<<1|1]=lazy[rt];sum[rt<<1]=(mid+1-l)*lazy[rt];sum[rt<<1|1]=(r-mid)*lazy[rt];lazy[rt]=0;} } void updata(int l,int r,int rt,int ll,int rr,int d){if(ll<=l&&r<=rr){sum[rt]=(r+1-l)*d;lazy[rt]=d;return;}pushdown(l,r,rt);int mid=(l+r)>>1;if(ll<=mid)updata(l,mid,rt<<1,ll,rr,d);if(rr>mid)updata(mid+1,r,rt<<1|1,ll,rr,d);sum[rt]=sum[rt<<1]+sum[rt<<1|1]; } int main(){scanf("%d",&t);int ce=1;while(t--){scanf("%d%d",&len,&n);build(1,len,1);for(int i=1;i<=n;i++){scanf("%d%d%d",&l,&r,&d);updata(1,len,1,l,r,d);}printf("Case %d: The total value of the hook is %d.\n",ce++,sum[1]);}return 0; }
区间更新,可以用树状数组也可以用线段树
题目代码
转载于:https://www.cnblogs.com/helman/p/11232835.html
线段树——HDU - 1698相关推荐
- poj 2528 离散化+线段树 hdu 1698 线段树 线段树题目类型一:染色计数 外加离散化
第一次听到离散化是今年省赛的时候,一道矩形并的题,很水,就两个矩形... 今天再去做线段树已经发现离散化忘得差不多了...水逼的悲哀啊... 先看简单点的hdu 1698 http://acm.hdu ...
- 线段树 HDU 4046 panda
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4046 代码风格:www.notonlysuccess.com 题目大意:求wbw出现的个数 算法:线段 ...
- 线段树 HDU 3397
5种操作 具体看代码 #include<iostream> #include<stdio.h> #include<string.h> #include<alg ...
- 线段树专辑——hdu 1698 Just a Hook
http://acm.hdu.edu.cn/showproblem.php?pid=1698 这是一个区间染色的问题,对于区间染色问题,通常的方法是在线段树中定义一个cover域,当cover的值为- ...
- hdu 1698 Just a Hook 线段树区间更新
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1698 Let us number the consecutive metallic sticks of ...
- hdu 1698 Just a Hook(线段树区间更新·经典)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1698 数据:case,n,q,q行x,y,z.在长度为n的hook上进行q次区间更新,把它们的价值改变.最 ...
- POJ 2777 ZOJ 1610 HDU 1698 --线段树--区间更新
直接将这3题 放一起了 今天在做线段树的东西 这3个都是区间更新的 查询方式互相不同 反正都可以放到一起吧 直接先上链接了 touch me touch me touch me 关于涉及到区间的修改 ...
- hdu 1698(线段树区间更新)
解题思路:线段树区间更新水题. #include<iostream> #include<cstdio> #include<cstring> using namesp ...
- 【HDU - 1698】 Just a Hook(线段树模板 区间覆盖更新(laz标记) + 区间和查询 )
题干: In the game of DotA, Pudge's meat hook is actually the most horrible thing for most of the heroe ...
最新文章
- sqlserver存储过程循环写法
- 用eclipse创建动态web项目手动生成web.xml方法
- word2003计算机考试题,[2018职称计算机Word2003考前练习题] 2018年职称计算机考试练习题库...
- Maven—Eclipse设置Maven项目JDK版本
- 七月算法机器学习1 概率论
- 鲜卑族的由来与现在的分布
- java中使用MD5验证文件的完整性
- 《剑指offer》阅读体会
- ”35岁没500万存款就是失败?“,35岁职场人真实存款流出!
- OpenStack常用运维命令手册-V1.0-黑夜青儿
- codeforces 1567 C. Carrying Conundrum
- time gmtime localtime strftime 时间函数
- 走进“开源SDR实验室” 一起玩转GNU Radio:gr-channels
- php curl 设置accept,CURL php不会接受Accept-Language:fr需要获取JSON
- core webapi缩略图_在ASP.NET Core Web API 项目里无法访问(wwwroot)下的文件
- oracle联表更新语句
- 车载c语言,车载考试系统
- 模拟路线软件 android,来自巴西模拟器的路线
- Oracle相关知识点关键词
- 共享键盘鼠标 oxs mac linux,Synergy 1.5.0 多台Macbook共享鼠标和键盘