Zoj 3157 weapon Inverse number/tree array

Source: Internet
Author: User

B-weaponTime limit:1000MS Memory Limit:32768KB 64bit IO Format:%lld &%llu Submit Status

Description

In the World War 3, your countries ' scientists has invented a special weapon. Assume that the enemy's city can is described by rectangular coordinates and it has N roads which is all lines . None of the road is paralled with Y-axis. Besides, each road was represented by and different points (ai,bi) (ci,di) on I T. Any three roads won't intersect at one point.

This special weapon can destroy all the castles whose x coordinate belongs to (l,r). After spying, you know the "all the" The castles is set in the "crossing point of" and "roads" and "crossing" is A castle. In addition, each road's end-point ' s X coordinate does not belong to (l,r).

The scientists want to check the weapon ' s effect. If its effect can not reach army ' s expectation, they has to spend more time and more money in expanding its range. Obviously, the number of castles it can destroy plays an important role on the effect. So is asked to calculate how many castles can is destroyed by this special weapon.

Input

Input contains multiple cases.

Every test case, the first line was an integers n (2 <= n <= 10000). then n lines follow. The (i+1)-th line contains four integers ai,bi,ci,di ( -1E8 <= Ai,bi,ci,di <= 1E8). The (n+2)-th line contains-doubles l,r ( -1E8 <= l,r <= 1E8) There is a blank line between Cases.

Output

For each case, the output of the number of castles is destroyed by the weapon.

Sample Input

30 0 1 12 0 1 10 0 2 00 2.5

Sample Output

2
#include <cstdio>#include<cmath>#include<cstring>#include<ctime>#include<iostream>#include<algorithm>#include<Set>#include<vector>#include<sstream>#include<queue>#include<typeinfo>#include<fstream>typedefLong Longll;using namespacestd;//freopen ("d.in", "R", stdin);//freopen ("D.out", "w", stdout);#defineSspeed ios_base::sync_with_stdio (0); Cin.tie (0)#defineMAXN 10001#defineEPS 1e-6Const intinf=0x7fffffff;//infinitely LargeintN;structnode{Doublex; Doubley;};DoubleD[maxn];node Point1[maxn],point2[maxn];node KISS[MAXN],KILL[MAXN];intLowbit (intx) {    returnx& (-x);}voidUpdate1 (intx) {     while(x<=N) {d[x]++; X+=lowbit (x); }}voidUpdate2 (intXintnum) {     while(x>0) {D[x]+=num; X-=lowbit (x); }}intGETSUM1 (intx) {    ints=0;  while(x>0) {s+=D[x]; X-=lowbit (x); }    returns;}BOOLCMP (node X,node y) {if(x.x==y.x)returnx.y<y.y; returnx.x<y.x;}intMain () {sspeed; intN;  while(cin>>N) {memset (d,0,sizeof(d)); N=N;  for(intI=0; i<n;i++) {cin>>point1[i].x>>point1[i].y>>point2[i].x>>point2[i].y; }        DoubleL,r; CIN>>l>>R; L+=EPS; R-=EPS;  for(intI=0; i<n;i++)        {            DoubleK; K= (POINT2[I].Y-POINT1[I].Y)/(point2[i].x-point1[i].x); kill[i].x=k* (l-point2[i].x) +point2[i].y; Kill[i].y=k* (r-point2[i].x) +point2[i].y;//Find out} ll ans=0; Sort (Kill,kill+n,cmp);  for(intI=0; i<n;i++) {kiss[i].x=kill[i].y; Kiss[i].y=i+1; } sort (Kiss,kiss+n,cmp);  for(inti=n-1; i>=0; i--) {ans+=getSum1 (KISS[I].Y);        Update1 (KISS[I].Y); } cout<<ans<<Endl; }    return 0;}

Zoj 3157 weapon Inverse number/tree array

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.