結果

問題 No.2544 Many RMQ Problems
ユーザー AngrySadEightAngrySadEight
提出日時 2023-08-22 12:29:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 769 ms / 2,000 ms
コード長 3,698 bytes
コンパイル時間 4,923 ms
コンパイル使用メモリ 222,140 KB
実行使用メモリ 19,404 KB
最終ジャッジ日時 2024-05-09 18:09:33
合計ジャッジ時間 27,398 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 686 ms
19,300 KB
testcase_01 AC 711 ms
19,132 KB
testcase_02 AC 690 ms
19,236 KB
testcase_03 AC 769 ms
19,404 KB
testcase_04 AC 681 ms
19,328 KB
testcase_05 AC 678 ms
19,308 KB
testcase_06 AC 698 ms
19,224 KB
testcase_07 AC 680 ms
19,280 KB
testcase_08 AC 705 ms
19,328 KB
testcase_09 AC 700 ms
19,228 KB
testcase_10 AC 678 ms
19,284 KB
testcase_11 AC 763 ms
19,304 KB
testcase_12 AC 715 ms
19,232 KB
testcase_13 AC 763 ms
19,228 KB
testcase_14 AC 689 ms
19,304 KB
testcase_15 AC 695 ms
19,328 KB
testcase_16 AC 703 ms
19,248 KB
testcase_17 AC 699 ms
19,248 KB
testcase_18 AC 706 ms
19,132 KB
testcase_19 AC 721 ms
19,328 KB
testcase_20 AC 711 ms
19,248 KB
testcase_21 AC 716 ms
19,328 KB
testcase_22 AC 703 ms
19,232 KB
testcase_23 AC 714 ms
19,328 KB
testcase_24 AC 712 ms
19,300 KB
testcase_25 AC 703 ms
19,328 KB
testcase_26 AC 713 ms
19,320 KB
testcase_27 AC 688 ms
19,328 KB
testcase_28 AC 676 ms
19,200 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <atcoder/all>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using namespace atcoder;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define repk(i, k, n) for (int i = k; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define mod1 1000000007
#define mod2 998244353
#define mod3 100000007
#define vi vector<int>
#define vs vector<string>
#define vc vector<char>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vector<int>>
#define vvc vector<vector<char>>
#define vvl vector<vector<ll>>
#define vvb vector<vector<bool>>
#define vvvi vector<vector<vector<int>>>
#define vvvl vector<vector<vector<ll>>>
#define pii pair<int, int>
#define pil pair<int, ll>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define vpii vector<pair<int, int>>
#define vpll vector<pair<ll, ll>>
#define vvpii vector<vector<pair<int, int>>>
#define vvpll vector<vector<pair<ll, ll>>>

using mint = modint998244353;

template <typename T>
void debug(T e) {
    cerr << e << endl;
}

template <typename T>
void debug(vector<T> &v) {
    rep(i, v.size()) { cerr << v[i] << " "; }
    cerr << endl;
}

template <typename T>
void debug(vector<vector<T>> &v) {
    rep(i, v.size()) {
        rep(j, v[i].size()) { cerr << v[i][j] << " "; }
        cerr << endl;
    }
}

template <typename T>
void debug(vector<pair<T, T>> &v) {
    rep(i, v.size()) { cerr << v[i].first << " " << v[i].second << endl; }
}

template <typename T>
void debug(set<T> &st) {
    for (auto itr = st.begin(); itr != st.end(); itr++) {
        cerr << *itr << " ";
    }
    cerr << endl;
}

template <typename T>
void debug(multiset<T> &ms) {
    for (auto itr = ms.begin(); itr != ms.end(); itr++) {
        cerr << *itr << " ";
    }
    cerr << endl;
}

template <typename T>
void debug(map<T, T> &mp) {
    for (auto itr = mp.begin(); itr != mp.end(); itr++) {
        cerr << itr->first << " " << itr->second << endl;
    }
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << H << " ";
    debug_out(T...);
}

ll my_pow(ll x, ll n, ll mod) {
    //  繰り返し二乗法.x^nをmodで割った余り.
    ll ret;
    if (n == 0) {
        ret = 1;
    } else if (n % 2 == 1) {
        ret = (x * my_pow((x * x) % mod, n / 2, mod)) % mod;
    } else {
        ret = my_pow((x * x) % mod, n / 2, mod);
    }
    return ret;
}

ll inv(ll x, ll mod) { return my_pow(x, mod - 2, mod); }

int main() {
    ll N, Q;
    cin >> N >> Q;
    assert(1 <= N && N <= 1000000);
    assert(1 <= Q && Q <= 1000000);
    vector<ll> fact(1020003);
    fact[0] = 1;
    for (ll i = 0; i < 1020002; i++) {
        fact[i + 1] = (fact[i] * (i + 1)) % mod2;
    }
    vector<ll> numinv(1020003);
    for (ll i = 1; i < 1020003; i++) {
        numinv[i] = inv(i, mod2);
    }
    ll ans = 0;
    for (ll i = 1; i <= N; i++) {
        ll num = fact[N + 1];
        num = (num * numinv[i + 1]) % mod2;
        num = (num * (N - i + 1)) % mod2;
        ans = (ans + num) % mod2;
    }
    ans = (ans * Q) % mod2;
    ll toori = (N * (N + 1) / 2);
    toori %= mod2;
    ans = (ans * my_pow(toori, Q - 1, mod2)) % mod2;
    cout << ans << endl;
}
0