Submission #6705215


Source Code Expand

Copy
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
#define Fast_cin ios::sync_with_stdio(false), cin.tie(0);
#define rep(i, a, b) for(register int i = a; i <= b; i++)
#define per(i, a, b) for(register int i = a; i >= b; i--)
using namespace std;

typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef long long ll;

template <typename _T>
inline void read(_T &f) {
    f = 0; _T fu = 1; char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') fu = -1; c = getchar(); }
    while(c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + (c & 15); c = getchar(); }
    f *= fu;
}

template <typename T>
void print(T x) {
    if(x < 0) putchar('-'), x = -x;
    if(x < 10) putchar(x + 48);
    else print(x / 10), putchar(x % 10 + 48);
}

template <typename T>
void print(T x, char t) {
    print(x); putchar(t);
}

template <typename T>
struct hash_map_t {
    vector <T> v, val, nxt;
    vector <int> head;
    int mod, tot, lastv;
    T lastans;
    bool have_ans;

    hash_map_t (int md = 0) {
        head.clear(); v.clear(); val.clear(); nxt.clear(); tot = 0; mod = md;
        nxt.resize(1); v.resize(1); val.resize(1); head.resize(mod);
        have_ans = 0;
    }

    void clear() { *this = hash_map_t(mod); }

    bool count(int x) {
        int u = x % mod;
        for(register int i = head[u]; i; i = nxt[i]) {
            if(v[i] == x) {
                have_ans = 1;
                lastv = x;
                lastans = val[i];
                return 1;
            }
        }
        return 0;
    }

    void ins(int x, int y) {
        int u = x % mod;
        nxt.push_back(head[u]); head[u] = ++tot;
        v.push_back(x); val.push_back(y);
    }

    int qry(int x) {
        if(have_ans && lastv == x) return lastans;
        count(x);
        return lastans;
    }
};

const int N = 2e5 + 5, md = 998244353;

inline int add(int x, int y) {
    x += y;
    if(x >= md) x -= md;
    return x;
}

inline int sub(int x, int y) {
    x -= y;
    if(x < 0) x += md;
    return x;
}

inline int mul(int x, int y) { return 1ll * x * y % md; }

inline int fpow(int x, int y) {
    int ans = 1;
    while(y) {
        if(y & 1) ans = mul(ans, x);
        y >>= 1; x = mul(x, x);
    }
    return ans;
}

struct ele { int x, y, id; } a[N];

int x[N], y[N], tmpx[N], tmpy[N], f[N], v[5][N];
int n, ans;

inline int lowbit(int x) { return x & -x; }

void add(int x) {
    for(register int i = x; i <= n; i += lowbit(i))
        ++f[i];
}

int query(int x) {
    int ans = 0;
    for(register int i = x; i; i ^= lowbit(i))
        ans += f[i];
    return ans;
}

bool cmp(ele a, ele b) { return a.x < b.x; }

int main() {
    read(n);
    for(register int i = 1; i <= n; i++) read(x[i]), read(y[i]), tmpx[i] = x[i], tmpy[i] = y[i];
    sort(tmpx + 1, tmpx + n + 1); sort(tmpy + 1, tmpy + n + 1);
    for(register int i = 1; i <= n; i++) {
        x[i] = lower_bound(tmpx + 1, tmpx + n + 1, x[i]) - tmpx;
        y[i] = lower_bound(tmpy + 1, tmpy + n + 1, y[i]) - tmpy;
        a[i] = (ele) {x[i], y[i], i};
    }
    sort(a + 1, a + n + 1, cmp);
    for(register int i = 1; i <= n; i++) {
        int val = query(a[i].y);
        v[1][a[i].id] = val; v[2][a[i].id] = i - 1 - val;
        add(a[i].y);
    }
    memset(f, 0, sizeof(f));
    for(register int i = n; i >= 1; i--) {
        int val = query(a[i].y);
        v[4][a[i].id] = val; v[3][a[i].id] = n - i - val;
        add(a[i].y);
    }
    for(register int i = 1; i <= n; i++) {
        ans = add(ans, fpow(2, n));
        for(register int j = 1; j <= 4; j++) {
            int go = j + 1;
            if(go == 5) go = 1;
            ans = sub(ans, fpow(2, v[j][i] + v[go][i]));
            ans = add(ans, fpow(2, v[j][i]));
        }
    }
    ans = sub(ans, n);
    print(ans, '\n');
    return 0;
}

Submission Info

Submission Time
Task F - Enclosed Points
User LJC00118
Language C++14 (GCC 5.4.1)
Score 600
Code Size 3964 Byte
Status AC
Exec Time 306 ms
Memory 9600 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 2 ms 6400 KB
02.txt AC 2 ms 6400 KB
03.txt AC 2 ms 6400 KB
04.txt AC 2 ms 6400 KB
05.txt AC 2 ms 6400 KB
06.txt AC 2 ms 6400 KB
07.txt AC 2 ms 6400 KB
08.txt AC 2 ms 6400 KB
09.txt AC 2 ms 6400 KB
10.txt AC 2 ms 6400 KB
11.txt AC 302 ms 9600 KB
12.txt AC 296 ms 9472 KB
13.txt AC 306 ms 9600 KB
14.txt AC 290 ms 9472 KB
15.txt AC 306 ms 9600 KB
16.txt AC 306 ms 9600 KB
17.txt AC 306 ms 9600 KB
18.txt AC 306 ms 9600 KB
19.txt AC 267 ms 9600 KB
20.txt AC 262 ms 9600 KB
21.txt AC 289 ms 9600 KB
22.txt AC 289 ms 9600 KB
23.txt AC 2 ms 6400 KB
s1.txt AC 2 ms 6400 KB
s2.txt AC 2 ms 6400 KB
s3.txt AC 2 ms 6400 KB