hdu 1823 Luck and Love

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1823

题目大意:
I H A L: 把(H,A)处的值设为L.
Q H1 H2 A1 A2 :求(H1,A1)--->(H2,A2)中的最大值.

题目思路: 
100<=H<=200 , 0<=A*10<=1000,  果断的二维单点线段树.

代码:

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <math.h>
#include <time.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;

#define ull unsigned __int64
#define ll __int64
//#define ull unsigned long long
//#define ll long long
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define middle (l+r)>>1
#define MOD 1000000007
#define esp (1e-4)
const int INF=0x3F3F3F3F;
const double DINF=10001.00;
//const double pi=acos(-1.0);
const int N=110,M=1010;
int n,m;
int mmax[N<<2][M<<2];
char op[2];

void PushUp(int x,int rt){
	mmax[x][rt]=max(mmax[x][rt<<1],mmax[x][rt<<1|1]);
}

void yUpdate(int l,int r,int rt,int xrt,int y,int c){
	if(l==r){
		mmax[xrt][rt]=max(mmax[xrt][rt],c);
		return;
	}
	int mid=middle;
	if(y<=mid) yUpdate(lson,xrt,y,c);
	else yUpdate(rson,xrt,y,c);
	PushUp(xrt,rt);
}

void xUpdate(int l,int r,int rt,int x,int y,int c){
	yUpdate(0,1000,1,rt,y,c);
	if(l==r) return;
	int mid=middle;
	if(x<=mid) xUpdate(lson,x,y,c);
	else xUpdate(rson,x,y,c);
}

int yQuery(int l,int r,int rt,int xrt,int L,int R){
	if(L<=l && r<=R) return mmax[xrt][rt];
	int mid=middle,ret=-1;
	if(L<=mid) ret=max(ret,yQuery(lson,xrt,L,R));
	if(mid<R) ret=max(ret,yQuery(rson,xrt,L,R));
	return ret;
}

int xQuery(int l,int r,int rt,int L,int R,int yL,int yR){
	if(L<=l && r<=R) return yQuery(0,1000,1,rt,yL,yR);
	int mid=middle,ret=-1;
	if(L<=mid) ret=max(ret,xQuery(lson,L,R,yL,yR));
	if(mid<R) ret=max(ret,xQuery(rson,L,R,yL,yR));
	return ret;
}

int main(){
	//freopen("1.in","r",stdin);
	//freopen("1.out","w",stdout);
	int i,j,k,H1,H2;
	double A1,A2,L;
	//int T,cas;scanf("%d",&T);for(cas=1;cas<=T;cas++)
	while(~scanf("%d",&m) && m){
		memset(mmax,-1,sizeof(mmax));//double不可以这样直接赋为-1,会出问题滴.
		while(m--){
			scanf("%s",op);
			if(op[0]=='I'){
				scanf("%d%lf%lf",&H1,&A1,&L);
				xUpdate(100,200,1,H1,A1*10,L*10);
			}else{
				scanf("%d%d%lf%lf",&H1,&H2,&A1,&A2);
				if(H1>H2) swap(H1,H2);
				if(A1>A2) swap(A1,A2);
				L=xQuery(100,200,1,H1,H2,A1*10,A2*10);
				if(L>=0) printf("%.1lf\n",L/10);
				else puts("-1");
			}
		}
	}
	return 0;
}


你可能感兴趣的:(hdu 1823 Luck and Love)