题目大意
Kanade has an infinity set
H:{{(a,b) | a≥x,b∈[y1,y2]} | y1∈R,y2∈R,x∈R,y1≤y2}
H
:
{
{
(
a
,
b
)
|
a
≥
x
,
b
∈
[
y
1
,
y
2
]
}
|
y
1
∈
R
,
y
2
∈
R
,
x
∈
R
,
y
1
≤
y
2
}
A point set
S
S
is good if and only if for each subset of
S
S
there exist satisfy
h∩S=T
h
∩
S
=
T
。
Now kanade has n distinct points and she want to know how many non-empty subset of these points is
good.
(真的不是我懒啊,我也转述不明白这个定义orz)
解题思路
对于 |S|=1,他显然是好的
对于 |S|=2,只要两个点的 y 坐标不相同,那么这个集合也是好的
对于 |S|=3,三个点的形状必须是 < 型
对于 |S|>3,不可能任何三个点都是 < 型,所以一定不是好的
枚举 < 型里顶点上的点,用树状数组维护 y 轴区间上点的个数,那么每个顶点对应的答案就应该是 y 坐标大于该顶点的点的个数 cnt1 与 y 坐标小于该顶点的点的个数 cnt2 的乘积。
记得把 y 坐标相同的 |S|=2 的集合减去。
不瞒你们说,这道题是用自信过掉的。
代码
#include <bits/stdc++.h>
using namespace std;
const int moder=998244353;
inline int add(const int &a,const int &b) {return (a+b<moder)?a+b:a+b-moder;}
inline int mul(const int &a,const int &b) {return 1ll*a*b%moder;}
inline int les(const int &a,const int &b) {return (a>=b)?a-b:a-b+moder;}
inline int read() {
register int val=0, sign=1; char ch;
while(~(ch=getchar()) && (ch<'0' || ch>'9') && ch!='-'); ch=='-'?sign=-1:val=ch-'0';
while(~(ch=getchar()) && (ch>='0' && ch<='9')) val=(val<<1)+(val<<3)+ch-'0';
return val*sign;
}
#define x first
#define y second
const int maxn=int(1e5)+111;
typedef pair<int,int> pii;
int n;
int sta[maxn], top;
pii p[maxn];
bool cmp(const pii &a,const pii &b) {
if(a.x==b.x) return a.y<b.y;
return a.x>b.x;
}
#define lowbit(k) ((k)&(-(k)))
int sum[maxn];
void modify(int pos) {
for(;pos<=n;sum[pos]++,pos+=lowbit(pos));
return;
}
int query(int pos) {
int res=0;
for(;pos>0;res+=sum[pos],pos-=lowbit(pos));
return res;
}
void work() {
n=read();
register int i;
for(i=1;i<=n;++i) {
p[i].x=read(), p[i].y=read();
sta[i]=p[i].y;
}
sort(p+1,p+1+n,cmp);
sort(sta+1,sta+1+n);
top=unique(sta+1,sta+1+n)-(sta+1);
for(i=1;i<=n;++i)
p[i].y=lower_bound(sta+1,sta+1+top,p[i].y)-sta;
int ans=0, pos=0;
for(i=1;i<=n+1;++i) {
if(i>1 && p[i].x!=p[pos=i-1].x) {
while(pos>=1 && p[pos].x==p[i-1].x)
modify(p[pos--].y);
}
if(i>n) break;
int cnt1=query(p[i].y-1);
int cnt2=query(top)-query(p[i].y);
ans=add(ans,mul(cnt1,cnt2));
}
ans=add(ans,n);
if(n&1) ans=add(ans,mul(n,(n-1)/2));
else ans=add(ans,mul(n/2,n-1));
for(i=1;i<=top;++i) {
int cnt=query(i)-query(i-1);
if(cnt==1) continue;
if(cnt&1) ans=les(ans,mul(cnt,(cnt-1)/2));
else ans=les(ans,mul(cnt/2,cnt-1));
}
printf("%d\n",ans);
return;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
#endif
work();
return 0;
}