結果

問題 No.2336 Do you like typical problems?
ユーザー 👑 kmjpkmjp
提出日時 2023-06-02 22:36:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 418 ms / 2,000 ms
コード長 1,745 bytes
コンパイル時間 2,354 ms
コンパイル使用メモリ 207,628 KB
実行使用メモリ 37,732 KB
最終ジャッジ日時 2023-08-28 04:44:16
合計ジャッジ時間 6,422 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
23,960 KB
testcase_01 AC 10 ms
23,824 KB
testcase_02 AC 10 ms
23,808 KB
testcase_03 AC 9 ms
23,848 KB
testcase_04 AC 9 ms
23,840 KB
testcase_05 AC 10 ms
23,812 KB
testcase_06 AC 9 ms
23,820 KB
testcase_07 AC 10 ms
23,912 KB
testcase_08 AC 12 ms
24,024 KB
testcase_09 AC 12 ms
23,984 KB
testcase_10 AC 13 ms
23,952 KB
testcase_11 AC 13 ms
24,160 KB
testcase_12 AC 13 ms
23,968 KB
testcase_13 AC 418 ms
37,732 KB
testcase_14 AC 410 ms
37,728 KB
testcase_15 AC 412 ms
37,672 KB
testcase_16 AC 415 ms
37,724 KB
testcase_17 AC 410 ms
37,648 KB
testcase_18 AC 111 ms
27,956 KB
testcase_19 AC 121 ms
28,052 KB
testcase_20 AC 322 ms
37,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N;
int B[202020],C[202020];

vector<int> add[404040];
vector<int> del[404040];
const ll mo=998244353;

ll modpow(ll a, ll n = mo-2) {
	ll r=1;a%=mo;
	while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
	return r;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	vector<int> Xs={0};
	FOR(i,N) {
		cin>>B[i]>>C[i];
		C[i]++;
		Xs.push_back(B[i]);
		Xs.push_back(C[i]);
	}
	sort(ALL(Xs));
	Xs.erase(unique(ALL(Xs)),Xs.end());
	
	FOR(i,N) {
		x=lower_bound(ALL(Xs),B[i])-Xs.begin();
		y=lower_bound(ALL(Xs),C[i])-Xs.begin();
		add[x].push_back(modpow(C[i]-B[i]));
		del[y].push_back(modpow(C[i]-B[i]));
	}
	
	ll ret=1LL*N*(N-1)%mo*modpow(4)%mo;
	ll sum1=0,sum2=0;
	FOR(i,Xs.size()) {
		FORR(d,del[i]) {
			(sum1+=mo-d)%=mo;
			(sum2+=mo-sum1*d)%=mo;
		}
		FORR(d,add[i]) {
			(sum2+=sum1*d)%=mo;
			(sum1+=d)%=mo;
		}
		if(sum2) {
			(ret+=mo-sum2*(Xs[i+1]-Xs[i])%mo*modpow(2)%mo)%=mo;
		}
	}
	FOR(i,N) ret=ret*(i+1)%mo;
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0