結果
問題 | No.1067 #いろいろな色 / Red and Blue and more various colors (Middle) |
ユーザー | toma |
提出日時 | 2020-05-29 23:16:54 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,301 bytes |
コンパイル時間 | 2,047 ms |
コンパイル使用メモリ | 185,728 KB |
実行使用メモリ | 499,328 KB |
最終ジャッジ日時 | 2024-11-06 07:53:41 |
合計ジャッジ時間 | 8,294 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,820 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | TLE | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
ソースコード
#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]) %= MOD; } 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 (ridx<A2.size() - 1 && 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) % MOD; } }(); // 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) % MOD); ridx++; } ll base = dp2[ridx][p] * (ridx == A2.size() - 1 ? 1 : muls2[ridx + 1]); ll diff = A[ridx] - l + 1; res ^= (base * (diff % 2)) % MOD; cout << res % MOD << endl; } return 0; }