結果
問題 | No.1067 #いろいろな色 / Red and Blue and more various colors (Middle) |
ユーザー | stoq |
提出日時 | 2020-11-04 05:43:12 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 5,292 bytes |
コンパイル時間 | 2,462 ms |
コンパイル使用メモリ | 217,684 KB |
実行使用メモリ | 284,444 KB |
最終ジャッジ日時 | 2024-07-22 09:40:01 |
合計ジャッジ時間 | 9,843 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
13,884 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,944 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | AC | 2 ms
6,944 KB |
testcase_07 | AC | 2 ms
6,940 KB |
testcase_08 | AC | 2 ms
6,940 KB |
testcase_09 | AC | 2 ms
6,944 KB |
testcase_10 | AC | 2 ms
6,940 KB |
testcase_11 | TLE | - |
testcase_12 | AC | 1,086 ms
141,952 KB |
testcase_13 | TLE | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
ソースコード
#define MOD_TYPE 2 #pragma region Macros #include <bits/stdc++.h> using namespace std; #if 0 #include <boost/multiprecision/cpp_int.hpp> #include <boost/multiprecision/cpp_dec_float.hpp> using Int = boost::multiprecision::cpp_int; using lld = boost::multiprecision::cpp_dec_float_100; #endif #if 0 #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #endif using ll = long long int; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; using pld = pair<ld, ld>; template <typename Q_type> using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>; constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353); constexpr int INF = (int)1e9 + 10; constexpr ll LINF = (ll)4e18; constexpr double PI = acos(-1.0); constexpr double EPS = 1e-7; constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0}; constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0}; #define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i) #define rep(i, n) REP(i, 0, n) #define REPI(i, m, n) for (int i = m; i < (int)(n); ++i) #define repi(i, n) REPI(i, 0, n) #define MP make_pair #define MT make_tuple #define YES(n) cout << ((n) ? "YES" : "NO") << "\n" #define Yes(n) cout << ((n) ? "Yes" : "No") << "\n" #define possible(n) cout << ((n) ? "possible" : "impossible") << "\n" #define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n" #define all(v) v.begin(), v.end() #define NP(v) next_permutation(all(v)) #define dbg(x) cerr << #x << ":" << x << "\n"; struct io_init { io_init() { cin.tie(0); ios::sync_with_stdio(false); cout << setprecision(30) << setiosflags(ios::fixed); }; } io_init; template <typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } inline ll CEIL(ll a, ll b) { return (a + b - 1) / b; } template <typename A, size_t N, typename T> inline void Fill(A (&array)[N], const T &val) { fill((T *)array, (T *)(array + N), val); } template <typename T, typename U> constexpr istream &operator>>(istream &is, pair<T, U> &p) noexcept { is >> p.first >> p.second; return is; } template <typename T, typename U> constexpr ostream &operator<<(ostream &os, pair<T, U> &p) noexcept { os << p.first << " " << p.second; return os; } #pragma endregion ll mod_pow(ll a, ll n, ll m) { ll res = 1, p = a % m; while (n) { if (n & 1) res = res * p % m; p = p * p % m; n >>= 1; } return res; } template <ll mod = 998244353, ll root = 3> //特殊な素数と原始根 998244353のとき3 class NTT { private: template <typename T> inline void bit_reverse(vector<T> &a) { int n = a.size(); int i = 0; for (int j = 1; j < n - 1; ++j) { for (int k = n >> 1; k > (i ^= k); k >>= 1) ; if (j < i) swap(a[i], a[j]); } } void _ntt(vector<long long> &a, int sign) { const int n = a.size(); assert((n ^ (n & -n)) == 0); //n = 2^k long long tmp = (mod - 1) * mod_pow((ll)n, mod - 2, mod) % mod; // -1/n long long h = mod_pow(root, tmp, mod); // ^n√g if (sign == -1) h = mod_pow(h, mod - 2, mod); bit_reverse(a); for (ll m = 1; m < n; m <<= 1) { const ll m2 = 2 * m; long long _base = mod_pow((ll)h, (ll)(n / m2), mod); long long _w = 1; for (int x = 0; x < m; ++x) { for (ll s = x; s < n; s += m2) { long long u = a[s]; long long d = (a[s + m] * _w) % mod; a[s] = (u + d) % mod; a[s + m] = (u - d + mod) % mod; } _w = (_w * _base) % mod; } } } void ntt(vector<long long> &input) { _ntt(input, 1); } void intt(vector<long long> &input) { _ntt(input, -1); const long long n_inv = mod_pow((ll)input.size(), mod - 2, mod); for (auto &x : input) x = (x * n_inv) % mod; } public: // 畳み込み演算を行う vector<long long> convolution(const vector<long long> &a, const vector<long long> &b) { int result_size = a.size() + b.size() - 1; int n = 1; while (n < result_size) n <<= 1; vector<long long> _a = a, _b = b; _a.resize(n, 0); _b.resize(n, 0); ntt(_a); ntt(_b); for (int i = 0; i < n; ++i) _a[i] = (_a[i] * _b[i]) % mod; intt(_a); _a.resize(result_size); return _a; } }; void solve() { NTT<> ntt; int n, q; cin >> n >> q; vector<ll> a(n); rep(i, n) cin >> a[i]; sort(all(a)); vector<ll> L(n + 1); vector<vector<ll>> R(n + 1); L[0] = 1; R[n].push_back(1); rep(i, n) { L[i + 1] = L[i] * a[i] % MOD; } for (int i = n; i > 0; i--) { vector<ll> f = {a[i - 1] - 1, 1}; R[i - 1] = ntt.convolution(R[i], f); } vector<vector<ll>> F(n + 1); rep(i, n + 1) { F[i] = R[i]; for (auto &&c : F[i]) c = c * L[i] % MOD; } rep(qi, q) { int l, r, p; cin >> l >> r >> p; ll ans = 0; REP(i, l, r + 1) { int idx = lower_bound(all(a), i) - a.begin(); if (p < F[idx].size()) ans ^= F[idx][p]; } ans %= MOD; cout << ans << "\n"; } } int main() { solve(); }