HDU 1698Just a Hook
来源:互联网 发布:jdk环境变量 linux 编辑:程序博客网 时间:2024/05/22 22:33
题意:水题线段树,区间更新带上+lazy标记,最后统计即可;
#include<algorithm>#include<iostream>#include<queue>#include<stack>#include<map>#include<vector>#include<set>#include<cstring>#include<cstdio>#define N 100005using namespace std;typedef struct node{int x;int y;int date;int p;}node;node a[N*4];void built(int root,int first,int end){if(first==end){a[root].date=1;a[root].x=first;a[root].y=end;a[root].p=0;return ;}int mid=(first+end)/2;built(root*2,first,mid);built(root*2+1,mid+1,end);a[root].x=a[root*2].x;a[root].y=a[root*2+1].y;a[root].date=a[root*2+1].date+a[root*2].date;a[root].p=0;}void U(int root,int first,int end,int l,int r,int e){if(l<=first&&end<=r){a[root].date=(end-first+1)*e;a[root].p=e;return ;}int mid=(first+end)/2;if(a[root].p!=0){a[root*2+1].date=(end-mid)*a[root].p;a[root*2+1].p=a[root].p;a[root*2].date=(mid-first+1)*a[root].p;a[root*2].p=a[root].p;a[root].p=0;}if(l<=mid) U(root*2,first,mid,l,r,e);if(r>mid) U(root*2+1,mid+1,end,l,r,e);a[root].date=a[root*2].date+a[root*2+1].date;}void Q(int root,int first,int end){if(first==end){return ;}int mid=(first+end)/2;if(a[root].p!=0){a[root*2+1].date=(end-mid)*a[root].p;a[root*2+1].p=a[root].p;a[root*2].date=(mid-first+1)*a[root].p;a[root*2].p=a[root].p;a[root].p=0;}Q(root*2,first,mid);Q(root*2+1,mid+1,end);a[root].date=a[root*2+1].date+a[root*2].date;}int main(){int m;scanf("%d",&m);for(int i=1;i<=m;i++){int n;scanf("%d",&n);built(1,1,n);int k;scanf("%d",&k);int b,c,d;for(int j=1;j<=k;j++){scanf("%d%d%d",&b,&c,&d);U(1,1,n,b,c,d);}Q(1,1,n);printf("Case %d: ",i);printf("The total value of the hook is %d.\n",a[1].date);}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
- 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
- [BZOJ 2657][Zjoi2012]旅游(journey):树的直径
- Python 输入时间字符串以分钟单位计算时间差
- PHP获取访客IP、地区位置信息、浏览器、来源页面
- plsql字符乱码-字符集设置
- Android开发基础之Intent
- HDU 1698Just a Hook
- 最近要学的课程
- 大数据可视化,助力行业大数据应用
- 获取bean的三种方法
- D 03_JavaScript概述
- 链表面试题集锦
- 设置Android Studio Documentation 不自动弹出
- 安装Genymotion模拟器运行Android studio的工程
- Apache Zeppelin 0.7.2 中文文档-ApacheCN