結果

問題 No.3026 Range LCM (Online Version)
ユーザー kmjp
提出日時 2025-02-23 01:13:57
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 2,824 bytes
コンパイル時間 2,685 ms
コンパイル使用メモリ 211,712 KB
実行使用メモリ 134,884 KB
最終ジャッジ日時 2025-02-23 01:14:23
合計ジャッジ時間 25,975 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 10 TLE * 1 -- * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------


const int B=202020;
const int DI=60;
vector<int> D[B];
int FD[202020];
ll dp[B/DI][B/DI];
vector<int> pos[B];
const ll mo=998244353;
int N,Q;
int A[B];
vector<pair<int,int>> pre[B],nex[B];
vector<pair<int,ll>> preS[B],nexS[B];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	for(i=2;i<=200000;i++) if(D[i].empty()) {
		for(j=i;j<=200000;j+=i) {
			FD[j]=i;
			x=j;
			while(x%i==0) x/=i;
			D[j].push_back(j/x);
		}
	}
	
	FOR(i,B) pos[i].push_back(0);
	
	cin>>N;
	FOR(i,B) A[i]=1;
	for(i=1;i<=N;i++) {
		cin>>A[i];
		FORR(d,D[A[i]]) {
			x=FD[d];
			y=d;
			while(y>1) {
				nex[pos[y].back()].push_back({y,i});
				pre[i].push_back({y,pos[y].back()});
				pos[y].push_back(i);
				y/=x;
			}
		}
	}
	FOR(i,B) if(pos[i].back()!=0) nex[pos[i].back()].push_back({N+1,i});
	
	FOR(x,B/DI) {
		ll ret=1;
		for(y=x*DI;y<B-DI*2;y++) {
			if(y%DI==0) dp[x][y/DI]=ret;
			FORR2(a,b,pre[y]) if(b<x*DI) ret=ret*FD[a]%mo;
		}
	}
	for(i=1;i<=N;i++) {
		sort(ALL(pre[i]));
		preS[i].push_back({0,1});
		FORR2(p,v,pre[i]) preS[i].push_back({p+1,preS[i].back().second*FD[v]%mo});
		sort(ALL(nex[i]));
		reverse(ALL(nex[i]));
		nexS[i].push_back({N+1,1});
		FORR2(p,v,nex[i]) nexS[i].push_back({p,nexS[i].back().second*FD[v]%mo});
		reverse(ALL(pos[i]));
		/*
		cout<<"#"<<i<<endl;
		FORR2(p,v,nex[i]) cout<<p<<" "<<v<<endl;
		cout<<"---"<<endl;
		FORR2(p,v,nexS[i]) cout<<p<<" "<<v<<endl;
		cout<<"---"<<endl;
		*/
	}
	
	cin>>Q;
	ll ret=1;
	while(Q--) {
		ll qa,qb;
		cin>>qa>>qb;
		x=(qa*ret%mo)%N+1;
		y=(qb*ret%mo)%N+1;
		if(x>y) swap(x,y);
		y++;
		ret=1;
		if(y-x<=2*DI) {
			ret=A[x];
			for(i=x+1;i<y;i++) {
				FORR2(a,b,pre[i]) if(b<x) {
					ret=ret*FD[a]%mo;
				}
			}
		}
		else {
			int L=(x+DI-1)/DI*DI;
			int R=y/DI*DI;
			ret=dp[L/DI][R/DI];
			while(x<L) {
				L--;
				auto it=lower_bound(ALL(nexS[L]),make_pair(R,0LL));
				ret=ret*it->second%mo;
			}
			while(R<y) {
				auto it=lower_bound(ALL(preS
				[L]),make_pair(x,0LL));
				it--;
				ret=ret*it->second%mo;
				R++;
			}
		}
		cout<<ret<<endl;
		
		
	}
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0