http://acm.hdu.edu.cn/showproblem.php?pid=1823
总结:二维线段树最值查询,要注意参数位置,把活跃值乘10变成整数就喝身高组成二维数组了~
#include<algorithm>
#include<set>
#include<vector>
#include<queue>
#include<cmath>
#include<cstring>
#include<iostream>
#include<set>
#include<vector>
#include<queue>
#include<cmath>
#include<cstdio>
#include<map>
#include<stack>
#include<string>
#include<bits/stdc++.h>
using namespace std;
#define sfi(i) scanf("%d",&i)
#define pri(i) printf("%d\n",i)
#define sff(i) scanf("%lf",&i)
#define ll long long
#define ull unsigned long long
#define mem(x,y) memset(x,y,sizeof(x))
#define INF 0x3f3f3f3f
#define eps 1e-16
#define PI acos(-1)
#define lowbit(x) ((x)&(-x))
#define zero(x) (((x)>0?(x):-(x))<eps)
#define fl() printf("flag\n")
#define MOD(x) ((x%mod)+mod)%mod
#define endl '\n'
#define pb push_back
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
const int maxn=1000+9;
const int mod=1e9+7;
inline ll read()
{
ll f=1,x=0;
char ss=getchar();
while(ss<'0'||ss>'9')
{
if(ss=='-')f=-1;ss=getchar();
}
while(ss>='0'&&ss<='9')
{
x=x*10+ss-'0';ss=getchar();
} return f*x;
}
int n,m,k;
int tree[maxn<<2][maxn<<2];
void subbuild(int rt,int l,int r,int t)
{
tree[t][rt]=-1;
if(l!=r)
{
int mid=(l+r)>>1;
subbuild(lson,t);
subbuild(rson,t);
}
}
void build(int rt,int l,int r)
{
subbuild(1,0,n,rt);
if(l!=r)
{
int mid=(l+r)>>1;
build(lson);
build(rson);
}
}
void subupdate(int rt,int l,int r,int y,int t,int val)
{
if(l==r&&l==y) tree[t][rt]=max(val,tree[t][rt]);
else
{
int mid=(l+r)>>1;
if(y<=mid) subupdate(lson,y,t,val);
else subupdate(rson,y,t,val);
tree[t][rt]=max(tree[t][rt<<1],tree[t][rt<<1|1]);
}
}
void update(int rt,int l,int r,int x,int y,int val)
{
subupdate(1,0,n,y,rt,val);//根包含全部子树所以要更新
if(l!=r)
{
int mid=(l+r)>>1;
if(x<=mid) update(lson,x,y,val);
else update(rson,x,y,val);
}
}
int subque(int rt,int l,int r,int LY,int RY,int t)
{
if(LY <= l && RY >= r)
return tree[t][rt];
int mid = (l + r) >> 1;
int ans = -1;
if(LY <= mid) ans =max(ans, subque(lson,LY,RY,t));
if(RY > mid ) ans =max(ans, subque(rson,LY,RY,t));
return ans;
}
int que(int rt,int l,int r,int LX,int RX,int LY,int RY)
{
if(LX <= l && RX >= r)
return subque(1,0,n,LY,RY,rt);
int mid = (l + r) >> 1;
int ans = -1;
if(LX <= mid) ans =max(ans, que(lson,LX,RX,LY,RY));
if(RX > mid ) ans =max(ans, que(rson,LX,RX,LY,RY));
return ans;
}
int main()
{
while(~scanf("%d",&k)&&k)
{
n=1000;
//mem(tree,-1);
build(1,1,200);
while(k--)
{
int h1,h2;
double a1,c1,a2,c2;
char ch[3];
scanf("%s",ch);
if(ch[0]=='I')
{
scanf("%d%lf%lf",&h1,&a1,&c1);
update(1,100,200,h1,a1*10,c1*10);
//cout<<que(1,100,200,h1,h1,a1*10,a1*10)<<endl;
}
else
{
scanf("%d%d%lf%lf",&h1,&h2,&a1,&a2);
if(h1>h2) swap(h1,h2);
if(a1>a2) swap(a1,a2);
double ans=que(1,100,200,h1,h2,a1*10,a2*10);
if(ans==-1) puts("-1");
else
printf("%.1lf\n",ans/10.0);
}
}
}
return 0;
}