Farmer John‘s N cows (1 <= N <= 50,000) appear to be stampeding along the road at the front of FJ‘s farm, but they are actually just running in a foot race to see which cow is the fastest. Viewed from above, each cow is represented by a unit-length horizontal line segment, specified by the coordinates of its left corner point at time t=0. For example, (-3,6) would specify a cow who at time t=0 is represented by the segment from (-3,6) to (-2,6). Each cow is moving to the right (in the +x direction) at a certain rate, specified by the integer amount of time it takes her to move 1 unit to the right. FJ is not particularly thrilled that his cows are outside running instead of in the barn producing milk. He plans to admonish them with a stern lecture after the race ends. In order to determine which of his cows are participating in the race, FJ situates himself at (0,0) and looks along a ray extending in the +y direction. As the race unfolds, FJ sees a cow if she is ever the first cow visible along this ray. That is, a cow might not be visible if another cow is "in front" of her during the entire time she crosses FJ‘s line of sight. Please compute the number of cows FJ can see during the entire race.
PoPoQQQ站在原点上向y轴正半轴看,然后有一群羊驼从他眼前飞过。这些羊驼初始都在第二象限,尾巴在(Xi,Yi),头在(Xi+1,Yi),每Ci秒向右走一个单位。
PoPoQQQ能看见一匹羊驼当且仅当它身体任意某部位x坐标为0时,没有其它y坐标小于此羊驼的羊驼身体某部位x坐标为0。
问PoPoQQQ能看见几匹羊驼?
The first line of the input contains N. Each of the following N lines describes a cow with three integers x y r, corresponding to a cow whose left endpoint is at (x,y) at time t=0, moving to the right at a continuous speed of 1 unit of distance every r units of time. The value of x is in the range -1000..-1, the value of y is in the range 1..1,000,000 (and distinct for every cow, to prevent any possible collisions), and the value of r is in the range 1..1,000,000.
A single integer, specifying the number of cows FJ can see during the entire race (from t=0 onward).
1 #include<iostream>
2 #include<cstdio>
3 #include<cstring>
4 #include<algorithm>
5 #include<map>
6 using namespace std;
7 int n,size,cnt,ans;
8 struct dt{
9 int l,r,h;
10 }yt[60010];
11 int f[200010];
12 map<int,int>mp;
13 bool cmp(const dt&aa,const dt&bb){
14 return aa.h<bb.h;
15 }
16 int segtree[400010];
17 int ask(int pl,int pr,int pos,int ll,int rr){
18 if(pl>rr||pr<ll) return 0;
19 if(segtree[pos]) return 0;
20 //if(pl==pr) return 0;手残!!!
21 if(pl<=ll&&pr>=rr){
22 segtree[pos]=1;
23 return 1;
24 }
25 int mid=(ll+rr)>>1;
26 int p1=0,p2=0;
27 if(pl<=mid) p1=ask(pl,pr,pos<<1,ll,mid);
28 if(pr>mid) p2=ask(pl,pr,pos<<1|1,mid+1,rr);
29 segtree[pos]=segtree[pos]|(segtree[pos<<1]&segtree[pos<<1|1]);
30 return p1|p2;
31 }
32 int main(){
33 scanf("%d",&n);
34 f[0]=-1;
35 int x,t;
36 for(int i=1;i<=n;i++){
37 scanf("%d%d%d",&x,&yt[i].h,&t);
38 yt[i].l=(-x-1)*t;
39 yt[i].r=-x*t;
40 f[++cnt]=yt[i].l;
41 f[++cnt]=yt[i].r;
42 }
43 sort(yt+1,yt+n+1,cmp);
44 sort(f+1,f+cnt+1);
45 for(int i=1;i<=cnt;i++)
46 if(f[i]!=f[i-1]) mp[f[i]]=++size;
47 for(int i=1;i<=n;i++){
48 yt[i].l=mp[yt[i].l];
49 yt[i].r=mp[yt[i].r]-1;
50 }
51 for(int i=1;i<=n;i++) ans+=ask(yt[i].l,yt[i].r,1,1,size);
52 printf("%d",ans);
53 return 0;
54 }