Problem: We have a set S of N points in a two-dimensional plane. The coordinates of the i-th point are (x_i, y_i). The N points have distinct x-coordinates and distinct y-coordinates.  For a non-empty subset T of S, let f(T) be the number of points contained in the smallest rectangle, whose sides are parallel to the coordinate axes, that contains all the points in T. More formally, we define f(T) as follows:    * f(T) :=  (the number of integers i (1 \leq i \leq N) such that a \leq x_i \leq b and c \leq y_i \leq d, where a, b, c, and d are the minimum x-coordinate, the maximum x-coordinate, the minimum y-coordinate, and the maximum y-coordinate of the points in T)  Find the sum of f(T) over all non-empty subset T of S. Since it can be enormous, print the sum modulo 998244353.

Submission attempts (in order):
import sys
input = sys.stdin.readline
mod = 998244353

def sub(a, b):
    return (a % mod + mod - b % mod) % mod

sys.setrecursionlimit(pow(10, 8))

def power(x, y):
    if   y == 0     : return 1
    elif y == 1     : return x % mod
    elif y % 2 == 0 : return power(x, y//2)**2 % mod
    else            : return power(x, (y-1)//2)**2 * x % mod

class SegTree:
    def __init__(self, init_val, n, ide_ele, seg_func):
        self.segfunc = seg_func
        self.num = 2**(n-1).bit_length()
        self.ide_ele = ide_ele
        self.seg=[self.ide_ele]*2*self.num
        for i in range(n):
            self.seg[i+self.num-1]=init_val[i]    
        for i in range(self.num-2,-1,-1) :
            self.seg[i]=self.segfunc(self.seg[2*i+1],self.seg[2*i+2]) 
        
    def update(self, k, x):
        k += self.num-1
        self.seg[k] = x
        while k+1:
            k = (k-1)//2
            self.seg[k] = self.segfunc(self.seg[k*2+1],self.seg[k*2+2])
        
    def query(self, p, q):
        if q<=p:
            return self.ide_ele
        p += self.num-1
        q += self.num-2
        res=self.ide_ele
        while q-p>1:
            if p&1 == 0:
                res = self.segfunc(res,self.seg[p])
            if q&1 == 1:
                res = self.segfunc(res,self.seg[q])
                q -= 1
            p = p//2
            q = (q-1)//2
        if p == q:
            res = self.segfunc(res,self.seg[p])
        else:
            res = self.segfunc(self.segfunc(res,self.seg[p]),self.seg[q])
        return res

def mm(a, b, c, d, n):
    return 1
    return sub(
            power(2, n) - 1,
            sub(
                power(2, b+c) + power(2, c+d) + power(2, d+a) + power(2, a+b),
                power(2, a) + power(2, b) + power(2, c) + power(2, d)
                )
            )
n, = list(map(int, input().split()))
ps, xs, ys = [], [], []
for _ in range(n):
    x, y = list(map(int, input().split()))
    xs.append(x)
    ys.append(y)
for i, xi in enumerate(sorted(list(range(n)), key=lambda x:xs[x])):
    xs[xi] = i 
for i, yi in enumerate(sorted(list(range(n)), key=lambda x:ys[x])):
    ys[yi] = i 
for x, y in zip(xs, ys):
    ps.append((x,y))
ps = sorted(ps, key=lambda x:x[0])

ss1 = SegTree([0] * n, n, 0, lambda x,y:x+y)


r = 0
for p in ps:
    ss1.update(p[1], 1)
#    ss2.update(p[1], 0)
    d = ss1.query(0, p[1])
    c = p[0] - d
    b = (n-1) - p[1] - c
#    a = ss2.query(0, p[1])
    a = (n-1) - b - c - d
    r = (r + mm(a, b, c, d, n)) % mod

print(r)


import sys
input = sys.stdin.readline
mod = 998244353

def sub(a, b):
    return (a % mod + mod - b % mod) % mod


def main():
    n, = list(map(int, input().split()))
    t = 1
    dd = [t]
    for _ in range(n):
        t=2*t%mod
        dd.append(t)

    xs, ys = [], []
    for _ in range(n):
        x, y = list(map(int, input().split()))
        xs.append(x)
        ys.append(y)

    ini = sorted(list(range(n)), key=lambda x:xs[x])
    for i, yi in enumerate(sorted(list(range(n)), key=lambda x:ys[x])):
        ys[yi] = i 
    nys = [ys[i] for i in ini]

    tree = [0] * (n + 1)
    r = 0
    for i, y in enumerate(nys):
        j = y+1
        while j <= n:
            tree[j] += 1
            j += j & -j

        d = 0
        j = y
        while j > 0:
            d += tree[j]
            j -= j & -j

        c = i - d
        b = (n-1) - y - c
        a = (n-1) - b - c - d
        r = (r + sub(dd[b+c] + dd[c+d] + dd[d+a] + dd[a+b],
                dd[a] + dd[b] + dd[c] + dd[d])) % mod

    print(sub((dd[n] * n) % mod, (r+n)%mod))
main()


Verdicts: Wrong Answer

Accepted