(1698)线段树
来源:互联网 发布:印度奶茶知乎 编辑:程序博客网 时间:2024/05/21 05:57
#include<iostream>
#include<cstdio>
#include<string.h>
#include<string>
#include<stack>
#include<set>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#define ll __int64
#define lll unsigned long long
#define MAX 3000001
#define eps 1e-8
#define INF 0xfffffff
#define mod 1000000007
/*
题意:线段树
想法: 成段更新
*/
using namespace std;
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
const int maxn = 155555;
int sum[maxn<<2];
int col[maxn<<2];
void Pushup(int rt)
{
sum[rt] = sum[rt<<1] + sum[rt<<1|1];
}
void PushDown(int rt,int m)
{
if(col[rt])
{
col[rt<<1] = col[rt<<1|1] = col[rt];
sum[rt<<1] = (m - (m>>1))*col[rt<<1];
sum[rt<<1|1] = (m>>1)*col[rt<<1|1];
col[rt] = 0;
}
}
void build(int l,int r, int rt)
{
sum[rt] = 1;
col[rt] = 0;
if(l==r) return ;
int m = (l+r)>>1;
build(lson);
build(rson);
Pushup(rt);
}
void update(int L,int R,int c,int l,int r,int rt)
{
if(L<=l&&r<=R)
{
col[rt] = c;
sum[rt] = (r - l + 1)*c;
return ;
}
PushDown(rt, r - l + 1);
int m = (l+r)>>1;
if(L<=m)
update(L,R,c,lson);
if(R>m)
update(L,R,c,rson);
Pushup(rt);
}
int main()
{
int t;
int n,m;
int X,Y,Z;
scanf("%d",&t);
for(int i = 1;i<=t;i++)
{
scanf("%d%d",&n,&m);
build(1,n,1);
for(int j = 0;j<m;j++)
{
scanf("%d%d%d",&X,&Y,&Z);
update(X,Y,Z,1,n,1);
}
printf("Case %d: The total value of the hook is %d.\n",i,sum[1]);
}
return 0;
}
#include<cstdio>
#include<string.h>
#include<string>
#include<stack>
#include<set>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#define ll __int64
#define lll unsigned long long
#define MAX 3000001
#define eps 1e-8
#define INF 0xfffffff
#define mod 1000000007
/*
题意:线段树
想法: 成段更新
*/
using namespace std;
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
const int maxn = 155555;
int sum[maxn<<2];
int col[maxn<<2];
void Pushup(int rt)
{
sum[rt] = sum[rt<<1] + sum[rt<<1|1];
}
void PushDown(int rt,int m)
{
if(col[rt])
{
col[rt<<1] = col[rt<<1|1] = col[rt];
sum[rt<<1] = (m - (m>>1))*col[rt<<1];
sum[rt<<1|1] = (m>>1)*col[rt<<1|1];
col[rt] = 0;
}
}
void build(int l,int r, int rt)
{
sum[rt] = 1;
col[rt] = 0;
if(l==r) return ;
int m = (l+r)>>1;
build(lson);
build(rson);
Pushup(rt);
}
void update(int L,int R,int c,int l,int r,int rt)
{
if(L<=l&&r<=R)
{
col[rt] = c;
sum[rt] = (r - l + 1)*c;
return ;
}
PushDown(rt, r - l + 1);
int m = (l+r)>>1;
if(L<=m)
update(L,R,c,lson);
if(R>m)
update(L,R,c,rson);
Pushup(rt);
}
int main()
{
int t;
int n,m;
int X,Y,Z;
scanf("%d",&t);
for(int i = 1;i<=t;i++)
{
scanf("%d%d",&n,&m);
build(1,n,1);
for(int j = 0;j<m;j++)
{
scanf("%d%d%d",&X,&Y,&Z);
update(X,Y,Z,1,n,1);
}
printf("Case %d: The total value of the hook is %d.\n",i,sum[1]);
}
return 0;
}
0 0
- HDOJ 1698 (线段树)
- HDU 1698 线段树
- hdoj 1698 线段树
- hdu~1698~线段树
- HDU 1698 线段树
- HDU 1698 线段树
- hdu 1698 线段树
- HDOJ 1698-----线段树
- (1698)线段树
- poj 1698 线段树
- [线段树] HDU 1698
- 线段树?线段树!
- 线段树?线段树!
- 线段_线段树
- 线段_线段树
- hdu 1698 线段树(修改线段值)
- HDU-1698(线段树入门)
- hdu 1698 (线段树)
- 细说 iOS 消息推送
- WIN7(32位)VS2010+openCV 2.4.10+PCL 1.6.0+CUDA 6.5.14+CMake 3.2.1+SSBA-3.0配置
- 日经社説 20150409 看過できぬ株式新規公開の規律の緩み
- cocos2d-x 学习过程错误记录--Expression: animation!=nullptr
- 创建连接握手状态图
- (1698)线段树
- 文档模式
- Ubuntu系统编写shell脚本程序一次安装多个软件包
- IntelliJ IDEA14.1配置c3p0jar包
- java 微信授权后获取微信用户信息昵称乱码问题 解决
- note-4-9
- struts环境搭建
- Spark安装与学习
- C语言中正确使用输入函数scanf