HDU - 1698 Just a Hook (线段树)
来源:互联网 发布:手机淘宝没有收藏按钮 编辑:程序博客网 时间:2024/05/03 22:55
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=1698
题解:
做的我不想说啥了…..此题使用cin的话会超时,结构体tr得开原来数据范围的4倍左右
AC代码:
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#define lc (d<<1)#define rc (d<<1|1)#define mid ((l+r)>>1)using namespace std;int n,m;struct node{ int sum, lz;}tr[400040];void build(int d, int l, int r){ tr[d].lz = 0; tr[d].sum = 1; if(l == r) { return; } build(lc, l, mid); build(rc, mid+1, r);}void lazy(int d, int l, int r){ int x = r - l + 1; if(tr[d].lz != 0) { tr[lc].lz = tr[d].lz; tr[rc].lz = tr[d].lz; tr[lc].sum = tr[d].lz * (x - (x>>1));//这个括号贼关键,不用就wa tr[rc].sum = tr[d].lz * (x>>1);//这里错了好久。。忘记除2了 tr[d].lz = 0 ; }}void update(int d, int l, int r, int L, int R, int k){ if(l >= L && r <= R) { tr[d].lz = k; tr[d].sum = k * (r - l + 1); return; } lazy(d,l,r); if(L <= mid) update(lc,l,mid,L,R,k); if(R > mid) update(rc,mid+1,r,L,R,k); tr[d].sum = tr[lc].sum + tr[rc].sum;}int main(){ int t,cnt = 1; scanf("%d", &t); while(t--) { scanf("%d", &n); build(1,1,n); scanf("%d", &m); while(m--) { int l,r,k; scanf("%d%d%d", &l,&r,&k); update(1,1,n,l,r,k); } printf("Case %d: The total value of the hook is %d.\n",cnt++,tr[1].sum); } return 0;}
0 0
- HDU 1698 Just a Hook 线段树
- [hdu]1698 Just a Hook -- 线段树
- hdu 1698 Just a Hook 线段树
- HDU 1698 JUST A HOOK(线段树)
- HDU 1698 Just a Hook 线段树
- HDU 1698 Just a Hook(线段树)
- HDU 1698 just a hook 线段树
- HDU 1698 Just a Hook(线段树)
- hdu 1698 - Just a Hook(线段树)
- HDU 1698 Just a Hook (线段树)
- hdu 1698 Just a Hook 线段树
- hdu 1698 Just a Hook 线段树
- Just a Hook - HDU 1698 线段树
- hdu 1698 Just a Hook(线段树)
- hdu 1698 Just a Hook(线段树)
- HDU - 1698 Just a Hook(线段树)
- hdu 1698 Just a Hook 线段树
- hdu 1698 Just a Hook(线段树)
- OpenCV | 基本操作API
- MySQL表约束
- POJ3641
- 排序---快速排序
- SPOJ BALNUM - Balanced Numbers
- HDU - 1698 Just a Hook (线段树)
- hdu 1598 find the most comfortable road(并查集+枚举)
- MySQL索引的使用
- carriewave 根据一个 url 来保存图片
- CodeForces 560A Currency System in Geraldion
- AAC音频格式分析与解码
- 规模化敏捷框架(SAFe)的原则
- Linux下crontab定时任务服务
- 【ITOO】——动态删除题库补充