結果

問題 No.1067 #いろいろな色 / Red and Blue and more various colors (Middle)
ユーザー knshnbknshnb
提出日時 2020-05-30 02:56:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 226 ms / 2,000 ms
コード長 3,885 bytes
コンパイル時間 2,416 ms
コンパイル使用メモリ 208,316 KB
実行使用メモリ 144,384 KB
最終ジャッジ日時 2024-04-24 10:34:42
合計ジャッジ時間 4,824 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 137 ms
91,520 KB
testcase_12 AC 87 ms
56,064 KB
testcase_13 AC 185 ms
127,232 KB
testcase_14 AC 102 ms
71,296 KB
testcase_15 AC 42 ms
29,312 KB
testcase_16 AC 37 ms
23,296 KB
testcase_17 AC 8 ms
7,040 KB
testcase_18 AC 108 ms
74,368 KB
testcase_19 AC 111 ms
78,848 KB
testcase_20 AC 52 ms
31,488 KB
testcase_21 AC 225 ms
144,256 KB
testcase_22 AC 225 ms
144,256 KB
testcase_23 AC 226 ms
144,384 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>  // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Fri May 29 23:28:54 JST 2020
 **/

template <class T> T pow(T x, int n, const T UNION = 1) {
    T ret = UNION;
    while (n) {
        if (n & 1) ret *= x;
        x *= x;
        n >>= 1;
    }
    return ret;
}

/// @docs src/Math/ModInt.md
template <int Mod> struct ModInt {
    int x;
    static int runtime_mod;
    static std::unordered_map<int, int> to_inv;
    // テンプレート引数が負のときは実行時ModInt
    static int mod() { return Mod < 0 ? runtime_mod : Mod; }
    static void set_runtime_mod(int mod) {
        static_assert(Mod < 0, "template parameter Mod must be negative for runtime ModInt");
        runtime_mod = mod;
        to_inv.clear();
    }
    ModInt() : x(0) {}
    ModInt(long long x_) {
        if ((x = x_ % mod() + mod()) >= mod()) x -= mod();
    }

    ModInt& operator+=(ModInt rhs) {
        if ((x += rhs.x) >= mod()) x -= mod();
        return *this;
    }
    ModInt& operator*=(ModInt rhs) {
        x = (unsigned long long)x * rhs.x % mod();
        return *this;
    }
    ModInt& operator-=(ModInt rhs) {
        if ((x -= rhs.x) < 0) x += mod();
        return *this;
    }
    ModInt& operator/=(ModInt rhs) {
        x = (unsigned long long)x * rhs.inv().x % mod();
        return *this;
    }
    ModInt operator-() const { return -x < 0 ? mod() - x : -x; }
    ModInt operator+(ModInt rhs) const { return ModInt(*this) += rhs; }
    ModInt operator*(ModInt rhs) const { return ModInt(*this) *= rhs; }
    ModInt operator-(ModInt rhs) const { return ModInt(*this) -= rhs; }
    ModInt operator/(ModInt rhs) const { return ModInt(*this) /= rhs; }
    bool operator==(ModInt rhs) const { return x == rhs.x; }
    bool operator!=(ModInt rhs) const { return x != rhs.x; }
    ModInt inv() const { return to_inv.count(this->x) ? to_inv[this->x] : (to_inv[this->x] = pow(*this, mod() - 2).x); }

    friend std::ostream& operator<<(std::ostream& s, ModInt<Mod> a) {
        s << a.x;
        return s;
    }
    friend std::istream& operator>>(std::istream& s, ModInt<Mod>& a) {
        long long tmp;
        s >> tmp;
        a = ModInt<Mod>(tmp);
        return s;
    }
    friend std::string to_string(ModInt<Mod> a) { return std::to_string(a.x); }
};
template <int Mod> std::unordered_map<int, int> ModInt<Mod>::to_inv;
template <int Mod> int ModInt<Mod>::runtime_mod;

template <class T, class S> T make_vec(S x) { return x; }
template <class T, class... Ts> auto make_vec(size_t n, Ts... ts) {
    return std::vector<decltype(make_vec<T>(ts...))>(n, make_vec<T>(ts...));
}

#ifndef CALL_FROM_TEST
using mint = ModInt<998244353>;
#endif
const Int MOD = 998244353;
signed main() {
    Int n, Q;
    std::cin >> n >> Q;
    std::vector<Int> a(n);
    REP(i, n) std::cin >> a[i];
    std::sort(a.rbegin(), a.rend());
    auto dp = make_vec<mint>(n + 1, n + 1, 0);
    dp[0][0] = 1;
    REP(i, n) {
        REP(j, n) {
            dp[i + 1][j] += dp[i][j] * (a[i] - 1);
            dp[i + 1][j + 1] += dp[i][j];
        }
    }
    std::vector<mint> acc(n + 1, 1);
    for (Int i = n - 1; i >= 0; i--) acc[i] = acc[i + 1] * a[i];
    REP(q, Q) {
        Int l, r, p;
        std::cin >> l >> r >> p;
        Int ans = 0;
        REP(c, l, r + 1)  {
            Int idx = std::upper_bound(a.begin(), a.end(), c, std::greater<Int>()) - a.begin();
            ans ^= (dp[idx][p] * acc[idx]).x;
        }
        std::cout << ans % MOD << "\n";
    }
}
0