結果

問題 No.2273 一点乗除区間積
ユーザー risujirohrisujiroh
提出日時 2023-04-14 22:53:36
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,621 bytes
コンパイル時間 3,843 ms
コンパイル使用メモリ 288,776 KB
実行使用メモリ 8,448 KB
最終ジャッジ日時 2024-04-18 20:28:45
合計ジャッジ時間 10,476 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,248 KB
testcase_03 AC 2 ms
5,376 KB
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#include <atcoder/modint>
#include <atcoder/segtree>

using namespace std;

map<int, int> factor(int n) {
  map<int, int> ret;
  for (int i = 2; i * i <= n; ++i) {
    while (n % i == 0) {
      ++ret[i];
      n /= i;
    }
  }
  if (1 < n) {
    ++ret[n];
  }
  return ret;
}

using atcoder::modint;

vector<int> ps;

struct S {
  modint r;
  array<int, 9> e;
};

S op(S x, S y) {
  auto e = x.e;
  for (size_t j = 0; j < size(e); ++j) {
    e[j] += y.e[j];
  }
  return {x.r * y.r, e};
}
S e() { return {1, {}}; }

S makeS(int64_t A) {
  auto s = e();
  for (size_t j = 0; j < size(ps); ++j) {
    while (A % ps[j] == 0) {
      ++s.e[j];
      A /= ps[j];
    }
  }
  s.r = A;
  return s;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int N, B, Q;
  cin >> N >> B >> Q;

  modint::set_mod(B);

  for (auto [p, e] : factor(B)) {
    ps.push_back(p);
  }

  atcoder::segtree<S, op, e> seg(N);

  for (int i = 0; i < N; ++i) {
    int64_t A;
    cin >> A;

    seg.set(i, makeS(A));
  }

  while (Q--) {
    int i;
    int64_t m;
    int l, r;
    cin >> i >> m >> l >> r;
    ++r;

    auto s = makeS(m);
    if (m == B) {
      bool multiple = true;
      auto e = seg.get(i).e;
      for (size_t j = 0; j < size(ps); ++j) {
        multiple &= s.e[j] <= e[j];
      }
      if (multiple) {
        for (int& x : s.e) {
          x = -x;
        }
      }
    }
    seg.set(i, op(seg.get(i), s));
    s = seg.prod(l, r);
    auto ans = s.r;
    for (size_t j = 0; j < size(ps); ++j) {
      ans *= modint(ps[j]).pow(s.e[j]);
    }
    cout << ans.val() << '\n';
  }
}
0