結果
問題 | No.2273 一点乗除区間積 |
ユーザー | ei1333333 |
提出日時 | 2023-04-14 22:47:03 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 6,436 bytes |
コンパイル時間 | 2,383 ms |
コンパイル使用メモリ | 220,852 KB |
実行使用メモリ | 9,896 KB |
最終ジャッジ日時 | 2024-10-10 13:46:02 |
合計ジャッジ時間 | 9,442 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | TLE | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
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 | -- | - |
ソースコード
#include<bits/stdc++.h> using namespace std; using int64 = long long; const int mod = 998244353; const int64 infll = (1LL << 62) - 1; const int inf = (1 << 30) - 1; struct IoSetup { IoSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup; template< typename T1, typename T2 > ostream &operator<<(ostream &os, const pair< T1, T2 >& p) { os << p.first << " " << p.second; return os; } template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; } template< typename T > ostream &operator<<(ostream &os, const vector< T > &v) { for(int i = 0; i < (int) v.size(); i++) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } template< typename T > istream &operator>>(istream &is, vector< T > &v) { for(T &in : v) is >> in; return is; } template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); } template< typename T = int64 > vector< T > make_v(size_t a) { return vector< T >(a); } template< typename T, typename... Ts > auto make_v(size_t a, Ts... ts) { return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...)); } template< typename T, typename V > typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) { t = v; } template< typename T, typename V > typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e, v); } template< typename F > struct FixPoint : F { explicit FixPoint(F &&f) : F(forward< F >(f)) {} template< typename... Args > decltype(auto) operator()(Args &&... args) const { return F::operator()(*this, forward< Args >(args)...); } }; template< typename F > inline decltype(auto) MFP(F &&f) { return FixPoint< F >{forward< F >(f)}; } #line 1 "math/combinatorics/mod-pow.hpp" /** * @brief Mod Pow(べき乗) * @docs docs/mod-pow.md */ template< typename T > T mod_pow(T x, int64_t n, const T &p) { T ret = 1; while(n > 0) { if(n & 1) (ret *= x) %= p; (x *= x) %= p; n >>= 1; } return ret % p; } #line 1 "math/number-theory/prime-factor.hpp" map< int64_t, int > prime_factor(int64_t n) { map< int64_t, int > ret; for(int64_t i = 2; i * i <= n; i++) { while(n % i == 0) { ret[i]++; n /= i; } } if(n != 1) ret[n] = 1; return ret; } #line 1 "structure/segment-tree/segment-tree.hpp" /** * @brief Segment Tree(セグメント木) * @docs docs/segment-tree.md */ template< typename T, typename F > struct SegmentTree { int n, sz; vector< T > seg; const F f; const T ti; SegmentTree() = default; explicit SegmentTree(int n, const F f, const T &ti) : n(n), f(f), ti(ti) { sz = 1; while(sz < n) sz <<= 1; seg.assign(2 * sz, ti); } explicit SegmentTree(const vector< T > &v, const F f, const T &ti) : SegmentTree((int) v.size(), f, ti) { build(v); } void build(const vector< T > &v) { assert(n == (int) v.size()); for(int k = 0; k < n; k++) seg[k + sz] = v[k]; for(int k = sz - 1; k > 0; k--) { seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]); } } void set(int k, const T &x) { k += sz; seg[k] = x; while(k >>= 1) { seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]); } } T get(int k) const { return seg[k + sz]; } T operator[](const int &k) const { return get(k); } void apply(int k, const T &x) { k += sz; seg[k] = f(seg[k], x); while(k >>= 1) { seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]); } } T prod(int l, int r) const { T L = ti, R = ti; for(l += sz, r += sz; l < r; l >>= 1, r >>= 1) { if(l & 1) L = f(L, seg[l++]); if(r & 1) R = f(seg[--r], R); } return f(L, R); } T all_prod() const { return seg[1]; } template< typename C > int find_first(int l, const C &check) const { if(l >= n) return n; l += sz; T sum = ti; do { while((l & 1) == 0) l >>= 1; if(check(f(sum, seg[l]))) { while(l < sz) { l <<= 1; auto nxt = f(sum, seg[l]); if(not check(nxt)) { sum = nxt; l++; } } return l + 1 - sz; } sum = f(sum, seg[l++]); } while((l & -l) != l); return n; } template< typename C > int find_last(int r, const C &check) const { if(r <= 0) return -1; r += sz; T sum = ti; do { r--; while(r > 1 and (r & 1)) r >>= 1; if(check(f(seg[r], sum))) { while(r < sz) { r = (r << 1) + 1; auto nxt = f(seg[r], sum); if(not check(nxt)) { sum = nxt; r--; } } return r - sz; } sum = f(seg[r], sum); } while((r & -r) != r); return -1; } }; template< typename T, typename F > SegmentTree< T, F > get_segment_tree(int N, const F &f, const T &ti) { return SegmentTree{N, f, ti}; } template< typename T, typename F > SegmentTree< T, F > get_segment_tree(const vector< T > &v, const F &f, const T &ti) { return SegmentTree{v, f, ti}; } using u64 = uint64_t; struct fast_div { using u128 = __uint128_t; fast_div() {} fast_div(u64 n) : m(n) { s = (n == 1) ? 0 : 127 - __builtin_clzll(n - 1); x = ((u128(1) << s) + n - 1) / n; } friend u64 operator / (u64 n, fast_div d) { return u128(n) * d.x >> d.s; } friend u64 operator % (u64 n, fast_div d) { return n - n / d * d.m; } u64 m, s, x; }; int main() { int N, B, Q; cin >> N >> B >> Q; vector< u64 > A(N); cin >> A; auto P_ = prime_factor(B); vector< pair< int64, int > > P(P_.begin(), P_.end()); vector< fast_div > fd; fast_div fdB(B); for(int i = 0; i < P.size(); i++) fd.emplace_back(P[i].first); auto as = make_v< int >(P.size(), N); for(int i = 0; i < N; i++) { if(P[i].first == 2) { for (int j = 0; j < P.size(); j++) { while (A[i] % 2 == 0) { A[i] = A[i] / 2; ++as[j][i]; } } } else { for (int j = 0; j < P.size(); j++) { while (A[i] % fd[P[j].first] == 0) { A[i] = A[i] / fd[P[j].first]; ++as[j][i]; } } } A[i] %= B; } cout << A << endl; }