首页 > 其他 > 详细

hpu校赛--雪人的高度(离散化线段树)

时间:2015-12-06 00:01:04      阅读:309      评论:0      收藏:0      [点我收藏+]

1721: 感恩节KK专场——雪人的高度

时间限制: 1 Sec  内存限制: 128 MB 提交: 81  解决: 35 [提交][状态][讨论版]

题目描述

大雪过后,KK决定在春秋大道的某些区间上堆雪人。现在KK遇到了一道统计雪人高度的难题,请你帮帮他吧。注:KK堆雪人前春秋大道上是没有雪人的即所有位置雪人高度为0。

输入

给定一个整数t,表示有t(t<=5)组测试数据。每组测试数据有两个整数N(1<=N<=200000),表示N次操作。

操作分四种:    U1 x y v   [x, y]位置的雪人高度减v

   U2 x y v   [x, y]位置的雪人高度加v

   Q1 x y     查询[x, y]之间雪人的最大高度    Q2 x y     查询[x, y]之间雪人的最小高度

   注: (|x|, |y|<=2^30, |v|<=100)

 

   若上面的操作使某个位置的雪人高度为负,我们认为这种情况是合法的。

输出

对每个查询输出结果,结果占一行。结果保证不会超int。

样例输入

1
2
U2 -1000 1000 1
Q1 1000 10001

样例输出

1
写了一半,现扔着
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
#include<set>
using namespace std;
#define mem(x,y) memset(x,y,sizeof(x))
#define lson root<<1,l,mid
#define rson root<<1,mid+1,r
#define V(root) tree[root].v
#define HI(root) tree[root].hi
#define LW(root) tree[root].lw
#define LAZY(root) tree[root].lazy
#define pushup1 HI=max(tree[root<<1].v,tree[root<<1|1].v)
#define pushup2 LW=min(tree[root<<1].v,tree[root<<1|1].v)
#define ll root<<1
#define rr root<<1|1
const int MAXN=400000;
typedef long long LL;
struct Node{
	LL hi,lw;
	int lazy;
};
Node tree[MAXN<<2];
void pushdown(int root){
	if(LAZY(root)){
		LAZY(ll)+=LAZY(root);
		LAZY(rr)+=LAZY(root);
		HI(ll)+=LAZY(root);
		HI(rr)+=LAZY(root);
		LW(ll)+=LAZY(root);
		LW(rr)+=LAZY(root);
		LAZY(root)=0;
	}
}
void update(int L,int R,int v,int root,int l,int r){
	int mid=(l+r)>>1;
	if(l>=L&&r<=R){
		LAZY(root)+=v;
		VAL(root)=v;
		HI(root)+=v;
		LW(root)+=v;
		return ;
	}
	pushdown(root);
	if(mid>=R)update(L,R,v,lson);
	else if(mid<L)update(L,R,v,rson);
	else{
		update(L,mid,v,lson);
		update(mid+1,R,v,rson);
	}
	push1;push2;
}
void query(int x,int y,int root,int l,int r){
	int mid=(l+r)>>1;
	if(l>=x&&r<=y){
		mi=min(mi,LW(root));
		mx=max(mx,HI(root));
		return;
	}
	pushdown(root);
	if(mid>=x)query(x,y,lson);
	if(mid<y)qiery(x,y,rson);
}
int main(){
	int T,N,x,y,v;
	char s[5];
	scanf("%d",&T);
	while(T--){
		scanf("%d",&N);
		for(int i=0;i<N;i++){
			scanf("%s",s);
			if(strcmp(s,"U1")){
				scanf("%d%d%d",&x,&y,&v);
				
			}
		}
	}
	return 0;
}

  

hpu校赛--雪人的高度(离散化线段树)

原文:http://www.cnblogs.com/handsomecui/p/5022461.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!