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.

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include<bits/stdc++.h>
using namespace std;
const int maxn=4e5+10,mod=998244353;
void plusle(int &a,int b){
    a+=b;if(a>=mod)a-=mod; return;
}
void minun(int &a,int b){
    a-=b; if(a<0)a+=mod; return;
}
int add(int a,int b) {
  a+=b;
  return a>=mod?a-mod:a;
}
int sub(int a,int b) {
  a-=b;
  return a<0?a+mod:a;
}
int mul(int a,int b) {
  return (int)((long long)a*b%mod);
}
struct BIT{
    vector<int> bit;
    int n;
    BIT(int _n){
            bit.resize(_n+5,0);
            n=_n+5;
    }
    void update(int idx,int val){
        for(;idx<n;idx+=(idx&(-idx)))
            bit[idx]+=val;
        return;
    }
    int get(int idx){
        int sum=0;
        for(;idx>0;idx-=(idx&(-idx)))
            sum+=bit[idx];
        return sum;
    }
    int get(int l,int r){
        return get(r)-get(l-1);
    }
};
struct pt{
    int x,y;
    pt():x(0),y(0){}
    void read(){
        scanf("%d%d",&x,&y);
    }
    bool operator <(const pt &a){
        return x==a.x?y<a.y:x<a.x;
    }
}p[maxn];
vector<int> ss,sss;
int ans,n;
int p2[maxn];

int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        p[i].read();
        ss.push_back(p[i].x);
        sss.push_back(p[i].y);
    }
    ss.push_back((int)(-1e9-7));
    sss.push_back((int)(-1e9-7));
    sort(ss.begin(),ss.end());
    sort(sss.begin(),sss.end());
    ss.erase(unique(ss.begin(),ss.end()),ss.end());
    sss.erase(unique(sss.begin(),sss.end()),sss.end());
    for(int i=1;i<=n;i++){
        p[i].x=(int)(lower_bound(ss.begin(),ss.end(),p[i].x)-ss.begin());
        p[i].y=(int)(lower_bound(sss.begin(),sss.end(),p[i].y)-sss.begin());
    }
    p2[0]=1;
    for(int i=1;i<=n;i++){
        p2[i]=add(p2[i-1],p2[i-1]);
    }
    sort(p+1,p+1+n);
    int cur=0,u1,u2,d1,d2;
    BIT f1(n),f2(n);
    for(int i=1;i<=n;i++)
        f1.update(p[i].y,1);
    for(int i=1;i<=n;i++){
        int j=i,ct=0;
        while(p[j].x==p[i].x&&j<=n){
            f1.update(p[j].y,-1);
            ct++;
            j++;
        }
        j--;
        for(int k=i;k<=j;k++){
        u1=f1.get(p[k].y+1,n),u2=f2.get(p[k].y+1,n);
        d1=f1.get(p[k].y-1),d2=f2.get(p[k].y-1);
        plusle(ans,p2[n]-1);
        ///completely above
        cur = u1 + u2 + (j-k);
        minun(ans,p2[cur]-1);
        ///completely below
        cur = d1 + d2 + (k-i);
        minun(ans,p2[cur]-1);
        ///completely left
        minun(ans,p2[i-1]-1);
        ///completely right
        minun(ans,p2[n-j]-1);
        ///shitty four corners
        ///left-up
        plusle (ans,p2[u2]-1);
        ///left down
        plusle(ans,p2[d2]-1);
        ///right up
        plusle(ans,p2[u1]-1);
        ///right down
        plusle(ans,p2[d1]-1);
        }
        for(int k=i;k<=j;k++){
            f2.update(p[k].y,1);
        }
        i=j;
    }
    printf("%d\n",ans);
}

/*
    Good Luck
        -Lucina
*/