ログイン
新規登録
AtsuoCoder Waseda Tour Finals 2025
読込中…
Home
Tasks
Clar
Submissions
Standings
提出 c4d83c93-87d1-45eb-a357-ca3daa60a8af
コード
#include<bits/stdc++.h> #include<atcoder/all> using namespace std; using namespace atcoder; using ll=long long; const ll inf=1e18,MAX=(1ll<<31)-1; using P=pair<ll,ll>; P op(P a,P b){ P p=crt(vector<ll>({a.first,b.first}),vector<ll>({a.second,b.second})); if(p.first==0) p.first+=p.second; if(p.first>MAX||p.second==0){ p.first=-1; p.second=MAX+2; } if(p.second>MAX+2) p.second=MAX+2; return p; } P e(){ return P(1,1); } int main(){ int n,a,b,q,l,r; cin>>n; assert(1<=n&&n<=100000); segtree<P,op,e>seg(n); for(int i=0;i<n;i++){ cin>>a>>b; assert(0<=a&&a<b&&b<=MAX); if(a==0) a+=b; seg.set(i,P(a,b)); } cin>>q; assert(1<=q&&q<=100000); for(int i=0;i<q;i++){ cin>>l>>r; assert(1<=l&&l<=r&&r<=n); l--; cout<<seg.prod(l,r).first<<endl; } }
結果
問題
点数
言語
結果
実行時間
メモリ
I - Segment CRT
150
C++
AC
369 ms
8880 KiB