标签:
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4135 Accepted Submission(s): 2041
2 5 1 1 4 2 1 3 3 7 2 1.5 5 4.5 3.5 1.25 7.5 4 6 3 10 7 3 0 0 1 1 1 0 2 1 2 0 3 1
7.63 0.00
我对我的线段树很有自信,直接cin
#include<map> #include<string> #include<cstring> #include<cstdio> #include<cstdlib> #include<cmath> #include<queue> #include<vector> #include<iostream> #include<algorithm> #include<bitset> #include<climits> #include<list> #include<iomanip> #include<stack> #include<set> using namespace std; double hs[2010]; struct Tree { int l,r,num; double val,len; }tree[2000<<2]; void create(int l,int r,int k) { tree[k].l=l; tree[k].r=r; tree[k].num=0; tree[k].val=tree[k].len=0; if(l+1==r) return; int m=l+r>>1; create(l,m,k<<1); create(m,r,k<<1|1); } void update(int l,int r,int k,int flag) { if(tree[k].l==l&&tree[k].r==r) { tree[k].num+=flag; if(tree[k].num==0) { tree[k].val=l+1==r?0:tree[k<<1].val+tree[k<<1|1].val; tree[k].len=l+1==r?0:tree[k<<1].len+tree[k<<1|1].len; } else { tree[k].val=hs[r]-hs[l]; if(tree[k].num==1) tree[k].len=l+1==r?0:tree[k<<1].val+tree[k<<1|1].val; else tree[k].len=hs[r]-hs[l]; } return; } int m=tree[k].l+tree[k].r>>1; if(r<=m) update(l,r,k<<1,flag); else if(l>=m) update(l,r,k<<1|1,flag); else { update(l,m,k<<1,flag); update(m,r,k<<1|1,flag); } if(tree[k].num==0) { tree[k].val=tree[k<<1].val+tree[k<<1|1].val; tree[k].len=tree[k<<1].len+tree[k<<1|1].len; } else if(tree[k].num==1) tree[k].len=tree[k<<1].val+tree[k<<1|1].val; } struct Seg { int flag; double l,r,y; bool operator <(Seg one)const { return y<one.y; } }seg[2010]; int main() { int T; cin>>T; while(T--) { int n; cin>>n; vector<double>box; for(int i=0;i<n;i++) { double x1,y1,x2,y2; cin>>x1>>y1>>x2>>y2; seg[i<<1].l=seg[i<<1|1].l=x1; seg[i<<1].r=seg[i<<1|1].r=x2; seg[i<<1].y=y1; seg[i<<1|1].y=y2; seg[i<<1].flag=1; seg[i<<1|1].flag=-1; box.push_back(x1); box.push_back(x2); } sort(box.begin(),box.end()); box.erase(unique(box.begin(),box.end()),box.end()); for(int i=0;i<box.size();i++) hs[i+1]=box[i]; n*=2; sort(seg,seg+n); double ans=0; create(1,box.size(),1); for(int i=0;i<n;i++) { int l=1+lower_bound(box.begin(),box.end(),seg[i].l)-box.begin(); int r=1+lower_bound(box.begin(),box.end(),seg[i].r)-box.begin(); if(i!=n-1) { update(l,r,1,seg[i].flag); ans+=tree[1].len*(seg[i+1].y-seg[i].y); } } printf("%.2f\n",ans); } }
标签:
原文地址:http://blog.csdn.net/stl112514/article/details/45793155