QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#863594 | #9994. waht 先生的法阵 | YMH_fourteen | WA | 30ms | 32220kb | C++14 | 2.8kb | 2025-01-19 19:44:32 | 2025-01-19 19:44:33 |
Judging History
answer
// Author: YE Minghan
#include<bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include "templates/debug.h"
#else
#define dbg(...) (void)0
#define here (void)0
#endif
#define ll long long
#define endl '\n'
#define PB emplace_back
#define PPB pop_back
#define MP make_pair
#define ALL(Name) Name.begin(),Name.end()
#define PII pair<int,int>
#define VI vector<int>
#define GI greater<int>
#define fi first
#define se second
// O(nBlogn+qn/B)
// B=sqrt(n/logn)
// O(nsqrt(nlogn))
const int N=250005,B=100,C=N/B+2,S=N+B,P=32000,MOD=998244353;
int K(int x){return (x-1)/B;}
int A(int x,int y){return x+y-(x+y>=MOD?MOD:0);}
int n,q,rem[S];
bool isp[N];
VI pf[N];
set<int>mtp[N];
int a[S],nxt[S];
int nxk[S],nxv[S],mul[C];
int reb[C];
void bld(int x,int y)
{
int l=x*B+1,r=(x+1)*B;
for(int i=l;i<=r;i++)a[i]=1ll*a[i]*mul[x]%MOD;
for(int i=y;i>=l;i--)
{
if(nxt[i]<=r)nxk[i]=nxk[nxt[i]],nxv[i]=A(a[i],nxv[nxt[i]]);
else nxk[i]=nxt[i],nxv[i]=a[i];
}
mul[x]=1;
}
#define now chrono::high_resolution_clock::now()
#define clk(x,y) int(chrono::duration_cast<chrono::duration<double,ratio<1,10000000>>>(y-x).count()/10)
int main()
{
// auto st=now;
// freopen("1.in","r",stdin);
// freopen("1.out","w",stdout);
ios::sync_with_stdio(false),cin.tie(nullptr);
// int _;cin>>_;while(_--)
memset(isp,1,sizeof(isp));
for(int i=2;i<N;i++)
if(isp[i])
{
for(int j=i<<1;j<N;j+=i)isp[j]=0;
for(int j=i;j<N;j+=i)pf[j].PB(i);
}
cin>>n>>q;
for(int i=1;i<=n;i++)
{
cin>>a[i];
int g=__gcd(a[i],i);
nxt[i]=i+g;
rem[i]=i/g;
for(int j:pf[i/g])mtp[j].insert(i);
}
for(int i=n+1;i<=((n-1)/B+1)*B;i++)rem[i]=1,a[i]=0,nxt[i]=1e9;
n=((n-1)/B+1)*B;
for(int i=0;i<n/B;i++)mul[i]=1,bld(i,(i+1)*B);
while(q--)
{
int op;
cin>>op;
if(op==1)
{
int l,r,c;
cin>>l>>r>>c;
int kl=K(l),kr=K(r);
if(kl==kr)
{
for(int i=l;i<=r;i++)a[i]=1ll*a[i]*c%MOD;
reb[kl]=r;
}
else
{
reb[kl]=(kl+1)*B,reb[kr]=r;
for(int i=l;i<=(kl+1)*B;i++)a[i]=1ll*a[i]*c%MOD;
for(int i=kr*B+1;i<=r;i++)a[i]=1ll*a[i]*c%MOD;
for(int i=kl+1;i<kr;i++)mul[i]=1ll*mul[i]*c%MOD;
}
int cr=-1;
VI chg;
for(int i:pf[c])
for(auto it=mtp[i].lower_bound(l);it!=mtp[i].end()&&*it<=r;it++)chg.PB(*it);
for(int i:chg)
{
int g=__gcd(rem[i],c);
if(g==1)continue;
rem[i]/=g;
for(int j:pf[i])
if(rem[i]%j)mtp[j].erase(i);
nxt[i]+=(g-1)*(nxt[i]-i);
reb[K(i)]=max(reb[K(i)],i);
}
for(int i=kl;i<=kr;i++)
if(reb[i])bld(i,reb[i]),reb[i]=0;
}
else
{
int x;cin>>x;
int ans=0;
while(x<=n)ans=(ans+1ll*nxv[x]*mul[K(x)])%MOD,x=nxk[x];
cout<<ans<<endl;
}
}
// cerr<<"Time: "<<clk(st,now)<<" microseconds\n";
// cerr<<"Time1: "<<tot<<" microseconds\n";
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 30ms
memory: 32220kb
input:
998 4970 604930052 733121966 111477169 629331886 907145780 306419159 358274571 279467377 778652746 419669771 929596817 426691768 554317460 313052874 798647485 491363256 951783139 128560911 373258126 597578307 941513530 738365198 772320937 328050879 190312538 576900137 141991025 960913405 64864592 24...
output:
990686178 667194672 996502138 554093709 501808911 353261525 87917945 21605443 772819913 654270513 191228588 118675822 551855700 888843636 428221646 356503639 210170664 562480949 128892422 749784320 917176113 243605144 230050872 739793347 239859571 825062205 616538154 590198451 394395945 213384619 90...
result:
wrong answer 2nd lines differ - expected: '15417519', found: '667194672'