結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
15,336 KB
testcase_01 AC 16 ms
15,360 KB
testcase_02 AC 17 ms
15,392 KB
testcase_03 AC 17 ms
16,580 KB
testcase_04 AC 18 ms
16,272 KB
testcase_05 AC 17 ms
15,312 KB
testcase_06 AC 16 ms
15,204 KB
testcase_07 AC 19 ms
16,224 KB
testcase_08 AC 20 ms
16,432 KB
testcase_09 AC 21 ms
16,648 KB
testcase_10 AC 18 ms
16,528 KB
testcase_11 AC 18 ms
16,148 KB
testcase_12 AC 19 ms
16,040 KB
testcase_13 AC 20 ms
16,528 KB
testcase_14 AC 19 ms
16,552 KB
testcase_15 AC 19 ms
16,328 KB
testcase_16 AC 19 ms
15,764 KB
testcase_17 AC 18 ms
16,044 KB
testcase_18 AC 20 ms
16,396 KB
testcase_19 AC 19 ms
16,032 KB
testcase_20 AC 19 ms
16,228 KB
testcase_21 AC 18 ms
16,628 KB
testcase_22 AC 18 ms
15,980 KB
testcase_23 AC 18 ms
16,672 KB
testcase_24 AC 19 ms
16,488 KB
testcase_25 AC 20 ms
16,552 KB
testcase_26 AC 16 ms
15,156 KB
testcase_27 AC 16 ms
15,356 KB
testcase_28 AC 18 ms
16,496 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;
	assert(1 <= N && N <= 2e5);
	assert(0 <= Q && Q <= 60);
	vi imos(N+1,0);
	rep(i,Q){
		ll L,R;
		cin >> L >> R;
		assert(1 <= L && L <= R && R <= N);
		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