結果
問題 | No.3026 Range LCM (Online Version) |
ユーザー |
|
提出日時 | 2025-02-14 23:05:30 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 3,737 bytes |
コンパイル時間 | 6,301 ms |
コンパイル使用メモリ | 336,620 KB |
実行使用メモリ | 814,708 KB |
最終ジャッジ日時 | 2025-02-14 23:06:40 |
合計ジャッジ時間 | 68,648 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 10 MLE * 26 |
ソースコード
#include <bits/stdc++.h>using namespace std;#include <atcoder/all>using namespace atcoder;using mint = modint998244353;using vm = vector<mint>;using vvm = vector<vm>;inline ostream &operator<<(ostream &os, const mint x){return os << x.val();};inline istream &operator>>(istream &is, mint &x){long long v;is >> v;x = v;return is;};struct Fast{Fast(){std::cin.tie(nullptr);ios::sync_with_stdio(false);cout << setprecision(10);}} fast;#define all(a) (a).begin(), (a).end()#define contains(a, x) ((a).find(x) != (a).end())#define rep(i, a, b) for (int i = (a); i < (int)(b); i++)#define rrep(i, a, b) for (int i = (int)(b) - 1; i >= (a); i--)#define YN(b) cout << ((b) ? "YES" : "NO") << "\n";#define Yn(b) cout << ((b) ? "Yes" : "No") << "\n";#define yn(b) cout << ((b) ? "yes" : "no") << "\n";using ll = long long;using vl = vector<ll>;using vi = vector<int>;using vvi = vector<vi>;int opmax(int x, int y) { return max(x, y); }int opor(int x, int y) { return x | y; }int e() { return 0; }void solve(){const int m = 200200;const int sq = 500;vi ps, lpf(m + 1);rep(i, 0, m + 1) lpf[i] = i;rep(i, 2, m + 1){if (lpf[i] == i){ps.push_back(i);for (int j = i; j <= m; j += i)if (lpf[j] > i) lpf[j] = i;}}map<int, int> ps_idx;rep(i, 0, ps.size()) ps_idx[ps[i]] = i;const int B = 10;int n;cin >> n;vi a(n);rep(i, 0, n) cin >> a[i];vi ps_small, ps_large;for (auto p : ps){if (p < sq)ps_small.push_back(p);elseps_large.push_back(p);}int x0 = ps_idx[ps_large[0]];vector<segtree<int, opmax, e>> seg_small(ps_small.size());rep(i, 0, seg_small.size()) seg_small[i] = segtree<int, opmax, e>(n);vector<segtree<int, opor, e>> seg_large((ps_large.size() + B - 1) / B);rep(i, 0, seg_large.size()) seg_large[i] = segtree<int, opor, e>(n);rep(i, 0, a.size()){int v = a[i];while (v > 1){int p = lpf[v];int c = 0;while (v % p == 0){v /= p;c++;}if (p < sq)seg_small[ps_idx[p]].set(i, c);else{int x = ps_idx[p] - x0;seg_large[x / B].set(i, 1 << (x % B));}}}vvi pow(seg_small.size());rep(i, 0, pow.size()){int p = ps_small[i];int sz = seg_small[i].all_prod();pow[i] = vi(sz + 1);pow[i][0] = 1;rep(j, 1, pow[i].size())pow[i][j] = pow[i][j - 1] * p;}vvm prod(seg_large.size());rep(i, 0, prod.size()){int sz = seg_large[i].all_prod();int c = min(B, (int)ps_large.size() - i * B);prod[i] = vm(sz + 1, 1);rep(j, 0, prod[i].size()) rep(k, 0, c) if (((j >> k) & 1) == 1) prod[i][j] *= ps_large[i * B + k];}int q;cin >> q;const ll MOD = 998244353;mint prv_ans = 1;while (q-- > 0){ll x, z;cin >> x >> z;x = (x * prv_ans).val(), z = (z * prv_ans).val();ll y = x % n, w = z % n;int l = (int)min(y, w), r = (int)max(y, w) + 1;mint ans = 1;rep(i, 0, seg_small.size())ans *= pow[i][seg_small[i].prod(l, r)];rep(i, 0, seg_large.size())ans *= prod[i][seg_large[i].prod(l, r)];cout << ans.val() << "\n";prv_ans = ans.val();}}int main(){int t = 1;// cin >> t;while (t--)solve();}