結果
| 問題 |
No.1067 #いろいろな色 / Red and Blue and more various colors (Middle)
|
| コンテスト | |
| ユーザー |
veqcc
|
| 提出日時 | 2020-05-29 23:48:28 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 420 ms / 2,000 ms |
| コード長 | 3,057 bytes |
| コンパイル時間 | 1,143 ms |
| コンパイル使用メモリ | 114,800 KB |
| 実行使用メモリ | 284,928 KB |
| 最終ジャッジ日時 | 2024-11-06 08:58:33 |
| 合計ジャッジ時間 | 5,126 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 25 |
ソースコード
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 998244353;
template <ll mod> class ModInt {
ll a;
public:
constexpr ModInt(const ll a = 0) noexcept : a((a % mod + mod) % mod) {}
constexpr ll &value() noexcept { return a; }
constexpr ModInt operator + (const ModInt &rhs) const noexcept { return ModInt(*this) += rhs; }
constexpr ModInt operator - (const ModInt &rhs) const noexcept { return ModInt(*this) -= rhs; }
constexpr ModInt operator * (const ModInt &rhs) const noexcept { return ModInt(*this) *= rhs; }
constexpr ModInt operator / (const ModInt &rhs) const noexcept { return ModInt(*this) /= rhs; }
constexpr ModInt &operator += (const ModInt &rhs) noexcept {
a += rhs.a;
if (a >= mod) a -= mod;
return *this;
}
constexpr ModInt &operator -= (const ModInt &rhs) noexcept {
a += mod - rhs.a;
if (a >= mod) a -= mod;
return *this;
}
constexpr ModInt &operator *= (const ModInt &rhs) noexcept {
a = a * rhs.a % mod;
return *this;
}
constexpr ModInt pow(ll t) const noexcept {
if (t == 0) return 1;
auto ret = pow(t >> 1);
ret *= ret;
if (t & 1) ret *= *this;
return ret;
}
constexpr ModInt inv() const noexcept { return pow(mod - 2); }
constexpr ModInt operator /=(const ModInt &rhs) { return (*this) *= rhs.inv(); }
constexpr bool operator == (const ModInt &rhs) const noexcept { return this->a == rhs.a; }
constexpr bool operator != (const ModInt &rhs) const noexcept { return this->a != rhs.a; }
friend constexpr ostream &operator << (ostream &os, const ModInt &rhs) noexcept { return os << rhs.a; }
friend constexpr istream &operator >> (istream &is, ModInt &rhs) {
is >> rhs.a;
return is;
}
};
using mint = ModInt<MOD>;
typedef pair<int, int> P;
int main() {
int n, q;
cin >> n >> q;
vector<ll> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
sort(a.begin(), a.end());
vector<mint> as(n + 1, 1);
for (int i = 0; i < n; i++) as[i + 1] = as[i] * a[i];
reverse(a.begin(), a.end());
vector<vector<mint>> dp(n + 1, vector<mint>(n + 1, 0));
dp[0][0] = 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j <= n; j++) {
dp[i + 1][j] = dp[i][j] * (a[i] - 1);
if (j) dp[i + 1][j] += dp[i][j - 1];
}
}
reverse(a.begin(), a.end());
for (int i = 0; i < q; i++) {
int l, r, p;
cin >> l >> r >> p;
ll ret = 0;
for (int j = l; j <= r; j++) {
int idx = lower_bound(a.begin(), a.end(), j) - a.begin();
mint x = as[idx] * dp[n - idx][p];
ret ^= x.value();
}
cout << ret % MOD << endl;
}
return 0;
}
veqcc