标签:des style blog http color io os ar java
8 I 160 50.5 60.0 I 165 30.0 80.5 I 166 10.0 50.0 I 170 80.5 77.5 Q 150 166 10.0 60.0 Q 166 177 10.0 50.0 I 166 40.0 99.9 Q 166 177 10.0 50.0 0
80.5 50.0 99.9
//171MS 5900K #include<stdio.h> #include<algorithm> #define M 1007 #define eps 1e-4 using namespace std; char s[7]; struct Sub_Tree { int left,right,ans; int mid(){return (left+right)>>1;} }; struct Tree { int left,right; int mid(){return (left+right)>>1;} Sub_Tree subtree[4*M]; }tree[M]; void build_subtree(int l,int r,int i,int fa) { tree[fa].subtree[i].left=l; tree[fa].subtree[i].right=r; tree[fa].subtree[i].ans=-1; if(l==r)return; int mid=(l+r)>>1; build_subtree(l,mid,i<<1,fa); build_subtree(mid+1,r,i<<1|1,fa); } void build(int l,int r,int i) { tree[i].left=l;tree[i].right=r; build_subtree(0,1000,1,i); if(l==r)return; int mid=(l+r)>>1; build(l,mid,i<<1); build(mid+1,r,i<<1|1); } void up(int i,int fa) { tree[fa].subtree[i].ans=max(tree[fa].subtree[i<<1].ans,tree[fa].subtree[i<<1|1].ans); } void update_subtree(int a,int l,int i,int fa) { if(tree[fa].subtree[i].left==tree[fa].subtree[i].right) { tree[fa].subtree[i].ans=max(tree[fa].subtree[i].ans,l); return; } int mid=tree[fa].subtree[i].mid(); if(a<=mid)update_subtree(a,l,i<<1,fa); else update_subtree(a,l,i<<1|1,fa); up(i,fa); } void update(int h,int a,int l,int i) { update_subtree(a,l,1,i); if(tree[i].left==tree[i].right)return; int mid=tree[i].mid(); if(h<=mid)update(h,a,l,i<<1); else update(h,a,l,i<<1|1); } int query_subtree(int a1,int a2,int i,int fa) { if(tree[fa].subtree[i].left>=a1&&tree[fa].subtree[i].right<=a2)return tree[fa].subtree[i].ans; int mid=tree[fa].subtree[i].mid(); int maxx=-1; if(a1<=mid)maxx=max(maxx,query_subtree(a1,a2,i<<1,fa)); if(mid<a2)maxx=max(maxx,query_subtree(a1,a2,i<<1|1,fa)); return maxx; } int query(int h1,int h2,int a1,int a2,int i) { if(tree[i].left>=h1&&tree[i].right<=h2)return query_subtree(a1,a2,1,i); int mid=tree[i].mid(); int maxx=-1; if(h1<=mid)maxx=max(maxx,query(h1,h2,a1,a2,i<<1)); if(mid<h2)maxx=max(maxx,query(h1,h2,a1,a2,i<<1|1)); return maxx; } int main() { int t; while(scanf("%d",&t),t) { build(100,200,1); int h,h1,h2; double a,a1,a2,l; while(t--) { scanf("%s",s); if(s[0]=='I') { scanf("%d%lf%lf",&h,&a,&l); update(h,int(a*10),int(l*10),1); } else { scanf("%d%d%lf%lf",&h1,&h2,&a1,&a2); if(h1>h2)swap(h1,h2); if(a1>a2)swap(a1,a2); int maxx=query(h1,h2,int(a1*10),int(a2*10),1); if(maxx<0)printf("-1\n"); else printf("%.1f\n",maxx/10.0); } } } return 0; }
HDU 1823 Luck and Love 二维线段树(树套树)
标签:des style blog http color io os ar java
原文地址:http://blog.csdn.net/crescent__moon/article/details/40146129