Simulation competition I made [amazing]

Source: Internet
Author: User

God (God .*)

Background

Czy find the treasure and get the Dragon Sword and secret! Now he is looking for NTR, his jmars, and revenge ......

Description

Czy learned how to make a "one-day attack". When he launches a one-day attack on a location, a big pitfall will be left on the ground. The circle around the circle is too large to pass. Therefore, each time czy starts a skill, the ground is split. Jmars has a lot of land and it cannot be seen in dozens of cases. Therefore, we can assume that the land size is infinite. Now czy has launched a violent attack on him. He wants to know how many pieces of his land have been cut into after the zeyu attack?

After all, czy is very virtual, so the center is on the X axis. In addition, ensure that all circles do not overlap.

Format

Enter the first row integer N, which indicates that czy has been placed for n times, then one click.

Next n rows, each row has two integers x [I], R [I]. Returns the X [I], 0, which is a one-day hit at the coordinate (X [I], and the radius is R [I].

Output a line, which indicates that the ground is divided into several parts.

Sample Input

4

7 5

-9 11

11 9

0 20

Sample output

6

Data range

For 30% data, n <= 5000

For 100% data, 1 <= n <= 300000,-10 ^ 9 <= x [I] <= 10 ^ 9,1 <= R [I] <= 10 ^ 9.

 

Vijos1883 http://www.cnblogs.com/zhber/p/4064916.html

Consider the contribution of the circle to the answer: when it is not separated along the diameter, the contribution to the answer is 1. If the contribution is 2. Therefore, the tree's left and right endpoints are discrete in ascending order of R, and a line segment tree is used to maintain whether the interval is overwritten. If it is already covered, the contribution is 2; otherwise, the contribution is 1.

  1 #include<cstdio>  2 #include<iostream>  3 #include<cstring>  4 #include<cstdlib>  5 #include<algorithm>  6 #include<cmath>  7 #include<queue>  8 #include<deque>  9 #include<set> 10 #include<map> 11 #include<ctime> 12 #define LL long long 13 #define N 500010 14 #define mod 1000007 15 using namespace std; 16 struct yuan{int x,r,left,right;}a[N];bool operator <(const yuan &a,const yuan &b){return a.r<b.r;} 17 struct ha{int v,next,rnk;}hash[3*N];bool operator <(const ha &a,const ha &b){return a.v<b.v;} 18 struct segtree{int l,r;bool mark;}tree[8*N]; 19 LL ans; 20 int n; 21 int head[mod]; 22 int cnt,mx; 23 int from[3*N]; 24 inline int ins(int w) 25 { 26     int u=w%mod;if (u<0)u+=mod; 27     for (int i=head[u];i;i=hash[i].next) 28       if (hash[i].v==w) return i; 29     hash[++cnt].v=w; 30     hash[cnt].next=head[u]; 31     hash[cnt].rnk=cnt; 32     head[u]=cnt; 33     return cnt; 34 } 35 inline void build(int now,int l,int r) 36 { 37     tree[now].l=l; 38     tree[now].r=r; 39     if (l==r)return; 40     int mid=(l+r)>>1; 41     build(now<<1,l,mid); 42     build(now<<1|1,mid+1,r); 43 } 44 inline void update(int k) 45 {tree[k].mark=tree[k<<1].mark&&tree[k<<1|1].mark;} 46 inline bool query(int now,int l,int r) 47 { 48     int x=tree[now].l,y=tree[now].r; 49     if (x==l&&y==r)return tree[now].mark; 50     int mid=(x+y)>>1; 51     if (r<=mid)return query(now<<1,l,r); 52     else if (l>mid)return query(now<<1|1,l,r); 53     else return query(now<<1,l,mid)&&query(now<<1|1,mid+1,r); 54 } 55 inline void mark(int now,int l,int r) 56 { 57     int x=tree[now].l,y=tree[now].r; 58     if (x==l&&y==r) 59     { 60         tree[now].mark=1; 61         return; 62     } 63     int mid=(x+y)>>1; 64     if (r<=mid)mark(now<<1,l,r); 65     else if (l>mid)mark(now<<1|1,l,r); 66     else 67     { 68         mark(now<<1,l,mid); 69         mark(now<<1|1,mid+1,r); 70     } 71     update(now); 72 } 73 int main() 74 { 75     //freopen("god7.in","r",stdin); 76     //freopen("god .ans","w",stdout); 77     scanf("%d",&n); 78     for(int i=1;i<=n;i++) 79     { 80         scanf("%d",&a[i].x); 81         scanf("%d",&a[i].r); 82         a[i].left=ins(a[i].x-a[i].r); 83         a[i].right=ins(a[i].x+a[i].r); 84     } 85     sort(hash+1,hash+cnt+1); 86     for (int i=1;i<=cnt;i++) 87       from[hash[i].rnk]=i; 88     for (int i=1;i<=n;i++) 89     { 90       a[i].left=from[a[i].left]; 91       a[i].right=from[a[i].right]; 92       if (a[i].right>mx)mx=a[i].right; 93     } 94     sort(a+1,a+n+1); 95     build(1,1,mx); 96     ans=n+1; 97     for (int i=1;i<=n;i++) 98       { 99           if (query(1,a[i].left,a[i].right-1))ans++;100           mark(1,a[i].left,a[i].right-1);101       }102     printf("%I64d\n",ans);103 }
View code

Simulation competition I made [amazing]

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.