Submission #6702389


Source Code Expand

Copy
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<unordered_set>
#include<unordered_map>
using namespace std;
typedef long long ll;
#define mod 998244353
#define mad(a,b) a=(a+b)%mod;
#define N 200010
typedef pair<ll,ll> P;
namespace seg{
  ll dat[2*N];
  void init(){
    for(int i=0;i<2*N;i++){
      dat[i]=0;
    }
  }
  void upd(ll p,ll x){
    p+=N;
    dat[p]=x;
    for(;p;p>>=1){
      dat[p/2]=dat[p]+dat[p^1];
    }
  }
  ll qry(ll l,ll r){
    l+=N,r+=N+1;
    ll res=0;
    for(ll a=l,b=r;a<b;a>>=1,b>>=1){
      if(a&1)res+=dat[a++];
      if(b&1)res+=dat[--b];
    }
    return res;
  };
};
ll po(ll x,ll y){
    ll res=1;
    for(;y;y>>=1){
	if(y&1)res=res*x%mod;
	x=x*x%mod;
    }
    return res;
}

ll n,x[N],y[N],xxx[N],yyy[N];
vector<ll> xx,yy;
unordered_map<ll,ll> compx,compy;
ll solve(){
  xx.clear(); yy.clear();
  compx.clear(); compy.clear();
  for(int i=0;i<n;i++){
    xx.push_back(x[i]);
    yy.push_back(y[i]);
  }
  sort(xx.begin(),xx.end());
  for(int i=0;i<xx.size();i++){
    compx[xx[i]]=i;
  }
  sort(yy.begin(),yy.end());
  for(int i=0;i<yy.size();i++){
    compy[yy[i]]=i;
  }
  for(int i=0;i<n;i++){
    xxx[i]=compx[x[i]];
    yyy[i]=compy[y[i]];
  }
  ll ans=0;
  seg::init();
  vector<P> v;
  for(int i=0;i<n;i++){
    v.push_back(make_pair(yyy[i],xxx[i]));
  }
  sort(v.begin(),v.end());
  for(int i=0;i<v.size();i++){
    ll e=seg::qry(0,n-1); mad(ans,(po(2,e)-1));
    ll w=seg::qry(0,v[i].second); mad(ans,(po(2,w)-1)*-1);
    seg::upd(v[i].second,1);
  }
  return ans;
}
int main(){
  cin>>n;
  for(int i=0;i<n;i++)cin>>x[i]>>y[i];
  ll ans=solve();
  for(int i=0;i<n;i++)x[i]*=-1;
  mad(ans,solve());
  for(int i=0;i<n;i++)y[i]*=-1;
  mad(ans,solve());
  for(int i=0;i<n;i++)x[i]*=-1;
  mad(ans,solve());
  ans*=-1;
  mad(ans,(po(2,n)-1)*n);
  if(ans<0)ans+=mod;
  cout<<ans<<endl;
  return 0;
}

Submission Info

Submission Time
Task F - Enclosed Points
User ynymxiaolongbao
Language C++14 (GCC 5.4.1)
Score 600
Code Size 1972 Byte
Status AC
Exec Time 942 ms
Memory 37172 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 26
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt AC 4 ms 7552 KB
02.txt AC 3 ms 7552 KB
03.txt AC 3 ms 7552 KB
04.txt AC 3 ms 7552 KB
05.txt AC 3 ms 7552 KB
06.txt AC 3 ms 7552 KB
07.txt AC 3 ms 7552 KB
08.txt AC 3 ms 7552 KB
09.txt AC 3 ms 7552 KB
10.txt AC 4 ms 7552 KB
11.txt AC 930 ms 37172 KB
12.txt AC 905 ms 36492 KB
13.txt AC 940 ms 36480 KB
14.txt AC 875 ms 36048 KB
15.txt AC 918 ms 36528 KB
16.txt AC 926 ms 36956 KB
17.txt AC 942 ms 36512 KB
18.txt AC 928 ms 36492 KB
19.txt AC 876 ms 36820 KB
20.txt AC 837 ms 36080 KB
21.txt AC 887 ms 37160 KB
22.txt AC 879 ms 36492 KB
23.txt AC 3 ms 7552 KB
s1.txt AC 3 ms 7552 KB
s2.txt AC 3 ms 7552 KB
s3.txt AC 3 ms 7552 KB