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;
ll 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){
    if(p==0)return 1;
    if(p&1)return (a*pow(a,p-1))%mod;
    ll k=pow(a,p/2);
    return (k*k)%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=(ans+pow(2,n-1))%mod;
        ans=(ans+(((ll)((pow(2,res[0][i])-1)*(ll)(pow(2,res[1][i])-1))%mod)*(ll)(pow(2,res[2][i])-1)%mod)*(ll)(pow(2,res[3][i])-1))%mod;
        ans=(ans+((ll)(pow(2,res[0][i])-1)*(ll)(pow(2,res[1][i])-1)%mod)*(ll)(pow(2,res[2][i])-1))%mod;
        ans=(ans+((ll)(pow(2,res[0][i])-1)*(ll)(pow(2,res[1][i])-1)%mod)*(ll)(pow(2,res[3][i])-1))%mod;
        ans=(ans+((ll)(pow(2,res[0][i])-1)*(ll)(pow(2,res[3][i])-1)%mod)*(ll)(pow(2,res[2][i])-1))%mod;
        ans=(ans+((ll)(pow(2,res[3][i])-1)*(ll)(pow(2,res[1][i])-1)%mod)*(ll)(pow(2,res[2][i])-1))%mod;
        ans=(ans+(ll)(pow(2,res[2][i])-1)*(ll)(pow(2,res[1][i])-1))%mod;
        ans=(ans+(ll)(pow(2,res[3][i])-1)*(ll)(pow(2,res[0][i])-1))%mod;
    }
    cout<<(ans+mod)%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:80:29: error: invalid operands of types '__gnu_cxx::__promote<double>::__type' {aka 'double'} and 'll' {aka 'long long int'} to binary 'operator%'
   80 |         ans=(ans+pow(2,n-1))%mod;
      |             ~~~~~~~~~~~~~~~~^~~~
      |                 |            |
      |                 |            ll {aka long long int}
      |                 __gnu_cxx::__promote<double>::__type {aka double}