ログイン
新規登録
AtsuoCoder Waseda Tour Finals 2025
読込中…
Home
Tasks
Clar
Submissions
Standings
提出 12d61bd2-21b7-4e43-9418-9c11984a541a
コード
#include <bits/stdc++.h> using namespace std; #include <atcoder/all> using namespace atcoder; using ll = long long; using xy = pair<ll, ll>; xy op(xy a, xy b) { if (a == xy{-1ll, -1ll}) return b; else if (b == xy{-1ll, -1ll}) return a; if (a == xy{0ll, 0ll} || b == xy{0ll, 0ll}) return xy{0ll, 0ll}; xy res = crt(vector<ll>{a.first, b.first}, vector<ll>{a.second, b.second}); if (res == xy{0ll, 0ll}) return xy{0ll, 0ll}; else if (res.first >= INT_MAX) return xy{0ll, 0ll}; else return res; } xy e() { return {-1ll, -1ll}; } int main() { ll n; cin >> n; vector<ll> a(n), b(n); for (int i = 0; i < n; i++) cin >> a[i] >> b[i]; vector<xy> init(n); for (int i = 0; i < n; i++) init[i].first = a[i], init[i].second = b[i]; segtree<xy, op, e> seg(init); int q; cin >> q; while (q--) { int l, r; cin >> l >> r; xy res = seg.prod(--l, r); if (res == xy{0, 0} || res.first >= INT_MAX) cout << -1 << endl; else cout << res.first << endl; } }
結果
問題
点数
言語
結果
実行時間
メモリ
I - Segment CRT
50
C++
WA
308 ms
10400 KiB