Language: C++

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

template <int MOD>
struct ModInt {
    using lint = long long;
    using mint = ModInt<MOD>;

    int val;

    // constructor
    ModInt(lint v = 0) : val(v % MOD) {
        if (val < 0) val += MOD;
    };

    // assignment
    ModInt& operator=(const ModInt& x) {
        if (this != &x) { this->val = x.val; }
        return *this;
    }

    // unary operator
    ModInt operator+() const { return ModInt(val); }
    ModInt operator-() const { return ModInt(MOD - val); }
    ModInt operator~() const {
        // non-recursive extended euclidean algorithm
        int s = val, t = MOD;
        mint sx = 1, sy = 0, tx = 0, ty = 1;
        while (s % t != 0) {
            int div = s / t;
            s -= t * div;
            sx -= tx * div;
            sy -= ty * div;

            std::swap(s, t);
            std::swap(sx, tx);
            std::swap(sy, ty);
        }
        return mint(tx);
    }

    // arithmetic
    ModInt operator+(const ModInt& x) const { return ModInt(*this) += x; }
    ModInt operator-(const ModInt& x) const { return ModInt(*this) -= x; }
    ModInt operator*(const ModInt& x) const { return ModInt(*this) *= x; }
    ModInt operator/(const ModInt& x) const { return ModInt(*this) /= x; }

    // compound assignment
    ModInt& operator+=(const ModInt& x) {
        if ((val += x.val) >= MOD) val -= MOD;
        return *this;
    }
    ModInt& operator-=(const ModInt& x) {
        if ((val -= x.val) < 0) val += MOD;
        return *this;
    }
    ModInt& operator*=(const ModInt& x) {
        val = lint(val) * x.val % MOD;
        return *this;
    }
    ModInt& operator/=(const ModInt& x) { return *this *= ~x; }

    // compare
    bool operator==(const ModInt& b) const { return val == b.val; }
    bool operator!=(const ModInt& b) const { return val != b.val; }

    // I/O
    friend std::ostream& operator<<(std::ostream& os, const ModInt& x) noexcept { return os << x.val; }
};

constexpr int MOD = 998244353;
using mint = ModInt<MOD>;

template <class T, class Int>
T ipow(T b, Int n) {
    T ret = 1;
    while (n > 0) {
        if (n & 1) ret *= b;
        n >>= 1;
        b *= b;
    }
    return ret;
}

template <class T>
std::map<T, int> compress(std::vector<T>& v) {
    std::sort(v.begin(), v.end());
    v.erase(std::unique(v.begin(), v.end()), v.end());

    std::map<T, int> rev;
    for (int i = 0; i < v.size(); ++i) rev[v[i]] = i;
    return rev;
}

template <class Data, class Operator>
class SegmentTree {
    using DataMerger = std::function<Data(Data, Data)>;
    using Applier = std::function<Data(Operator, Data)>;

private:
    int length;
    std::vector<Data> dat;
    Data dat_id;        // データの単位元
    DataMerger dmerge;  // データをマージする関数
    Applier app;        // データに作用素を適用する関数

    Data query(int ql, int qr, int nidx, int nl, int nr) {
        if (nr <= ql || qr <= nl) return dat_id;
        if (ql <= nl && nr <= qr) return dat[nidx];
        Data vl = query(ql, qr, nidx * 2, nl, (nl + nr) / 2);
        Data vr = query(ql, qr, nidx * 2 + 1, (nl + nr) / 2, nr);
        return dmerge(vl, vr);
    }

public:
    explicit SegmentTree(int N, Data dat_id, DataMerger dmerge, Applier app)
        : length(1), dat_id(dat_id), dmerge(dmerge), app(app) {
        while (length < N) length <<= 1;
        dat.assign(length * 2, dat_id);
    }

    // half-open interval [ql, qr)
    Data query(int ql, int qr) { return query(ql, qr, 1, 0, length); }

    void update(int idx, Operator e) {
        int nidx = idx + length;
        dat[nidx] = app(e, dat[nidx]);
        while (nidx > 0) {
            nidx >>= 1;
            dat[nidx] = dmerge(dat[nidx * 2], dat[nidx * 2 + 1]);
        }
    }
};

int main() {
    int n;
    std::cin >> n;
    std::vector<int> xs(n), ys(n);
    for (int i = 0; i < n; ++i) {
        std::cin >> xs[i] >> ys[i];
    }

    std::vector<int> ps(n);
    {
        auto xss = xs, yss = ys;
        auto revx = compress(xss);
        auto revy = compress(yss);
        for (int i = 0; i < n; ++i) {
            ps[revx[xs[i]]] = revy[ys[i]];
        }
    }

    SegmentTree<int, int> seg(
        n, 0,
        [](int a, int b) { return a + b; },
        [](int e, int a) { return a + e; });

    std::vector<int> ld(n);
    for (int x = 0; x < n; ++x) {
        ld[x] = seg.query(0, ps[x]);
        seg.update(ps[x], 1);
    }

    mint ans = 0;
    for (int x = 0; x < n; ++x) {
        mint pat = ipow(mint(2), n) -
                   (ipow(mint(2), x) + ipow(mint(2), n - x - 1) +
                    ipow(mint(2), ps[x]) + ipow(mint(2), n - ps[x] - 1)) +
                   (ipow(mint(2), ld[x]) +
                    ipow(mint(2), x - ld[x]) +
                    ipow(mint(2), ps[x] - ld[x]) +
                    ipow(mint(2), n - x - ps[x] + ld[x] - 1)) -
                   1;

        ans += pat;
    }

    std::cout << ans << std::endl;
    return 0;
}


Compiler output:
a.cc:99:29: error: 'function' in namespace 'std' does not name a template type
   99 |     using DataMerger = std::function<Data(Data, Data)>;
      |                             ^~~~~~~~
a.cc:5:1: note: 'std::function' is defined in header '<functional>'; this is probably fixable by adding '#include <functional>'
    4 | #include <map>
  +++ |+#include <functional>
    5 | 
a.cc:100:26: error: 'function' in namespace 'std' does not name a template type
  100 |     using Applier = std::function<Data(Operator, Data)>;
      |                          ^~~~~~~~
a.cc:100:21: note: 'std::function' is defined in header '<functional>'; this is probably fixable by adding '#include <functional>'
  100 |     using Applier = std::function<Data(Operator, Data)>;
      |                     ^~~
a.cc:106:5: error: 'DataMerger' does not name a type
  106 |     DataMerger dmerge;  // データをマージする関数
      |     ^~~~~~~~~~
a.cc:107:5: error: 'Applier' does not name a type
  107 |     Applier app;        // データに作用素を適用する関数
      |     ^~~~~~~
a.cc:118:46: error: 'DataMerger' has not been declared
  118 |     explicit SegmentTree(int N, Data dat_id, DataMerger dmerge, Applier app)
      |                                              ^~~~~~~~~~
a.cc:118:65: error: 'Applier' has not been declared
  118 |     explicit SegmentTree(int N, Data dat_id, DataMerger dmerge, Applier app)
      |                                                                 ^~~~~~~
a.cc: In constructor 'SegmentTree<Data, Operator>::SegmentTree(int, Data, int, int)':
a.cc:119:38: error: class 'SegmentTree<Data, Operator>' does not have any field named 'dmerge'
  119 |         : length(1), dat_id(dat_id), dmerge(dmerge), app(app) {
      |                                      ^~~~~~
a.cc:119:54: error: class 'SegmentTree<Data, Operator>' does not have any field named 'app'
  119 |         : length(1), dat_id(dat_id), dmerge(dmerge), app(app) {
      |                                                      ^~~
a.cc: In function 'int main()':
a.cc:157:9: error: invalid user-defined conversion from 'main()::<lambda(int, int)>' to 'int' [-fpermissive]
  157 |         [](int a, int b) { return a + b; },
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:157:9: note: candidate is: 'constexpr main()::<lambda(int, int)>::operator int (*)(int, int)() const' (near match)
  157 |         [](int a, int b) { return a + b; },
      |         ^
a.cc:157:9: note:   no known conversion from 'int (*)(int, int)' to 'int'
a.cc:118:57: note:   initializing argument 3 of 'SegmentTree<Data, Operator>::SegmentTree(int, Data, int, int) [with Data = int; Operator = int]'
  118 |     explicit SegmentTree(int N, Data dat_id, DataMerger dmerge, Applier app)
      |                                              ~~~~~~~~~~~^~~~~~
a.cc:158:9: error: invalid user-defined conversion from 'main()::<lambda(int, int)>' to 'int' [-fpermissive]
  158 |         [](int e, int a) { return a + e; });
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:158:9: note: candidate is: 'constexpr main()::<lambda(int, int)>::operator int (*)(int, int)() const' (near match)
  158 |         [](int e, int a) { return a + e; });
      |         ^
a.cc:158:9: note:   no known conversion from 'int (*)(int, int)' to 'int'
a.cc:118:73: note:   initializing argument 4 of 'SegmentTree<Data, Operator>::SegmentTree(int, Data, int, int) [with Data = int; Operator = int]'
  118 |     explicit SegmentTree(int N, Data dat_id, DataMerger dmerge, Applier app)
      |                                                                 ~~~~~~~~^~~
a.cc: In instantiation of 'void SegmentTree<Data, Operator>::update(int, Operator) [with Data = int; Operator = int]':
a.cc:163:19:   required from here
  163 |         seg.update(ps[x], 1);
      |         ~~~~~~~~~~^~~~~~~~~~
a.cc:129:24: error: 'app' was not declared in this scope
  129 |         dat[nidx] = app(e, dat[nidx]);
      |                     ~~~^~~~~~~~~~~~~~
a.cc:132:31: error: 'dmerge' was not declared in this scope
  132 |             dat[nidx] = dmerge(dat[nidx * 2], dat[nidx * 2 + 1]);
      |                         ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc: In instantiation of 'Data SegmentTree<Data, Operator>::query(int, int, int, int, int) [with Data = int; Operator = int]':
a.cc:125:46:   required from 'Data SegmentTree<Data, Operator>::query(int, int) [with Data = int; Operator = int]'
  125 |     Data query(int ql, int qr) { return query(ql, qr, 1, 0, length); }
      |                                         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
a.cc:162:26:   required from here
  162 |         ld[x] = seg.query(0, ps[x]);
      |                 ~~~~~~~~~^~~~~~~~~~
a.cc:114:22: error: 'dmerge' was not declared in this scope
  114 |         return dmerge(vl, vr);
      |                ~~~~~~^~~~~~~~