Submission #6701344


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;
}
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;
}

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, X[200000], Y[200000];
    cin >> N;
    map<int, int> xs, ys;
    for(int i=0; i<N; i++){
        cin >> X[i] >> Y[i];
        xs[X[i]] = 0;
        ys[Y[i]] = 0;
    }
    int sz = 0;
    for(auto p : xs) xs[p.first] = sz++;
    sz = 0;
    for(auto p : ys) ys[p.first] = sz++;
    for(int i=0; i<N; i++){
        X[i] = xs[X[i]];
        Y[i] = ys[Y[i]];
    }
    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]; });

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

    int64_t ans = 0;
    for(int i : order){
        int y = Y[i];
        bit_aft.plus(y, -1);
        int A = bit_bef.sum_between(0, y), B = bit_bef.sum_between(y, N-1);
        int C = bit_aft.sum_between(0, y), D = bit_aft.sum_between(y, N-1);

        add(ans, power_mod(2, N-1));
        add(ans, (power_mod(2, A)-1) * (power_mod(2, D)-1) % MOD * power_mod(2, B) % MOD * power_mod(2, C) % MOD);
        add(ans, power_mod(2, A) * power_mod(2, D) % MOD * (power_mod(2, B)-1) % MOD * (power_mod(2, C)-1) % MOD);
        add(ans, MOD - (power_mod(2, A)-1) * (power_mod(2, D)-1) % MOD * (power_mod(2, B)-1) % MOD * (power_mod(2, C)-1) % MOD);
        bit_bef.plus(y, 1);
    }
    cout << ans << endl;
    return 0;
}

Submission Info

Submission Time
Task F - Enclosed Points
User betrue12
Language C++14 (GCC 5.4.1)
Score 600
Code Size 2715 Byte
Status AC
Exec Time 837 ms
Memory 24960 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 832 ms 22528 KB
12.txt AC 751 ms 22144 KB
13.txt AC 788 ms 22912 KB
14.txt AC 708 ms 21760 KB
15.txt AC 792 ms 22912 KB
16.txt AC 797 ms 22912 KB
17.txt AC 837 ms 22912 KB
18.txt AC 807 ms 22912 KB
19.txt AC 660 ms 22784 KB
20.txt AC 633 ms 22528 KB
21.txt AC 748 ms 22912 KB
22.txt AC 717 ms 24960 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