-
-
Save fredbr/342c2b2a88f5e9dafe229e141d6b4b26 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//solucao de Leonardo Paes | |
#include <bits/stdc++.h> | |
using namespace std; | |
#define MAXN 600100 | |
#define PB push_back | |
typedef long long ll; | |
int tree[MAXN], vet[MAXN], n; | |
vector< pair< ll , ll> > m; | |
int sum(int x){ | |
int s=0; | |
while(x>0){ | |
s+=tree[x]; | |
x-=(x&-x); | |
} | |
return s; | |
} | |
void update(int x, int k){ | |
while(x<=n){ | |
tree[x]+=k; | |
x+=(x&-x); | |
} | |
} | |
bool compara(pair<long long, long long> a, pair<long long ,long long> b){ | |
return a.first < b.first; | |
} | |
bool compara2(pair<long long,long long> a, pair<long long ,long long> b){ | |
return a.second < b.second; | |
} | |
int main(){ | |
ios_base::sync_with_stdio(false);cin.tie(NULL); | |
long long resp=0; | |
cin >> n; | |
for(int i=1; i<=n; i++){ | |
long long a, b; | |
cin >> a >> b; | |
m.PB(make_pair(a*a + b*b, i)); | |
} | |
sort(m.begin(), m.end(), compara); | |
int k=1; | |
for(int i=0; i<n; i++){ | |
if(m[i].first==m[i+1].first){ | |
m[i].first = k; | |
} | |
else{ | |
m[i].first = k; | |
k++; | |
} | |
} | |
sort(m.begin(), m.end(), compara2); | |
for(int i=0; i<n; i++){ | |
resp+= sum(m[i].first); | |
update(m[i].first,1); | |
} | |
cout << resp << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment