【atcoder】Enclosed Points [abc136F]

  Topic Portal: https://atcoder.jp/contests/abc136/tasks/abc136_f

  Title effect: n-$ $ points have us define a set of points on a plane including a weight of the number of points is the smallest rectangle that contains the set of points (side of the rectangle parallel to the coordinate axes) on a plane, require that all non- the empty weight and the set point, to ensure that horizontal and vertical coordinates of each point different from each other.

  Consider converting it, ask each point is how many points rectangle set $ S $ contains, if we consider the current point $ i $, it can be divided into two cases: $ i \ in S $ or $ i \ notin S $.

    1. For $ i \ in the case of S $, $ I $ point is easy to find all contribute to the set of points comprising the $ I $, where the contribution of $ 2 ^ (n-1) $.

    2. For the $ I \ notin S $ case, since the vertical and horizontal coordinates of each point different from each other, so that the whole point $ I $ coordinate system is divided into four regions

    If the set point then the $ $ rectangle including the point S $ i $, then there must be $ p, q \ in S, p \ in A, q \ in D $ or $ p \ in B, q \ in D $.

    The number of points set $ A $ region is $ a $, the number of points $ B $ region is $ b $, the number of points $ C $ region is $ c $, the number of points $ D $ region is $ d $, inclusion and exclusion understood contribution here is $ (2 ^ a-1) 2 ^ b2 ^ c (2 ^ d-1) + 2 ^ a (2 ^ b-1) (2 ^ c-1) 2 ^ d- (2 ^ a-1) (2 ^ b-1) (2 ^ c-1) (2 ^ d-1) $.

  Fenwick tree after a maintenance area is calculated for each point may be ordered discrete points, then the problem can be solved $ O (n \ log n) $ at time complexity.

  Code:

#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#define ll long long
#define mod 998244353
#define maxn 200010
inline ll read()
{
    ll x=0; char c=getchar(),f=1;
    for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
    for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
    return x*f;
}
inline void write(ll x)
{
    static char buf[20],len; len=0;
    if(x<0)x=-x,putchar('-');
    for(;x;x/=10)buf[len++]=x%10+'0';
    if(!len)putchar('0');
    else while(len)putchar(buf[--len]);
}
inline void writesp(ll x){write(x); putchar(' ');}
inline void writeln(ll x){write(x); putchar('\n');}
struct Data{
    int x,id;
}num[maxn];
struct point{
    int x,y,rk;
}a[maxn];
int n;
bool cmp1(Data a,Data b){return a.x<b.x;}
bool cmp2(point a,point b){return a.x<b.x;}
inline ll power(ll a,ll b)
{
    ll ans=1;
    for(;b;b>>=1,a=a*a%mod)
        if(b&1)ans=ans*a%mod;
    return ans;
}
int bit1[maxn],bit2[maxn];
void add1(int x,int k){for(;x<=n;x+=x&(-x))bit1[x]+=k;}
int getsum1(int x){int sum=0; for(;x;x-=x&(-x))sum+=bit1[x]; return sum;}
void add2(int x,int k){for(;x<=n;x+=x&(-x))bit2[x]+=k;}
int getsum2(int x){int sum=0; for(;x;x-=x&(-x))sum+=bit2[x]; return sum;}
int main()
{
    n=read();
    for(int i=1;i<=n;i++){
        a[i].x=read(); a[i].y=read();
        num[i].x=a[i].y; num[i].id=i;
    }
    std::sort(num+1,num+n+1,cmp1);
    for(int i=1;i<=n;i++)
        a[num[i].id].rk=i;
    std::sort(a+1,a+n+1,cmp2);
    for(int i=1;i<=n;i++)
        bit1[i]=0,bit2[i]=i&(-i);
    ll ans=0;
    for(int i=1;i<=n;i++){
        add2(a[i].rk,-1);
        int A=getsum1(a[i].rk),B=getsum1(n)-getsum1(a[i].rk),C=getsum2(a[i].rk),D=getsum2(n)-getsum2(a[i].rk);
        ll totA=power(2,A),totB=power(2,B),totC=power(2,C),totD=power(2,D);
        ans=(ans+(totA-1)*totB%mod*totC%mod*(totD-1))%mod;
        ans=(ans+totA*(totB-1)%mod*(totC-1)%mod*totD)%mod;
        ans=(ans-(totA-1)*(totB-1)%mod*(totC-1)%mod*(totD-1)%mod+mod)%mod;
        ans=(ans+power(2,n-1))%mod;
        add1(a[i].rk,1);
    }
    writeln(ans);
    return 0;
}
abc136F

 

Guess you like

Origin www.cnblogs.com/quzhizhou/p/11300139.html