Submission #6707106


Source Code Expand

Copy
//#pragma GCC optimize("O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
//#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;

const int N = 2e5 + 5;

int fl[N], fr[N];

void add(int f[], int pos, int val = 1) {
    for (; pos < N; pos |= pos + 1) {
        f[pos] += val;
    }
}

int get(int f[], int pos) {
    int res = 0;
    for (; pos >= 0; pos = (pos & (pos + 1)) - 1) {
        res += f[pos];
    }
    return res;
}

int mod = 998244353;

ll binpow(ll a, ll p) {
    ll res = 1;
    while (p) {
        if (p & 1) {
            (res *= a) %= mod;
        }
        (a *= a) %= mod;
        p >>= 1;
    }
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    vector<int> a(n);
    vector<pair<int, int>> p(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i].first >> p[i].second;
        a[i] = p[i].second;
    }
    sort(a.begin(), a.end());
    map<int, int> mx;
    for (int i = 0; i < n; i++) {
        mx[a[i]] = i;
        add(fr, i);
    }
    for (int i = 0; i < n; i++) {
        p[i].second = mx[p[i].second];
    }
    sort(p.begin(), p.end());
    ll ans = (binpow(2, n) - 1) * n % mod;
    for (int i = 0; i < n; i++) {
        ll cnt[4];
        cnt[0] = get(fl, p[i].second);
        cnt[1] = get(fr, p[i].second) - 1;
        cnt[2] = get(fr, N - 1) - cnt[1] - 1;
        cnt[3] = get(fl, N - 1) - cnt[0];
        for (int j = 0; j < 4; j++) {
            ans = (ans - binpow(2, cnt[j] + cnt[(j + 1) % 4]) + 1 + mod) % mod;
        }
        for (int j = 0; j < 4; j++) {
            ans = (ans + binpow(2, cnt[j]) - 1) % mod;
        }
        add(fl, p[i].second);
        add(fr, p[i].second, -1);
    }
    cout << ans;
    return 0;
}

Submission Info

Submission Time
Task F - Enclosed Points
User meatrow
Language C++14 (GCC 5.4.1)
Score 600
Code Size 1952 Byte
Status AC
Exec Time 723 ms
Memory 13568 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 384 KB
02.txt AC 1 ms 384 KB
03.txt AC 1 ms 384 KB
04.txt AC 1 ms 384 KB
05.txt AC 1 ms 384 KB
06.txt AC 1 ms 384 KB
07.txt AC 1 ms 384 KB
08.txt AC 1 ms 384 KB
09.txt AC 1 ms 384 KB
10.txt AC 1 ms 384 KB
11.txt AC 711 ms 13440 KB
12.txt AC 696 ms 13184 KB
13.txt AC 719 ms 13568 KB
14.txt AC 681 ms 12928 KB
15.txt AC 719 ms 13568 KB
16.txt AC 723 ms 13568 KB
17.txt AC 719 ms 13568 KB
18.txt AC 718 ms 13568 KB
19.txt AC 603 ms 13440 KB
20.txt AC 587 ms 13312 KB
21.txt AC 659 ms 13568 KB
22.txt AC 658 ms 13568 KB
23.txt AC 1 ms 384 KB
s1.txt AC 1 ms 384 KB
s2.txt AC 1 ms 384 KB
s3.txt AC 1 ms 384 KB