Submission #8375654


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;

const int64_t MOD = 998244353;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

vector<int64_t> fact, seq_inv, fact_inv;

void create_fact_mod(int num){
    fact[0] = fact[1] = 1;
    for(int i=2; i<=num; i++) fact[i] = fact[i-1] * i % MOD;
}

void create_seq_inv_mod(int num){
    seq_inv[0] = seq_inv[1] = 1;
    for(int i=2; i<=num; i++) seq_inv[i] = (MOD - MOD/i) * seq_inv[MOD%i] % MOD;
}

void create_fact_inv_mod(int num){
    fact_inv[0] = fact_inv[1] = 1;
    for(int i=2; i<=num; i++) fact_inv[i] = fact_inv[i-1] * seq_inv[i] % MOD;
}

void create_mod_tables(int num){
    fact.resize(num+1);
    seq_inv.resize(num+1);
    fact_inv.resize(num+1);
    create_fact_mod(num);
    create_seq_inv_mod(num);
    create_fact_inv_mod(num);
}

int64_t comb_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD * fact_inv[k] % MOD;
}

int64_t perm_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD;
}

int64_t power_mod(int64_t num, int64_t power){
    int64_t prod = 1;
    num %= MOD;
    while(power > 0){
        if(power&1) prod = prod * num % MOD;
        num = num * num % MOD;
        power >>= 1;
    }
    return prod;
}

int64_t extgcd(int64_t a, int64_t b, int64_t& x, int64_t& y){
    int64_t d = a;
    if(b != 0){
        d = extgcd(b, a%b, y, x);
        y -= (a/b) * x;
    }else{
        x = 1; y = 0;
    }
    return d;
}

int64_t inv_mod(int64_t a){
    int64_t x, y;
    extgcd(a, MOD, x, y);
    return (MOD + x%MOD) % MOD;
}

template<typename T>
vector<T> compress(vector<T> A){
    sort(A.begin(), A.end());
    A.erase(unique(A.begin(), A.end()), A.end());
    return A;
}

template<typename T>
struct BIT {
    int n;
    vector<T> dat;

    BIT(int n=0){
        initialize(n);
    }

    void initialize(int nin){
        n = nin;
        dat.resize(n, 0);
    }

    T sum(int i){
        T s = 0;
        while(i >= 0){
            s += dat[i];
            i = (i & (i+1)) - 1;
        }
        return s;
    }

    T sum_between(int i, int j){
        return sum(j) - sum(i-1);
    }

    void plus(int i, T x){
        while(i < n){
            dat[i] += x;
            i |= i+1;
        }
    }

    // a[0]+...+a[ret] >= x
    int lower_bound(T x){
        int ret = -1;
        int k = 1;
        while(2*k <= n) k <<= 1;
        for( ;k>0; k>>=1){
            if(ret+k < n && dat[ret+k] < x){
                x -= dat[ret+k];
                ret += k;
            }
        }
        return ret + 1;
    }
};

int main(){
    int N;
    cin >> N;
    vector<int> X(N), Y(N);
    for(int i=0; i<N; i++) cin >> X[i] >> Y[i];
    auto xcmp = compress(X);
    auto ycmp = compress(Y);

    BIT<int> bit_lower(N), bit_upper(N);
    for(int i=0; i<N; i++) bit_upper.plus(i, 1);

    int64_t ans = N*power_mod(2, N-1);
    vector<int> order(N);
    for(int i=0; i<N; i++) order[i] = i;
    sort(order.begin(), order.end(), [&](int i, int j){ return X[i] < X[j]; });
    for(int i : order){
        int y = lower_bound(ycmp.begin(), ycmp.end(), Y[i]) - ycmp.begin();
        bit_upper.plus(y, -1);
        int n1 = bit_lower.sum_between(0, y-1);
        int n2 = bit_lower.sum_between(y+1, N-1);
        int n3 = bit_upper.sum_between(0, y-1);
        int n4 = bit_upper.sum_between(y+1, N-1);
        int64_t v1 = (power_mod(2, n1) - 1) * (power_mod(2, n4) - 1) % MOD * power_mod(2, n2+n3) % MOD;
        int64_t v2 = (power_mod(2, n2) - 1) * (power_mod(2, n3) - 1) % MOD * power_mod(2, n1+n4) % MOD;
        int64_t v3 = (power_mod(2, n1) - 1) * (power_mod(2, n4) - 1) % MOD * (power_mod(2, n2) - 1) % MOD * (power_mod(2, n3) - 1) % MOD;
        add(ans, v1+v2-v3+MOD);
        bit_lower.plus(y, 1);
    }
    cout << ans << endl;
}

Submission Info

Submission Time
Task F - Enclosed Points
User betrue12
Language C++14 (GCC 5.4.1)
Score 600
Code Size 3952 Byte
Status AC
Exec Time 459 ms
Memory 5760 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 26
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt AC 1 ms 256 KB
02.txt AC 1 ms 256 KB
03.txt AC 1 ms 256 KB
04.txt AC 1 ms 256 KB
05.txt AC 1 ms 256 KB
06.txt AC 1 ms 256 KB
07.txt AC 1 ms 256 KB
08.txt AC 1 ms 256 KB
09.txt AC 1 ms 256 KB
10.txt AC 1 ms 256 KB
11.txt AC 443 ms 5632 KB
12.txt AC 449 ms 5504 KB
13.txt AC 459 ms 5760 KB
14.txt AC 433 ms 5504 KB
15.txt AC 452 ms 5760 KB
16.txt AC 455 ms 5760 KB
17.txt AC 457 ms 5760 KB
18.txt AC 453 ms 5760 KB
19.txt AC 332 ms 5760 KB
20.txt AC 334 ms 5632 KB
21.txt AC 386 ms 5760 KB
22.txt AC 386 ms 5760 KB
23.txt AC 1 ms 256 KB
s1.txt AC 1 ms 256 KB
s2.txt AC 1 ms 256 KB
s3.txt AC 1 ms 256 KB