結果
| 問題 |
No.3026 Range LCM (Online Version)
|
| コンテスト | |
| ユーザー |
kmjp
|
| 提出日時 | 2025-02-23 08:41:47 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 3,081 bytes |
| コンパイル時間 | 3,394 ms |
| コンパイル使用メモリ | 212,176 KB |
| 実行使用メモリ | 54,872 KB |
| 最終ジャッジ日時 | 2025-02-23 08:42:06 |
| 合計ジャッジ時間 | 16,115 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 10 TLE * 1 -- * 25 |
ソースコード
#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=150;
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({i,x});
pre[i].push_back({pos[y].back(),x});
pos[y].push_back(i);
y/=x;
}
}
}
FOR(i,B) if(pos[i].back()!=0) nex[pos[i].back()].push_back({N+1,FD[i]});
for(i=1;i<=N;i++) {
sort(ALL(pre[i]));
preS[i].push_back({0,1});
ll cur=1;
FORR2(p,v,pre[i]) {
if(preS[i].back().first==p+1) preS[i].pop_back();
cur=cur*v%mo;
preS[i].push_back({p+1,cur});
}
sort(ALL(nex[i]));
reverse(ALL(nex[i]));
nexS[i].push_back({N+2,1});
cur=1;
FORR2(p,v,nex[i]) {
if(nexS[i].back().first!=p+1) nexS[i].push_back({p+1,cur});
cur=cur*v%mo;
}
nexS[i].push_back({i,cur});
reverse(ALL(nexS[i]));
}
FOR(x,B/DI) {
ll ret=A[x*DI];
for(y=x*DI+1;y<=N;y++) {
if(y%DI==0) dp[x][y/DI]=ret;
int m=1;
auto it=lower_bound(ALL(preS[y]),make_pair(x*DI+1,0LL));
it--;
ret=ret*it->second%mo;
}
}
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<=3*DI) {
ret=A[x];
for(i=x+1;i<y;i++) {
FORR2(a,b,pre[i]) if(a<x) ret=ret*b%mo;
}
}
else {
int L=(x+DI-1)/DI*DI;
int R=y/DI*DI;
assert(L<=R);
ret=dp[L/DI][R/DI];
while(x<L) {
L--;
int m=1;
FORR2(a,b,nex[L]) if(a>=R) m*=b;
ret=ret*m%mo;
}
while(R<y) {
auto it=lower_bound(ALL(preS[R]),make_pair(x+1,0LL));
it--;
ret=ret*it->second%mo;
R++;
}
/*
while(x<L) {
L--;
auto it=lower_bound(ALL(nexS[L]),make_pair(R,0LL));
ret=ret*prev(it)->second%mo;
}
while(R<y) {
int m=1;
FORR2(a,b,pre[R]) if(a<x) m*=b;
ret=ret*m%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;
}
kmjp