結果

問題 No.2336 Do you like typical problems?
ユーザー lgswdnlgswdn
提出日時 2023-06-02 22:15:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 174 ms / 2,000 ms
コード長 2,247 bytes
コンパイル時間 2,115 ms
コンパイル使用メモリ 205,968 KB
実行使用メモリ 19,928 KB
最終ジャッジ日時 2023-08-28 03:54:39
合計ジャッジ時間 4,406 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,536 KB
testcase_01 AC 2 ms
5,600 KB
testcase_02 AC 2 ms
5,536 KB
testcase_03 AC 2 ms
5,652 KB
testcase_04 AC 2 ms
5,592 KB
testcase_05 AC 2 ms
5,540 KB
testcase_06 AC 2 ms
5,540 KB
testcase_07 AC 2 ms
5,656 KB
testcase_08 AC 3 ms
5,660 KB
testcase_09 AC 3 ms
5,664 KB
testcase_10 AC 3 ms
5,644 KB
testcase_11 AC 4 ms
5,788 KB
testcase_12 AC 3 ms
5,668 KB
testcase_13 AC 174 ms
19,796 KB
testcase_14 AC 173 ms
19,716 KB
testcase_15 AC 171 ms
19,928 KB
testcase_16 AC 172 ms
19,788 KB
testcase_17 AC 173 ms
19,744 KB
testcase_18 AC 56 ms
13,476 KB
testcase_19 AC 64 ms
13,688 KB
testcase_20 AC 116 ms
19,740 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define mp make_pair
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 i128;
template<typename T,typename U>
T ceil(T x, U y) {return (x>0?(x+y-1)/y:x/y);}
template<typename T,typename U>
T floor(T x, U y) {return (x>0?x/y:(x-y+1)/y);}
template<class T,class S>
bool chmax(T &a,const S b) {return (a<b?a=b,1:0);}
template<class T,class S>
bool chmin(T &a,const S b) {return (a>b?a=b,1:0);}
int popcnt(int x) {return __builtin_popcount(x);}
int popcnt(ll x) {return __builtin_popcountll(x);}
int topbit(int x) {return (x==0?-1:31-__builtin_clz(x));}
int topbit(ll x) {return (x==0?-1:63-__builtin_clzll(x));}
int lowbit(int x) {return (x==0?-1:__builtin_ctz(x));}
int lowbit(ll x) {return (x==0?-1:__builtin_ctzll(x));}

#define int long long
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vp;
int read() {
  int x=0,w=1; char c=getchar(); 
  while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
  while(isdigit(c)) {x=x*10+(c-'0'); c=getchar();}
  return x*w;
}

const int mod=998244353,N=4e5+9,inv2=(mod+1)/2;
int n,len[N],b[N],cnt,d[N],d2[N];
pii p[N];

int ksm(int x,int y,int r=1) {
  for(;y;y>>=1,x=x*x%mod) if(y&1) r=r*x%mod;
  return r;
}

signed main() {
  n=read();
  rep(i,1,n) p[i].fi=read(), p[i].se=read();
  sort(p+1,p+n+1);
  rep(i,1,n) len[i]=p[i].se-p[i].fi+1;
  int ans=1,prod=1,sum=0;
  rep(i,1,n) ans=ans*i%mod;
  prod=ans*inv2%mod;
  ans=ans*n%mod*(n-1)%mod;
  ans=ans*ksm(4,mod-2)%mod;
  rep(i,1,n) b[++cnt]=p[i].fi, b[++cnt]=p[i].se+1;
  sort(b+1,b+cnt+1); cnt=unique(b+1,b+cnt+1)-b-1;
  rep(i,1,n) {
    int x=lower_bound(b+1,b+cnt+1,p[i].fi)-b;
    int y=lower_bound(b+1,b+cnt+1,p[i].se+1)-b;
    int p=ksm(len[i],mod-2), q=p*p%mod;
    d[x]=(d[x]+p)%mod, d[y]=(d[y]+mod-p)%mod;
    d2[x]=(d2[x]+q)%mod, d2[y]=(d2[y]+mod-q)%mod;
  }
  int cur=0,cur2=0;
  rep(i,1,cnt) {
    cur=(cur+d[i])%mod;
    cur2=(cur2+d2[i])%mod;
    int f=(cur*cur%mod+mod-cur2)%mod*inv2%mod;
    ans=(ans+mod-(b[i+1]-b[i])*f%mod*prod%mod)%mod;
  }
  printf("%lld\n",ans);
  return 0;
}
0