QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#306882 | #5547. Short Function | Aestivate | WA | 1ms | 5840kb | C++20 | 3.8kb | 2024-01-17 14:58:17 | 2024-01-17 14:58:17 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define F first
#define S second
#define pb push_back
const int mol=998244353;
bool vis[100005];
vector<vector<int>>mat,ori,tot;
void go(int id){
if(id==1) tot=ori;
else tot = mat;
vector<vector<int>>iu;
for(int i=0;i<2;i++){
vector<int>tt;
for(int j=0;j<2;j++){
int sum=0;
for(int k=0;k<2;k++){
sum+=mat[i][k]*tot[k][j]%(mol-1);
sum%=mol-1;
}
tt.pb(sum);
}
iu.pb(tt);
}
mat=iu;
}
int ff1(int g,int h){
if(h==0) return 1;
if(h==1) return g;
if(h%2) return g*ff1(g,h-1)%(mol-1);
else {
int t=ff1(g,h/2);
return t*t%(mol-1);
}
}
int ff(int g,int h){
if(h==0) return 1;
if(h==1) return g;
if(h%2) return g*ff(g,h-1)%mol;
else {
int t=ff(g,h/2);
return t*t%(mol);
}
}
vector<int>a(100005);
int n,k;
void dg(int ans,int t){
t++;
if(t==n+1) t=1;
for(int i=0;i<n;i++){
cout<<ans<<" ";
ans*=ff(a[i],mol-2);
ans%=mol;
ans*=a[t-1];
ans%=mol;
t++;
if(t==n+1) t=1;
}
}
int dis[100005];//走幾圈了
int preans[100005];
int haha[100005];// 走到目標之前走幾步
void solve(){
cin>>n>>k;
for(int i=0;i<n;i++) cin>>a[i];
for(int i=0;i<n;i++){
if(i==0) preans[i]=a[i];
else preans[i]=preans[i-1]*a[i]%mol;
}
int t=1;int lap=0;
int cnt=0;
while(vis[t]==0){
dis[t]=lap;
haha[t]=cnt;
vis[t]=1;
t+=t;lap+=lap;
lap%=(mol-1);
cnt++;
k--;
if(t>n) t-=n,lap++;
if(k==0) break;
}
lap%=(mol-1);
// cout<<cnt<<" "<<t<<" "<<lap<<" "<<k<<"\n";
cnt-=haha[t],lap-=dis[t];
if(lap<0) lap+=mol-1;
// cout<<cnt<<" "<<lap<<"\n";
// cout<<vis[t]<<"\n";
// cout<<t<<"t\n";
int ans=preans[t-1];
// cout<<vis[t]<<"tt\n";
if(!vis[t]){
ans*=ff(preans[n-1],lap);ans%=mol;
dg(ans,t);
return;
}
int o1=ff1(2,cnt);
// cerr<<o1<<"o1\n";
vector<int>b={o1,0};
ori.pb(b);
b={lap,1};
ori.pb(b);
mat=ori;
// b={lap,1};
// mat.pb(b);mat.pb(b);
k-=dis[t];k+=cnt;
int total=k/(cnt);// 總週期
total--;
int le=k%cnt;
// cout<<total<<"tt\n";
vector<int>qq;
while(total>1){
if(total%2==0) total>>=1,qq.pb(2);
else qq.pb(1),total--;
}
reverse(qq.begin(),qq.end());
for(int ii:qq){
// cerr<<mat[0][0]<<" "<<ii<<"\n";
go(ii);
// cerr<<mat[0][0]<<"mmmm\n";
}
preans[0]=1;
int laap=(mat[0][0]*lap+mat[1][0])%(mol-1);// 總圈數
if(total==0) laap=lap;
// cout<<ans<<" "<<laap<<" "<<preans[n-1]<<"\n";
ans*=ff(preans[n-1],laap);ans%=mol;
// cout<<ans<<" "<<le<<"\n";
// cerr<<le<<"lee\n";
lap=laap;
while(le){
le--,ans*=ff(preans[n-1],lap);ans%=mol;
lap+=lap;
lap%=mol-1;
int pp=t;
t+=t;
if(t>n) t-=n;
if(t<pp){
ans*=preans[t-1]*preans[n-1]%mol*ff(preans[pp-1],mol-2)%mol;
ans%=mol;
}
else{
ans*=preans[t-1]*ff(preans[pp-1],mol-2)%mol;
ans%=mol;
}
ans%=mol;
}
dg(ans,t);
return;
b=a;
for(int i=0;i<k;i++){
a=b;
for(int j=0;j<n;j++) b[j]=a[j]*a[(j+(1LL<<i))%n]%mol;
int sum=0;
for(int j=0;j<n;j++) cout<<b[j]<<" ",sum+=b[j];
cout<<"\n"<<sum<<"\n";
}
//100000
}
signed main(){
ios::sync_with_stdio(0);cin.tie(0);
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5700kb
input:
5 2 1 2 3 4 5
output:
24 120 60 40 30
result:
ok 5 number(s): "24 120 60 40 30"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3848kb
input:
8 3 12 5 16 14 10 6 9 2
output:
14515200 14515200 14515200 14515200 14515200 14515200 14515200 14515200
result:
ok 8 numbers
Test #3:
score: 0
Accepted
time: 1ms
memory: 5840kb
input:
6 10 3 7 8 2 9 5
output:
56347321 169041963 833775940 811788154 844769833 639990479
result:
ok 6 numbers
Test #4:
score: 0
Accepted
time: 1ms
memory: 3660kb
input:
2 100 1 2
output:
917380677 917380677
result:
ok 2 number(s): "917380677 917380677"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3788kb
input:
1 1 1
output:
1
result:
ok 1 number(s): "1"
Test #6:
score: -100
Wrong Answer
time: 1ms
memory: 3608kb
input:
119 1000000000 179906895 883175111 831258723 617910763 41850684 952649819 667608052 992898634 871657688 261948841 858714230 452797779 698675390 39373823 268148685 762575950 789163136 676908074 134428624 583625412 549545785 415007638 564283552 596519552 575204092 884934270 632550339 21505752 66058955...
output:
671385220 466317809 16709347 253411695 485352240 489455488 112969784 603278237 954994101 435645910 732891519 918074881 948469355 675056171 201975627 672771308 388993629 624248063 663193281 67638528 32808567 788381700 671908101 661676179 179431806 140700093 415591527 203523540 727907085 523061058 665...
result:
wrong answer 1st numbers differ - expected: '375116230', found: '671385220'