結果

問題 No.2133 Take it easy!
ユーザー iro_iro_
提出日時 2022-11-03 21:48:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 1,395 bytes
コンパイル時間 1,690 ms
コンパイル使用メモリ 173,508 KB
実行使用メモリ 16,628 KB
最終ジャッジ日時 2024-04-10 02:07:51
合計ジャッジ時間 3,158 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
15,140 KB
testcase_01 AC 16 ms
15,248 KB
testcase_02 AC 16 ms
15,392 KB
testcase_03 AC 19 ms
16,540 KB
testcase_04 AC 18 ms
16,204 KB
testcase_05 AC 16 ms
15,344 KB
testcase_06 AC 17 ms
15,380 KB
testcase_07 AC 20 ms
16,228 KB
testcase_08 AC 19 ms
16,508 KB
testcase_09 AC 19 ms
16,556 KB
testcase_10 AC 19 ms
16,476 KB
testcase_11 AC 18 ms
16,176 KB
testcase_12 AC 18 ms
16,104 KB
testcase_13 AC 19 ms
16,436 KB
testcase_14 AC 19 ms
16,540 KB
testcase_15 AC 20 ms
16,516 KB
testcase_16 AC 18 ms
15,800 KB
testcase_17 AC 19 ms
16,216 KB
testcase_18 AC 19 ms
16,340 KB
testcase_19 AC 22 ms
16,028 KB
testcase_20 AC 17 ms
16,212 KB
testcase_21 AC 19 ms
16,340 KB
testcase_22 AC 18 ms
15,940 KB
testcase_23 AC 19 ms
16,536 KB
testcase_24 AC 20 ms
16,488 KB
testcase_25 AC 19 ms
16,628 KB
testcase_26 AC 15 ms
15,320 KB
testcase_27 AC 16 ms
15,312 KB
testcase_28 AC 18 ms
16,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (ll i = 0; i < n; ++ i)
using ll = long long ;
using vi = vector<ll>;
const ll mod = 998244353;
//----------------------------------------------------------------
const ll si_f = 5e5;
ll f[si_f+1], invf[si_f+1], inv[si_f+1];
ll modpow(ll n,ll m){
    ll res = 1;
    while (m) {
        if (m&1) res = res * n % mod;
        n = n * n % mod;
        m /= 2;
    }
    return res;
}
void init() {
    f[0] = f[1] = 1;
	invf[0] = invf[1] = 1;
	inv[1] = 1;
    for(ll i = 2; i < si_f; ++i){
		f[i] = f[i-1] * i % mod;
		inv[i] = mod - inv[mod%i] * (mod/i) % mod;
		invf[i] = invf[i-1] * inv[i] % mod;
	}
	return;
}
ll C(int n, int k) {
    ll a = f[n]; // = n!
    ll b = invf[n-k]; // = (n-k)!
    ll c = invf[k]; // = k!

    ll bc = (b * c) % mod;
  
    return (a * bc) % mod;
}
//----------------------------------------------------------------
int main(){
	init();
    int N,Q;
	cin >> N >> Q;
	vi imos(N+1,0);
	rep(i,Q){
		ll L,R;
		cin >> L >> R;
		imos[L-1] += (1LL<<i);
		imos[R] -= (1LL<<i);
	}
	rep(i,N) imos[i+1] += imos[i];
	map<ll,int> kukan;
	rep(i,N) ++kukan[imos[i]];
	ll res = f[N/2]*f[N - N/2] % mod;
	if(N%2 == 1) ++kukan[0];
	for(auto t:kukan){
		int l = t.second;
		if(l%2 == 0){
			int x = l/2;
			ll c = C(l,x) * modpow(x+1,mod-2) % mod;
			res = res * c % mod;
		} else res = 0;
	}
	cout << res << endl;
}
0