hdu 1823 Luck and Love 二维线段树
母线段树每个节点保存一个子线段树。
//#pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<iostream> #include<sstream> #include<cmath> #include<climits> #include<string> #include<map> #include<queue> #include<vector> #include<stack> #include<set> using namespace std; typedef long long ll; typedef pair<int,int> pii; #define pb(a) push_back(a) #define INF 0x1f1f1f1f #define lson idx<<1,l,mid #define rson idx<<1|1,mid+1,r #define PI 3.1415926535898 template<class T> T min(const T& a,const T& b,const T& c) { return min(min(a,b),min(a,c)); } template<class T> T max(const T& a,const T& b,const T& c) { return max(max(a,b),max(a,c)); } void debug() { #ifdef ONLINE_JUDGE #else freopen("d:\\in.txt","r",stdin); // freopen("d:\\out1.txt","w",stdout); #endif } int getch() { int ch; while((ch=getchar())!=EOF) { if(ch!=' '&&ch!='\n')return ch; } return EOF; } const int maxh=110; const int maxa=1100; struct Tree { double maxv[maxh<<2]; int build(int idx,int l,int r) { maxv[idx]=-1; if(l==r)return 0; int mid=(r+l)>>1; build(lson); build(rson); return 0; } int update(int idx,int l,int r,int pos,double v) { if(l==r&&l==pos) { maxv[idx]=max(maxv[idx],v); return 0; } int mid=(r+l)>>1; if(pos<=mid)update(lson,pos,v); else update(rson,pos,v); maxv[idx]=max(maxv[idx<<1],maxv[idx<<1|1]); return 0; } double query(int idx,int l,int r,int tl,int tr) { if(tl<=l&&tr>=r) return maxv[idx]; int mid=(r+l)>>1; double x=-1; if(tl<=mid)x=max(x,query(lson,tl,tr)); if(tr>mid)x= max(x,query(rson,tl,tr)); return x; } }; Tree tree[maxa<<2]; int build(int idx,int l,int r) { tree[idx].build(1,100,200); if(l==r)return 0; int mid=(r+l)>>1; build(lson); build(rson); return 0; } int update(int idx,int l,int r,int a,int h,double v) { tree[idx].update(1,100,200,h,v); if(l==r&&l==a) { return 0; } int mid=(r+l)>>1; if(a<=mid)update(lson,a,h,v); else update(rson,a,h,v); return 0; } double query(int idx,int l,int r,int tla,int tra,int tlh,int trh) { if(tla<=l&&tra>=r) return tree[idx].query(1,100,200,tlh,trh); int mid=(r+l)>>1; double x=-1; if(tla<=mid)x=max(x,query(lson,tla,tra,tlh,trh)); if(tra>mid)x=max(x,query(rson,tla,tra,tlh,trh)); return x; } int main() { // debug(); int n; while(scanf("%d",&n)!=EOF&&n) { build(1,0,1000); for(int i=1;i<=n;i++) { char op[10]; scanf("%s",op); if(op[0]=='I') { int h; double a,v; scanf("%d %lf %lf",&h,&a,&v); update(1,0,1000,(int)((a+0.00001)*10),h,v); }else { int h1,h2; double a1,a2; scanf("%d%d%lf%lf",&h1,&h2,&a1,&a2); if(h1>h2)swap(h1,h2); if(a1>a2)swap(a1,a2); double num=query(1,0,1000,(int)((a1+0.00001)*10),(int)((a2+0.00001)*10),h1,h2); if(num>=0)printf("%.1lf\n",num+0.00001); else printf("-1\n"); } } } return 0; }