【Nowcoder】暑期多校day5 VCD (思维 树状数组)

题目大意

Kanade has an infinity set H:{{(a,b) | ax,b[y1,y2]}  |  y1R,y2R,xR,y1y2} 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 T of S S there exist hH satisfy hS=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;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值