結果

問題 No.3110 WIP Editorial
ユーザー KumaTachiRenKumaTachiRen
提出日時 2024-03-06 13:29:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 556 ms / 4,000 ms
コード長 1,927 bytes
コンパイル時間 4,760 ms
コンパイル使用メモリ 276,984 KB
実行使用メモリ 28,652 KB
最終ジャッジ日時 2024-03-10 01:02:45
合計ジャッジ時間 9,659 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 354 ms
9,088 KB
testcase_02 AC 431 ms
15,360 KB
testcase_03 AC 443 ms
16,384 KB
testcase_04 AC 521 ms
27,136 KB
testcase_05 AC 540 ms
28,352 KB
testcase_06 AC 556 ms
28,652 KB
testcase_07 AC 552 ms
28,652 KB
testcase_08 AC 550 ms
28,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using namespace atcoder;

struct Fast {
  Fast() {
    std::cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(10);
  }
} fast;

#define rep(i, a, b) for (int(i) = (a); (i) < (int)(b); (i)++)

using ll = long long;
using mint = modint998244353;

struct S {
  int size;
  mint value;
};
struct F {
  bool is_set;
  mint value;
};
S op(S x, S y) { return {x.size + y.size, x.value + y.value}; }
S e() { return {0, 0}; }
S mapping(F f, S x) { return {x.size, f.value * x.size + (f.is_set ? 0 : x.value)}; }
F id() { return {false, 0}; }
F composition(F f, F g) { return f.is_set ? f : F{g.is_set, f.value + g.value}; }
using lst = lazy_segtree<S, op, e, F, mapping, composition, id>;

int main() {
  const int P_MAX = 100;
  vector<int> primes;
  for (int x = 2; x <= P_MAX; x++) {
    bool ok = true;
    for (auto p : primes) ok &= x % p > 0;
    if (ok) primes.push_back(x);
  }
  int c = primes.size();

  int n;
  cin >> n;
  vector<vector<S>> data(c, vector<S>(n));
  rep(i, 0, n) {
    ll a;
    cin >> a;
    rep(j, 0, c) {
      int v = 0, p = primes[j];
      for (; a % p == 0; a /= p) v++;
      data[j][i] = {1, v};
    }
  }
  vector<lst> seg(c);
  rep(i, 0, c) seg[i] = lst(data[i]);

  int q;
  cin >> q;
  while (q--) {
    int t, l, r;
    ll x;
    cin >> t >> l >> r >> x;
    l--;
    if (t == 1) {
      rep(i, 0, c) {
        int v = 0, p = primes[i];
        for (; x % p == 0; x /= p) v++;
        seg[i].apply(l, r, F{true, v});
      }
    } else if (t == 2) {
      rep(i, 0, c) {
        int v = 0, p = primes[i];
        for (; x % p == 0; x /= p) v++;
        seg[i].apply(l, r, F{false, v});
      }
    } else {
      mint ans = 1;
      rep(i, 0, c) {
        int p = primes[i];
        if (p > x) break;
        ans *= seg[i].prod(l, r).value + 1;
      }
      cout << ans.val() << "\n";
    }
  }
}
0