CF573F
题意 就是用一个上面为空的容器去装点
问你装点有多少种方案
我们先考虑按照y排序
从高往低 因为低的不会影响高的
假设大家高度都不同
对当前高度 如果他左边有 l 个 右边有 r 个
那么他的贡献是 (l+1) + (r+1) +1代表自己不选的选项 那么就很好做了
但是如果高度相同呢?
我们就得从左到右 依次取消前面的影响
也就是你query的时候要query上一个点横坐标加1 到现在这个点横坐标减1的区间
也是十分的骚了
/*
if you can't see the repay
Why not just work step by step
rubbish is relaxed
to ljq
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod = (int)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}
void exgcd(ll a,ll b,ll &x,ll &y,ll &d){if(!b) {d = a;x = 1;y=0;}else{exgcd(b,a%b,y,x,d);y-=x*(a/b);}}//printf("%lld*a + %lld*b = %lld\n", x, y, d);
const int MAX_N = 200025;
const int N = 200001;
namespace sgt
{
#define mid ((l+r)>>1)
int s[MAX_N<<2];
void update(int rt,int l,int r,int x)
{
if(l==r)
{
s[rt] = 1;
return;
}
if(x<=mid) update(rt<<1,l,mid,x);
else update(rt<<1|1,mid+1,r,x);
s[rt] = s[rt<<1]+s[rt<<1|1];
}
int query(int rt,int l,int r,int x,int y)
{
if(x>y) return 0;
if(x<=l&&r<=y)
{
return s[rt];
}
if(x>mid) return query(rt<<1|1,mid+1,r,x,y);
else if(y<=mid) return query(rt<<1,l,mid,x,y);
else return query(rt<<1,l,mid,x,y)+query(rt<<1|1,mid+1,r,x,y);
}
#undef mid
}
struct node
{
int x,y;
bool operator < (const node other) const&
{
if(y==other.y) return x < other.x;
return y >other.y;
}
}arr[MAX_N];
int b[MAX_N],c[MAX_N];
int main()
{
//ios::sync_with_stdio(false);
//freopen("a.txt","r",stdin);
//freopen("b.txt","w",stdout);
int n;
scanf("%d",&n);
for(int i = 1;i<=n;++i)
scanf("%d%d",&arr[i].x,&arr[i].y),b[i] = arr[i].x,c[i] = arr[i].y;
sort(b+1,b+1+n);
sort(c+1,c+1+n);
int sz = unique(b+1,b+1+n)-b-1;
int sz_ = unique(c+1,c+1+n)-c-1;
for(int i = 1;i<=n;++i) arr[i].x = lower_bound(b+1,b+1+sz,arr[i].x)-b;
for(int i = 1;i<=n;++i) arr[i].y = lower_bound(c+1,c+1+sz_,arr[i].y)-c;
sort(arr+1,arr+1+n);
ll ans = 0;
for(int i = 1;i<=n;++i)
{
if(i!=n&&arr[i].y==arr[i+1].y)
{
sgt::update(1,1,N,arr[i].x);
int R = i+1;
while(R<=n&&arr[R].y==arr[i].y)
{
sgt::update(1,1,N,arr[R].x);
R++;
}
int l = sgt::query(1,1,N,1,arr[i].x-1);
int r = sgt::query(1,1,N,arr[i].x+1,N);
ans+=1ll*(l+1)*(r+1);
for(int j = i+1;j<R;++j)
{
int l = sgt::query(1,1,N,arr[j-1].x+1,arr[j].x-1);
int r = sgt::query(1,1,N,arr[j].x+1,N);
ans+=1ll*(l+1)*(r+1);
}
i = R-1;
}
else
{
int l = sgt::query(1,1,N,1,arr[i].x-1);
int r = sgt::query(1,1,N,arr[i].x+1,N);
ans+=1ll*(l+1)*(r+1);
sgt::update(1,1,N,arr[i].x);
}
}
printf("%lld\n",ans);
//fclose(stdin);
//fclose(stdout);
//cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
return 0;
}