結果

問題 No.2875 What is My Rank?
ユーザー 沙耶花
提出日時 2024-09-06 22:14:56
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 757 bytes
コンパイル時間 4,109 ms
コンパイル使用メモリ 252,620 KB
最終ジャッジ日時 2025-02-24 04:27:49
ジャッジサーバーID
(参考情報)
judge4 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 6 WA * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 1000000000000000001

int main(){
	int N;
	cin>>N;
	int L,R;
	cin>>L>>R;
	mint ans = 1;
	rep(i,N-1){
		int l,r;
		cin>>l>>r;
		if(l>R)continue;//ans++;
		else if(L>r)continue;
		else{
			int sl = max(L,l), sr = min(R,r);
			mint pp = (R-L+1);
			pp *= (r-l+1);
			{
				mint n =sr-sl+1;
				mint cnt = n * (n-1)/2;
				
				ans += cnt / pp;
			}
			if(L<sl){
				mint p = R-L+1;
				ans += mint(sl-L) / p;
			}
			if(r>sr){
				mint p = r-l+1;
				ans += mint(r-sr) / p;
			}
			
		}
	}
	cout<<ans.val()<<endl;
	
    return 0;
}
0