Language: C++

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
const ll inf=1001001001001001;
const int INF=1001001001;
//const int mod=1000000007;
const int mod=998244353;
const double pi=3.14159265358979323846;
bool chmin(auto &a,auto b){if(a>b){a=b;return true;}return false;}
bool chmax(auto &a,auto b){if(a<b){a=b;return true;}return false;}
void outvi(vi v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
void outvvi(vvi v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<endl;}}
vi segsum;
ll N=1;
ll pow(ll a,ll p){
    a%=mod;
    if(p==0)return 1;
    if(p&1)return (a*pow(a,p-1))%mod;
    return (pow(a,p/2)*pow(a,p/2))%mod;
}
void update(ll i,ll x){
    i=N+i-1;
    segsum[i]=x;
    while(i>0){
        i=(i-1)/2;
        segsum[i]=segsum[i*2+1]+segsum[i*2+2];
    }
}
ll sum(ll a,ll b,ll k,ll l,ll r){
    if(r<=a||b<=l)return 0;
    if(a<=l&&r<=b)return segsum[k];
    ll c1=sum(a,b,k*2+1,l,(l+r)/2);
    ll c2=sum(a,b,k*2+2,(l+r)/2,r);
    return c1+c2;
}
vi so;
ll id(ll i){
    return lb(so,i);
}
int main(){
    ll n;cin>>n;
    vvi res(4,vi(n));
    while(N<n)N*=2;
    segsum=vi(N*2-1);
    vector<P> v(n);
    rep(i,n)cin>>v[i].fi>>v[i].se;
    so=vi(n);
    rep(i,n)so[i]=v[i].se;
    sort(all(so));
    sort(all(v));
    rep(i,n){
        update(id(v[i].se),segsum[id(v[i].se)+N-1]+1);
        res[1][i]=sum(0,id(v[i].se),0,0,N);
        res[0][i]=i-res[1][i];
    }
    segsum=vi(N*2-1);
    reverse(all(v));
    rep(i,n){
        update(id(v[i].se),segsum[id(v[i].se)+N-1]+1);
        res[3][n-1-i]=sum(0,id(v[i].se),0,0,N);
        res[2][n-1-i]=i-res[3][n-1-i];
    }
    ll ans=0;
    rep(i,n){
        ans+=pow(2,n-1);
        ans+=(pow(2,res[0][i])-1)*(pow(2,res[1][i])-1)%mod*(pow(2,res[2][i])-1)%mod*(pow(2,res[3][i])-1)%mod;
        ans+=(pow(2,res[0][i])-1)*(pow(2,res[1][i])-1)%mod*(pow(2,res[2][i])-1)%mod;
        ans+=(pow(2,res[0][i])-1)*(pow(2,res[1][i])-1)%mod*(pow(2,res[3][i])-1)%mod;
        ans+=(pow(2,res[0][i])-1)*(pow(2,res[3][i])-1)%mod*(pow(2,res[2][i])-1)%mod;
        ans+=(pow(2,res[3][i])-1)*(pow(2,res[1][i])-1)%mod*(pow(2,res[2][i])-1)%mod;
        ans+=(pow(2,res[2][i])-1)*(pow(2,res[1][i])-1)%mod;
        ans+=(pow(2,res[3][i])-1)*(pow(2,res[0][i])-1)%mod;
    }
    cout<<ans%mod<<endl;
}

Compiler output:
a.cc:24:12: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts'
   24 | bool chmin(auto &a,auto b){if(a>b){a=b;return true;}return false;}
      |            ^~~~
a.cc:24:20: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts'
   24 | bool chmin(auto &a,auto b){if(a>b){a=b;return true;}return false;}
      |                    ^~~~
a.cc:25:12: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts'
   25 | bool chmax(auto &a,auto b){if(a<b){a=b;return true;}return false;}
      |            ^~~~
a.cc:25:20: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts'
   25 | bool chmax(auto &a,auto b){if(a<b){a=b;return true;}return false;}
      |                    ^~~~
a.cc: In function 'int main()':
a.cc:81:55: error: invalid operands of types '__gnu_cxx::__promote<double>::__type' {aka 'double'} and 'const int' to binary 'operator%'
   81 |         ans+=(pow(2,res[0][i])-1)*(pow(2,res[1][i])-1)%mod*(pow(2,res[2][i])-1)%mod*(pow(2,res[3][i])-1)%mod;
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
      |                                  |                     |
      |                                  |                     const int
      |                                  __gnu_cxx::__promote<double>::__type {aka double}
a.cc:82:55: error: invalid operands of types '__gnu_cxx::__promote<double>::__type' {aka 'double'} and 'const int' to binary 'operator%'
   82 |         ans+=(pow(2,res[0][i])-1)*(pow(2,res[1][i])-1)%mod*(pow(2,res[2][i])-1)%mod;
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
      |                                  |                     |
      |                                  |                     const int
      |                                  __gnu_cxx::__promote<double>::__type {aka double}
a.cc:83:55: error: invalid operands of types '__gnu_cxx::__promote<double>::__type' {aka 'double'} and 'const int' to binary 'operator%'
   83 |         ans+=(pow(2,res[0][i])-1)*(pow(2,res[1][i])-1)%mod*(pow(2,res[3][i])-1)%mod;
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
      |                                  |                     |
      |                                  |                     const int
      |                                  __gnu_cxx::__promote<double>::__type {aka double}
a.cc:84:55: error: invalid operands of types '__gnu_cxx::__promote<double>::__type' {aka 'double'} and 'const int' to binary 'operator%'
   84 |         ans+=(pow(2,res[0][i])-1)*(pow(2,res[3][i])-1)%mod*(pow(2,res[2][i])-1)%mod;
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
      |                                  |                     |
      |                                  |                     const int
      |                                  __gnu_cxx::__promote<double>::__type {aka double}
a.cc:85:55: error: invalid operands of types '__gnu_cxx::__promote<double>::__type' {aka 'double'} and 'const int' to binary 'operator%'
   85 |         ans+=(pow(2,res[3][i])-1)*(pow(2,res[1][i])-1)%mod*(pow(2,res[2][i])-1)%mod;
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
      |                                  |                     |
      |                                  |                     const int
      |                                  __gnu_cxx::__promote<double>::__type {aka double}
a.cc:86:55: error: invalid operands of types '__gnu_cxx::__promote<double>::__type' {aka 'double'} and 'const int' to binary 'operator%'
   86 |         ans+=(pow(2,res[2][i])-1)*(pow(2,res[1][i])-1)%mod;
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
      |                                  |                     |
      |                                  |                     const int
      |                                  __gnu_cxx::__promote<double>::__type {aka double}
a.cc:87:55: error: invalid operands of types '__gnu_cxx::__promote<double>::__type' {aka 'double'} and 'const int' to binary 'operator%'
   87 |         ans+=(pow(2,res[3][i])-1)*(pow(2,res[0][i])-1)%mod;
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
      |                                  |                     |
      |                                  |                     const int
      |                                  __gnu_cxx::__promote<double>::__type {aka double}