結果

問題 No.1067 #いろいろな色 / Red and Blue and more various colors (Middle)
ユーザー tomatoma
提出日時 2020-05-29 23:14:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 4,242 bytes
コンパイル時間 2,007 ms
コンパイル使用メモリ 185,276 KB
実行使用メモリ 13,632 KB
最終ジャッジ日時 2024-11-06 07:47:13
合計ジャッジ時間 7,497 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 RE -
testcase_02 RE -
testcase_03 WA -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using tp3 = tuple<int, int, int>;
using Mat = vector<vector<ll>>;
constexpr int INF = 1 << 28;
constexpr ll INFL = 1ll << 60;
constexpr int dh[4] = { 0,1,0,-1 };
constexpr int dw[4] = { -1,0,1,0 };
bool isin(const int H, const int W, const int h, const int w) {
    return 0 <= h && h < H && 0 <= w && w < W;
}

struct ModInt {
    static const ll MOD = 998244353;

    // constructors etc
    ModInt() :num(1ll) {}
    ModInt(ll num_) :num(num_%MOD) {}
    ModInt(const ModInt& modint) :num(modint.num%MOD) {}
    ll get()const { return num; }

    // operator etc
    // operator ll() const { return num; }
    // ll operator*() { return num; }
    ModInt& operator+=(const ModInt& r) { (num += r.num) %= MOD; return *this; }
    ModInt& operator-=(const ModInt& r) { (num += -r.num + MOD) %= MOD; return *this; }
    ModInt& operator*=(const ModInt& r) { (num *= r.num) %= MOD; return *this; }
    ModInt& operator/=(const ModInt& r) { (num *= r.inv().num) %= MOD; return *this; }
    ModInt pow(const ModInt& r)const {
        ll res = 1;
        ll x = num;
        ll n = r.num;
        while (n > 0) {
            if (n & 1)res = (res*x) % MOD;
            x = (x*x) % MOD;
            n >>= 1;
        }
        return res;
    }
    ModInt inv()const { return this->pow(MOD - 2); }

    ModInt operator+(const ModInt& r)const { return ModInt(*this) += r; }
    ModInt operator-(const ModInt& r)const { return ModInt(*this) -= r; }
    ModInt operator*(const ModInt& r)const { return ModInt(*this) *= r; }
    ModInt operator/(const ModInt& r)const { return ModInt(*this) /= r; }
    ModInt operator+(const ll& r)const { return *this + ModInt(r); }
    ModInt operator-(const ll& r)const { return *this - ModInt(r); }
    ModInt operator*(const ll& r)const { return *this * ModInt(r); }
    ModInt operator/(const ll& r)const { return *this / ModInt(r); }

private:
    ll num;
};
ostream& operator<<(ostream& stream, const ModInt& val) { stream << val.get(); return stream; }

// ============ template finished ============

int main()
{
    int N, Q;
    cin >> N >> Q;
    vector<ll> A(N), B(Q);
    rep(i, N)cin >> A[i];
    sort(A.begin(), A.end());
    reverse(A.begin(), A.end());

    vector<vector<ll>> dp(N, vector<ll>(N + 1, 0));
    dp[0][0] = A[0] - 1;
    dp[0][1] = 1;

    const ll MOD = 998244353;
    REP(i, 1, N) {
        dp[i][0] = dp[i - 1][0] * (A[i] - 1) % MOD;
        REP(j, 1, N + 1) {
            dp[i][j] = (dp[i - 1][j - 1] + dp[i - 1][j] * (A[i] - 1)) % MOD;
        }
    }
    vector<ll> muls = A;
    for (int i = A.size() - 1; i >= 1; i--) {
        muls[i - 1] *= muls[i];
    }


    vector<vector<ll>> dp2;
    vector<ll> A2;
    vector<ll> muls2;
    set<ll> used;
    for (int i = N - 1; i >= 0; i--)if (used.find(A[i]) == used.end()) {
        dp2.push_back(dp[i]);
        A2.push_back(A[i]);
        muls2.push_back(muls[i]);
        used.insert(A[i]);
    }
    reverse(dp2.begin(), dp2.end());
    reverse(A2.begin(), A2.end());
    reverse(muls2.begin(), muls2.end());

    // output
    rep(i, Q) {
        ll l, r, p;
        cin >> l >> r >> p;
        int ridx = 0;
        while (A2[ridx] > r)ridx++;

        ll res = [&]() {
            if (A2[ridx] == r) {
                return 0ll;
            }
            else {
                ll base = dp2[ridx - 1][p];
                ll diff = [&]() {
                    if (l < A2[ridx])return r - l + 1;
                    else return r - A2[ridx];
                }();
                return base * muls2[ridx] * (diff % 2);
            }
        }();
        // dp[ridx][p] * ((r - A[ridx] + 1) % 2);
        while (ridx<A2.size() - 1 && A2[ridx + 1] > l) {
            ll base = dp2[ridx][p] * muls2[ridx + 1];
            ll diff = A2[ridx] - A2[ridx + 1];
            res ^= base * (diff % 2);
            ridx++;
        }
        ll base = dp2[ridx][p] * (ridx == A2.size() - 1 ? 1 : muls2[ridx + 1]);
        ll diff = A[ridx] - l + 1;
        res ^= base * (diff % 2);
        cout << res << endl;
    }
    return 0;
}
0