标签:tor end pictures single accept gnu order ima rap
Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 6332 Accepted Submission(s): 2951
代码如下
#include <map> #include <set> #include <cmath> #include <ctime> #include <stack> #include <queue> #include <cstdio> #include <cctype> #include <bitset> #include <string> #include <vector> #include <cstring> #include <iostream> #include <algorithm> #include <functional> #define fuck(x) cout<<"["<<x<<"]"; #define FIN freopen("input.txt","r",stdin); #define FOUT freopen("output.txt","w+",stdout); #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; typedef long long LL; typedef pair<int, int> PII; const int maxn = 1e5+5; struct node1{ int l,r; int cover; int len; int lbt,rbt; int segnum; }st[maxn<<2]; struct node2{ int x,y1,y2; int flag; }edge[maxn]; int Y[maxn]; void build(int root,int l,int r){ st[root].l=l; st[root].r=r; st[root].cover=st[root].len=0; st[root].lbt=st[root].rbt=0; st[root].segnum=0; if(r-l==1) return; int mid=(l+r+1)/2; build(root<<1,l,mid); build(root<<1|1,mid,r); } void update(int root){ if(st[root].cover>0){ st[root].len=Y[st[root].r]-Y[st[root].l]; st[root].lbt=st[root].rbt=1; st[root].segnum=1; }else if(st[root].r-st[root].l==1){ st[root].len=0; st[root].lbt=st[root].rbt=0; st[root].segnum=0; }else{ st[root].len=st[root<<1].len+st[root<<1|1].len; st[root].lbt=st[root<<1].lbt; st[root].rbt=st[root<<1|1].rbt; st[root].segnum=st[root<<1].segnum+st[root<<1|1].segnum-st[root<<1].rbt*st[root<<1|1].lbt; } } void update(int root,int val,int y1,int y2){ if(y1<=Y[st[root].l]&&Y[st[root].r]<=y2){ st[root].cover+=val; }else{ int mid=(st[root].l+st[root].r+1)/2; if(y1<Y[mid]) update(root<<1,val,y1,y2); if(y2>Y[mid]) update(root<<1|1,val,y1,y2); } update(root); } bool cmp(node2 a,node2 b){ if(a.x==b.x) return a.y1<b.y1; return a.x<b.x; } int main(){ #ifndef ONLINE_JUDGE FIN #endif int n; while(scanf("%d",&n) !=EOF){ if(n==0) printf("0\n"); int x1,x2,y1,y2; for(int i=0;i<n;i++){ scanf("%d%d%d%d",&x1,&y1,&x2,&y2); edge[i<<1].x=x1; edge[i<<1].y1=y1; edge[i<<1].y2=y2; edge[i<<1].flag=1; Y[i<<1]=y1; edge[i<<1|1].x=x2; edge[i<<1|1].y1=y1; edge[i<<1|1].y2=y2; edge[i<<1|1].flag=-1; Y[i<<1|1]=y2; } sort(Y,Y+2*n); sort(edge,edge+2*n,cmp); int cnt=0; for(int i=0;i<2*n;i++){ if(Y[i]!=Y[i+1]) Y[cnt++]=Y[i]; } Y[cnt++]=Y[2*n-1]; build(1,0,cnt-1); int ans=0; int lastlen=0; for(int i=0;i<2*n-1;i++){ update(1,edge[i].flag,edge[i].y1,edge[i].y2); ans+=2*st[1].segnum*(edge[i+1].x-edge[i].x); ans+=abs(st[1].len-lastlen); lastlen=st[1].len; } ans+=(edge[2*n-1].y2-edge[2*n-1].y1); printf("%d\n",ans); } return 0; }
标签:tor end pictures single accept gnu order ima rap
原文地址:https://www.cnblogs.com/buerdepepeqi/p/9374499.html