Problem:


Score : 600 points

Problem Statement

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.

Constraints

1 \leq N \leq 2 \times 10^5

-10^9 \leq x_i, y_i \leq 10^9

x_i \neq x_j (i \neq j)

y_i \neq y_j (i \neq j)

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
x_1 y_1
:
x_N y_N

Output

Print the sum of f(T) over all non-empty subset T of S, modulo 998244353.

Sample Input 1

3
-1 3
2 1
3 -2

Sample Output 1

13

Let the first, second, and third points be P_1, P_2, and P_3, respectively. S = \{P_1, P_2, P_3\} has seven non-empty subsets, and f has the following values for each of them:

f(\{P_1\}) = 1

f(\{P_2\}) = 1

f(\{P_3\}) = 1

f(\{P_1, P_2\}) = 2

f(\{P_2, P_3\}) = 2

f(\{P_3, P_1\}) = 3

f(\{P_1, P_2, P_3\}) = 3

The sum of these is 13.

Sample Input 2

4
1 4
2 1
3 3
4 2

Sample Output 2

34

Sample Input 3

10
19 -11
-3 -12
5 3
3 -15
8 -14
-9 -20
10 -9
0 2
-7 17
6 -6

Sample Output 3

7222

Be sure to print the sum modulo 998244353.



Sample input:
3
-1 3
2 1
3 -2


Sample output:
13

Submission status: Wrong Answer

Solution code:
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):
    b = 0
    cs = []
    while True:
        if y == 0:
            r = 1
            break
        elif y == 1:
            r = x % mod
            break
        elif y % 2 == 0 :
            y = y // 2
            cs.append(0)
        else:
            y = (y-1)//2
            cs.append(1)
    while True:
        if len(cs) == 0:
            break
        c = cs.pop()
        if c == 1:
            r = r ** 2 * x % mod
        else:
            r = r ** 2 % mod
    return r

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 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()))
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]

ss1 = SegTree([0] * n, n, 0, lambda x,y:x+y)
r = 0
for i, y in enumerate(nys):
    ss1.update(y, 1)
    d = ss1.query(0, y)
    c = i - d
    b = (n-1) - y - c
    a = (n-1) - b - c - d
    r = (r + mm(a, b, c, d, n)) % mod

print(sub((power(2, n) * n) % mod, (r+n)%mod)+1)

Submission status: Wrong Answer

Solution code:
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):
    b = 0
    cs = []
    while True:
        if y == 0:
            r = 1
            break
        elif y == 1:
            r = x % mod
            break
        elif y % 2 == 0 :
            y = y // 2
            cs.append(0)
        else:
            y = (y-1)//2
            cs.append(1)
    for c in cs[::-1]:
        if c == 1:
            r = r ** 2 * x % mod
        else:
            r = r ** 2 % mod
    return r

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 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)
#ss2 = SegTree([1] * 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(sub((power(2, n) * n) % mod, (r+n)%mod)+1)

Submission status: Wrong Answer

Solution code:
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)
#ss2 = SegTree([1] * 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)

Submission status: Wrong Answer

Solution code:
# F - Enclosed Points
from itertools import chain

def selectTarget(startIdx, maxIdx, depth):
    resultList = []
    idx = startIdx
    if depth != 0:
        while idx <= maxIdx - depth:
            chldRetList = selectTarget(idx + 1, maxIdx, depth - 1)
            #resultList.extend(list(map(list, zip([idx] * len(chldRetList), chldRetList))))
            #if type(chldRetList[0]) is list:
            #    print('#chain#')
            #    resultList = list(chain.from_iterable(resultList))
            if type(chldRetList[0]) is list:
                for chldRet in chldRetList[:]:
                    chldRet.insert(0, idx)
                    resultList.append(chldRet)
            else:
                resultList.extend(list(map(list, zip([idx] * len(chldRetList), chldRetList))))
            idx += 1
    else:
        while idx <= maxIdx:
            resultList.append(idx)
            idx += 1
    return resultList



n = int(input())
pList = list()
for i in range(n):
    pList.append(list(map(int, input().split())))

# x座標、y座標でそれぞれソートしたリストを作成
sortXMap = {p[0]: pList.index(p) for p in pList}
sortYMap = {p[1]: pList.index(p) for p in pList}
sortXList = sorted(sortXMap.items(), key=lambda xMap: xMap[0])
sortYList = sorted(sortYMap.items(), key=lambda yMap: yMap[0])
tmp, sortX = map(list, zip(*sortXList))
tmp, sortY = map(list, zip(*sortYList))

# 点を2個以上n個未満含む集合を数える
cnt = n * 2
for j in range(1, n - 1):
    tList = selectTarget(0, n - 1, j)
    for t in tList:
        maxXIdx = -1
        minXIdx = len(sortX)
        maxYIdx = -1
        minYIdx = len(sortY)
        for pt in t:
            if maxXIdx < sortX.index(pt):
                maxXIdx = sortX.index(pt)
            if sortX.index(pt) < minXIdx:
                minXIdx = sortX.index(pt)
            if maxYIdx < sortY.index(pt):
                maxYIdx = sortY.index(pt)
            if sortY.index(pt) < minYIdx:
                minYIdx = sortY.index(pt)
        targetX = sortX[minXIdx:maxXIdx + 1]
        targetY = sortY[minYIdx:maxYIdx + 1]
        cnt += len(set(targetX) & set(targetY))
print(cnt % 998244353)

Submission status: Wrong Answer

Solution code:
N =int(input())
points = []
for x in range(N):
    points.append([int(x) for x in input().split()])
    
import itertools
cnt = 0
for L in range(1, len(points)+1):
    for point in itertools.combinations(points, L):
        max_x,max_y = point[0]
        min_x,min_y = point[0]
        
        for p in point:
            if max_x < p[0]: max_x = p[0]
            if max_y < p[1]: max_y = p[1]
            if min_x > p[0]: min_x = p[0]
            if min_y > p[1]: min_y = p[1]
        #print(max_x,max_y)
        #print(min_x,min_y)
        
        
        for p in points:
            if (p[0] >= min_x & p[0] <= max_x) & (p[1] >= min_y & p[1] <= max_y):
                cnt += 1
        #print(point)
print(cnt%998244353)

Submission status: Wrong Answer

Solution code:
N = int(input())

XY = []
for _ in range(N):
    x, y = map(int, input().split())
    XY.append((x, y))
    
all_p = XY[:]
sorted_x_p = sorted(all_p)
sorted_y_p = sorted(all_p, key=lambda x: x[1])

ans = 0
for i in range(N):
    for j in range(i+1, N+1):
        for k in range(N):
            for l in range(k+1, N+1):
                sub_p = set(sorted_x_p[i:j]) & set(sorted_y_p[k:l])
                ans += len(sub_p)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = str(input())

ans = 0
a = 0

for i in range(1,N):
    X = S[:i]
    Y = S[i:]
    lis = list(set(X))
    for j in range(len(lis)):
        if Y.count(X[j]) != 0:
            a += 1

    if a > ans:
        ans = a
    a = 0

print(ans)

Submission status: Wrong Answer

Solution code:

class SegmentTree:
    def __init__(self, L, op, default_val):
        self.op = op
        self.default_val = default_val
        self.sz = len(L)
        self.n = 1
        self.s = 1
        for i in range(1000):
            self.n *= 2
            self.s += 1
            if self.n >= self.sz:
                break
        self.node = [self.default_val]*(2*self.n-1)

        for i in range(self.sz):
            self.node[i+self.n-1] = L[i]

        for i in range(self.n-2,-1,-1):
            self.node[i] = self.op(self.node[i*2+1],self.node[i*2+2])
    
    def add(self, a, x):
        k = a+self.n-1
        self.node[k] += x
        for i in range(1000):
            k = (k-1)//2
            self.node[k] = self.op(self.node[2*k+1], self.node[2*k+2])
            if k <= 0:
                break
    
    def get(self, l, r):
        res = self.default_val
        n = self.n
        if self.sz <= r or 0 > l:
            print("ERROR: the indice are wrong.")
            return False

        for i in range(self.s):
            count = 2**i-1
            a = (r+1)//n
            b = (l-1)//n
            if a-b == 3:
                res = self.op(self.node[count+b+1],res)
                res = self.op(self.node[count+b+2],res)
                right = a*n
                left = (b+1)*n-1
                break
            if a-b == 2:
                res = self.op(self.node[count+b+1],res)
                right = a*n
                left = (b+1)*n-1
                break
            n = n//2

        n1 = n//2        
        #left
        for j in range(i+1,self.s):
            count = 2**j-1 
            a = (left+1)//n1
            b = (l-1)//n1
            if a-b == 2:
                res = self.op(self.node[count+b+1],res)
                left = (b+1)*n1-1                
            n1 = n1//2

        n1 = n//2        
        #right
        for j in range(i+1,self.s):
            count = 2**j-1 
            a = (r+1)//n1
            b = (right-1)//n1
            if a-b == 2:
                res = self.op(self.node[count+b+1],res)
                right = a*n1                
            n1 = n1//2
        return res

N = int(input())
point = [list(map(int,input().split())) for i in range(N)]

point.sort(lambda x: x[1])
for i in range(len(point)):
    point[i][1] = i

mod = 998244353

ans = ((N-4)*pow(2,N,mod)+3*N+4)%mod

pow2 = []
a = 1
for i in range(N+1):
    pow2.append(a)
    a *= 2
    a %= mod

point.sort(lambda x: x[0])

ST = SegmentTree([0]*len(point), lambda a,b:a+b, 0)


for i in range(len(point)):
    if point[i][1] > 0:
        lu = ST.get(0,point[i][1]-1)
        #ls = i//2
    else:
        lu = 0
    ld = i-lu
    ru = N - point[i][1] - 1 - lu
    rd = N - point[i][1] - 1 - ld    
    ans += pow2[lu]-1
    ans += pow2[ld]-1
    ans += pow2[ru]-1
    ans += pow2[rd]-1
    ans %= mod
    ST.add(point[i][1],1)

print(ans)

Submission status: Wrong Answer

Solution code:

class SegmentTree:
    def __init__(self, L, op, default_val):
        self.op = op
        self.default_val = default_val
        self.sz = len(L)
        self.n = 1
        self.s = 1
        for i in range(1000):
            self.n *= 2
            self.s += 1
            if self.n >= self.sz:
                break
        self.node = [self.default_val]*(2*self.n-1)

        for i in range(self.sz):
            self.node[i+self.n-1] = L[i]

        for i in range(self.n-2,-1,-1):
            self.node[i] = self.op(self.node[i*2+1],self.node[i*2+2])
    
    def add(self, a, x):
        k = a+self.n-1
        self.node[k] += x
        for i in range(1000):
            k = (k-1)//2
            self.node[k] = self.op(self.node[2*k+1], self.node[2*k+2])
            if k <= 0:
                break
    
    def get(self, l, r):
        res = self.default_val
        n = self.n
        if self.sz <= r or 0 > l:
            print("ERROR: the indice are wrong.")
            return False

        for i in range(self.s):
            count = 2**i-1
            a = (r+1)//n
            b = (l-1)//n
            if a-b == 3:
                res = self.op(self.node[count+b+1],res)
                res = self.op(self.node[count+b+2],res)
                right = a*n
                left = (b+1)*n-1
                break
            if a-b == 2:
                res = self.op(self.node[count+b+1],res)
                right = a*n
                left = (b+1)*n-1
                break
            n = n//2

        n1 = n//2        
        #left
        for j in range(i+1,self.s):
            count = 2**j-1 
            a = (left+1)//n1
            b = (l-1)//n1
            if a-b == 2:
                res = self.op(self.node[count+b+1],res)
                left = (b+1)*n1-1                
            n1 = n1//2

        n1 = n//2        
        #right
        for j in range(i+1,self.s):
            count = 2**j-1 
            a = (r+1)//n1
            b = (right-1)//n1
            if a-b == 2:
                res = self.op(self.node[count+b+1],res)
                right = a*n1                
            n1 = n1//2
        return res

N = int(input())
point = [list(map(int,input().split())) for i in range(N)]

point.sort(lambda x: x[1])
for i in range(len(point)):
    point[i][1] = i

mod = 998244353

ans = ((N-4)*pow(2,N,mod)+3*N+4)%mod

pow2 = []
a = 1
for i in range(N+1):
    pow2.append(a)
    a *= 2
    a %= mod

point.sort(lambda x: x[0])

ST = SegmentTree([0]*len(point), lambda a,b:a+b, 0)


for i in range(len(point)):
    if point[i][1] > 0:
        lu = ST.get(0,point[i][1]-1)
        #ls = i//2
    else:
        lu = 0
    ld = i-lu
    ru = N - i - 1 - lu
    rd = N - i - 1 - ld    
    ans += pow2[lu]-1
    ans += pow2[ld]-1
    ans += pow2[ru]-1
    ans += pow2[rd]-1
    ans %= mod
    ST.add(point[i][1],1)

print(ans)

Submission status: Wrong Answer

Solution code:


class SegmentTree:
    def __init__(self, L, op, default_val):
        self.op = op
        self.default_val = default_val
        self.sz = len(L)
        self.n = 1
        self.s = 1
        for i in range(1000):
            self.n *= 2
            self.s += 1
            if self.n >= self.sz:
                break
        self.node = [self.default_val]*(2*self.n-1)

        for i in range(self.sz):
            self.node[i+self.n-1] = L[i]

        for i in range(self.n-2,-1,-1):
            self.node[i] = self.op(self.node[i*2+1],self.node[i*2+2])
    
    def add(self, a, x):
        k = a+self.n-1
        self.node[k] += x
        for i in range(1000):
            k = (k-1)//2
            self.node[k] = self.op(self.node[2*k+1], self.node[2*k+2])
            if k <= 0:
                break
    
    def get(self, l, r):
        res = self.default_val
        n = self.n
        if self.sz <= r or 0 > l:
            print("ERROR: the indice are wrong.")
            return False

        for i in range(self.s):
            count = 2**i-1
            a = (r+1)//n
            b = (l-1)//n
            if a-b == 3:
                res = self.op(self.node[count+b+1],res)
                res = self.op(self.node[count+b+2],res)
                right = a*n
                left = (b+1)*n-1
                break
            if a-b == 2:
                res = self.op(self.node[count+b+1],res)
                right = a*n
                left = (b+1)*n-1
                break
            n = n//2

        n1 = n//2        
        #left
        for j in range(i+1,self.s):
            count = 2**j-1 
            a = (left+1)//n1
            b = (l-1)//n1
            if a-b == 2:
                res = self.op(self.node[count+b+1],res)
                left = (b+1)*n1-1                
            n1 = n1//2

        n1 = n//2        
        #right
        for j in range(i+1,self.s):
            count = 2**j-1 
            a = (r+1)//n1
            b = (right-1)//n1
            if a-b == 2:
                res = self.op(self.node[count+b+1],res)
                right = a*n1                
            n1 = n1//2
        return res

N = int(input())
point = [list(map(int,input().split())) for i in range(N)]

point.sort(lambda x: x[1])
for i in range(len(point)):
    point[i][1] = i

mod = 998244353

ans = ((N-4)*pow(2,N,mod)+3*N+4)%mod

pow2 = []
a = 1
for i in range(N+1):
    pow2.append(a)
    a *= 2
    a %= mod

point.sort(lambda x: x[0])

ST = SegmentTree([0]*len(point), lambda a,b:a+b, 0)


for i in range(len(point)):
    if point[i][1] > 0:
        ls = ST.get(0,point[i][1]-1)
        #ls = i//2
    else:
        ls = 0
    rs = i-ls
    #ans += pow2[ls]-1
    #ans += pow2[rs]-1
    #ans %= mod
    ST.add(point[i][1],1)

point.sort(lambda x: x[0],reverse=True)

ST = SegmentTree([0]*len(point), lambda a,b:a+b, 0)

for i in range(len(point)):
    if point[i][1] > 0:
        ls = ST.get(0,point[i][1]-1)
        #ls = i//2
    else:
        ls = 0
    rs = i-ls
    #ans += pow2[ls]-1
    #ans += pow2[rs]-1
    #ans %= mod
    ST.add(point[i][1],1)

print(ans)

Submission status: Wrong Answer

Solution code:

class SegmentTree:
    def __init__(self, L, op, default_val):
        self.op = op
        self.default_val = default_val
        self.sz = len(L)
        self.n = 1
        self.s = 1
        for i in range(1000):
            self.n *= 2
            self.s += 1
            if self.n >= self.sz:
                break
        self.node = [self.default_val]*(2*self.n-1)

        for i in range(self.sz):
            self.node[i+self.n-1] = L[i]

        for i in range(self.n-2,-1,-1):
            self.node[i] = self.op(self.node[i*2+1],self.node[i*2+2])
    
    def add(self, a, x):
        k = a+self.n-1
        self.node[k] += x
        for i in range(1000):
            k = (k-1)//2
            self.node[k] = self.op(self.node[2*k+1], self.node[2*k+2])
            if k <= 0:
                break
    
    def get(self, l, r):
        res = self.default_val
        n = self.n
        if self.sz <= r or 0 > l:
            print("ERROR: the indice are wrong.")
            return False

        for i in range(self.s):
            count = 2**i-1
            a = (r+1)//n
            b = (l-1)//n
            if a-b == 3:
                res = self.op(self.node[count+b+1],res)
                res = self.op(self.node[count+b+2],res)
                right = a*n
                left = (b+1)*n-1
                break
            if a-b == 2:
                res = self.op(self.node[count+b+1],res)
                right = a*n
                left = (b+1)*n-1
                break
            n = n//2

        n1 = n//2        
        #left
        for j in range(i+1,self.s):
            count = 2**j-1 
            a = (left+1)//n1
            b = (l-1)//n1
            if a-b == 2:
                res = self.op(self.node[count+b+1],res)
                left = (b+1)*n1-1                
            n1 = n1//2

        n1 = n//2        
        #right
        for j in range(i+1,self.s):
            count = 2**j-1 
            a = (r+1)//n1
            b = (right-1)//n1
            if a-b == 2:
                res = self.op(self.node[count+b+1],res)
                right = a*n1                
            n1 = n1//2
        return res

N = int(input())
point = [list(map(int,input().split())) for i in range(N)]

point.sort(lambda x: x[1])
for i in range(len(point)):
    point[i][1] = i

mod = 998244353

ans = ((N-4)*pow(2,N,mod)+3*N+4)%mod

pow2 = []
a = 1
for i in range(N+1):
    pow2.append(a)
    a *= 2
    a %= mod

point.sort(lambda x: x[0])

#ST = SegmentTree([0]*len(point), lambda a,b:a+b, 0)


for i in range(len(point)):
    if point[i][1] > 0:
        #ls = ST.get(0,point[i][1]-1)
        ls = i//2
    else:
        ls = 0
    rs = i-ls
    ans += pow2[ls]-1
    ans += pow2[rs]-1
    ans %= mod
    #ST.add(point[i][1],1)

point.sort(lambda x: x[0],reverse=True)

#ST = SegmentTree([0]*len(point), lambda a,b:a+b, 0)

for i in range(len(point)):
    if point[i][1] > 0:
        #ls = ST.get(0,point[i][1]-1)
        ls = i//2
    else:
        ls = 0
    rs = i-ls
    ans += pow2[ls]-1
    ans += pow2[rs]-1
    ans %= mod
    #ST.add(point[i][1],1)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
point = [list(map(int,input().split())) for i in range(N)]

x = []
y = []
for p in point:
    x.append(p[0])
    y.append(p[1])

x.sort()
y.sort()

x_dict = {}
y_dict = {}

for i in range(len(x)):
    x_dict[x[i]] = i

for i in range(len(y)):
    y_dict[y[i]] = i

Submission status: Wrong Answer

Solution code:

class SegmentTree:
    def __init__(self, L, op, default_val):
        self.op = op
        self.default_val = default_val
        self.sz = len(L)
        self.n = 1
        self.s = 1
        while self.n < self.sz:
            self.n *= 2
            self.s += 1
        self.node = [self.default_val]*(2*self.n-1)

        for i in range(self.sz):
            self.node[i+self.n-1] = L[i]

        for i in range(self.n-2,-1,-1):
            self.node[i] = self.op(self.node[i*2+1],self.node[i*2+2])
    
    def add(self, a, x):
        k = a+self.n-1
        self.node[k] += x
        for i in range(1000):
            k = (k-1)//2
            self.node[k] = self.op(self.node[2*k+1], self.node[2*k+2])
            if k <= 0:
                break
    
    def get(self, l, r):
        res = self.default_val
        n = self.n
        if self.sz <= r or 0 > l:
            print("ERROR: the indice are wrong.")
            return False

        for i in range(self.s):
            count = 2**i-1
            a = (r+1)//n
            b = (l-1)//n
            if a-b == 3:
                res = self.op(self.node[count+b+1],res)
                res = self.op(self.node[count+b+2],res)
                right = a*n
                left = (b+1)*n-1
                break
            if a-b == 2:
                res = self.op(self.node[count+b+1],res)
                right = a*n
                left = (b+1)*n-1
                break
            n = n//2

        n1 = n//2        
        #left
        for j in range(i+1,self.s):
            count = 2**j-1 
            a = (left+1)//n1
            b = (l-1)//n1
            if a-b == 2:
                res = self.op(self.node[count+b+1],res)
                left = (b+1)*n1-1                
            n1 = n1//2

        n1 = n//2        
        #right
        for j in range(i+1,self.s):
            count = 2**j-1 
            a = (r+1)//n1
            b = (right-1)//n1
            if a-b == 2:
                res = self.op(self.node[count+b+1],res)
                right = a*n1                
            n1 = n1//2
        return res

N = int(input())
point = [list(map(int,input().split())) for i in range(N)]

x = []
y = []
for p in point:
    x.append(p[0])
    y.append(p[1])

x.sort()
y.sort()

x_dict = {}
y_dict = {}

for i in range(len(x)):
    x_dict[x[i]] = i

for i in range(len(y)):
    y_dict[y[i]] = i

mod = 998244353

ans = ((N-4)*pow(2,N,mod)+3*N+4)%mod

pow2 = []
a = 1
for i in range(N+1):
    pow2.append(a)
    a *= 2
    a %= mod

point.sort(lambda x: x[0])

ST = SegmentTree([0]*len(y), lambda a,b:a+b, 0)


for i in range(len(point)):
    if y_dict[point[i][1]] > 0:
        ls = ST.get(0,y_dict[point[i][1]]-1)
        ls = i//2
    else:
        ls = 0
    rs = i-ls
    ans += pow2[ls]-1
    ans += pow2[rs]-1
    ans %= mod
    ST.add(y_dict[point[i][1]],1)

point.sort(lambda x: x[0],reverse=True)

ST = SegmentTree([0]*len(y), lambda a,b:a+b, 0)

for i in range(len(point)):
    if y_dict[point[i][1]] > 0:
        ls = ST.get(0,y_dict[point[i][1]]-1)
    else:
        ls = 0
    rs = i-ls
    ans += pow2[ls]-1
    ans += pow2[rs]-1
    ans %= mod
    ST.add(y_dict[point[i][1]],1)

print(ans)