Advertisement
Guest User

Untitled

a guest
Mar 24th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define fi first
  4. #define se second
  5.  
  6. using namespace std;
  7.  
  8. int n,i,w,x,y;
  9. vector < pair < pair < int , int > , pair < int ,int > > > all;
  10. long long res,first,secon;
  11.  
  12. bool tmp(pair < pair < int , int > , pair < int , int > > A,pair < pair < int , int > , pair < int , int > > B) {
  13.     if (1LL*A.fi.fi*B.fi.se < 1LL*A.fi.se*B.fi.fi) return true;
  14.     if (1LL*A.fi.fi*B.fi.se > 1LL*A.fi.se*B.fi.fi) return false;
  15.     return A.se<B.se;
  16. }
  17.  
  18. int main() {
  19.     cin>>n>>w;
  20.     for (i=1;i<=n;i++) {
  21.         scanf("%d%d",&x,&y);
  22.         if (x < 0) {
  23.             all.push_back({{-x,y+w},{0,1}});
  24.             all.push_back({{-x,y-w},{1,1}});
  25.         } else {
  26.             all.push_back({{x,-y+w},{0,2}});
  27.             all.push_back({{x,-y-w},{1,2}});
  28.         }
  29.     }
  30.     sort(all.begin(),all.end(),tmp);
  31.     for (i=0;i<all.size();i++) {
  32.         if (all[i].se.se == 1 && all[i].se.fi == 0) {res+=secon;first++;}
  33.         if (all[i].se.se == 2 && all[i].se.fi == 0) {res+=first;secon++;}
  34.         if (all[i].se.se == 1 && all[i].se.fi == 1) first--;
  35.         if (all[i].se.se == 2 && all[i].se.fi == 1) secon--;
  36.     }
  37.     cout<<res<<endl;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement