This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define erorp(x) cout<<#x<<"={"<<(x.F)<<" , "<<x.S<<"}"<<endl;
#define print(v,r) f(i,0,r) cout<<v[i]<<" "; cout<<endl;
#define Get(x,y) scanf("%I64d%I64d",&x,&y);
#define is_bit(x,y) (x%(1<<(y+1))>=(1<<y))
#define eror(x) cout<<#x<<'='<<(x)<<endl;
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define Gett(x,y) scanf("%d%d",&x,&y);
#define f(i,a,b) for(int i=a;i<b;i++)
#define get(x) scanf("%I64d",&x);
#define gett(x) scanf("%d",&x);
#define maxm(a,b) a=max(a,b);
#define minm(a,b) a=min(a,b);
#define Add(x,y) x=(x+y)%mod
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define F first
#define S second
const int maxn=1e5+9;
int N,X[maxn],Y[maxn];
ll ans;
pair<int,int> a[maxn];
map<pair<int,int>,int> mark,cnt;
ll e(int x){
return 1ll*x*(x-1)/2;
}
void swap(){
f(i,0,N) swap(a[i].F,a[i].S);
}
void solve(){
mark.clear();
sort(a,a+N);
f(i,0,N){
int x=a[i].F,y=a[i].S;
mark[mp(x,y)]=mark[mp(x,y-1)]+1;
if(a[i+1].F!=x || a[i+1].S!=y+1){
cnt[mp(x,y)]=cnt[mp(x-1,y)];
ans+=e(N);
ans-=e(cnt[mp(x,y)])+e(N-cnt[mp(x,y)]-mark[mp(x,y)]);
cnt[mp(x,y)]+=mark[mp(x,y)];
}
for(int j=i-1;0<=j && a[j].F==a[j+1].F && a[j].S+1==a[j+1].S;j--)
cnt[mp(a[j].F,a[j].S)]=cnt[mp(x,y)];
}
}
int DistanceSum(int N, int *X, int *Y){
f(i,0,N) a[i]=mp(X[i],Y[i]);
solve();
swap();
solve();
return ans-(e(N));
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |