QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#306907 | #5547. Short Function | NYCU_CartesianTree | WA | 1ms | 5892kb | C++20 | 3.7kb | 2024-01-17 15:47:00 | 2024-01-17 15:47:00 |
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];
if(!vis[t]){
ans*=ff(preans[n-1],lap);ans%=mol;
dg(ans,t);
return;
}
int o1=ff1(2,cnt);
vector<int>b={o1,0};
ori.pb(b);
b={lap,1};
ori.pb(b);
mat=ori;
// b={lap,1};
// mat.pb(b);mat.p b(b);
// k+=dis[t];
// k-=dis[t],k+=cnt;
k+=cnt;
int total=k/(cnt);// 總週期
total--;
// cout<<k<<" "<<cnt<<" "<<lap<<" "<<ans<<"\n";
int le=k%cnt;
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){
go(ii);
}
int laap=(mat[0][0]*lap%(mol-1)+mat[1][0])%(mol-1);// 總圈數
if(total==0) laap=lap;
// cout<<ans<<" "<<laap<<" "<<preans[n-1]<<" "<<total<<"\n";
ans*=ff(preans[n-1],laap);ans%=mol;
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: 3668kb
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: 3808kb
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: 3856kb
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: 5892kb
input:
2 100 1 2
output:
917380677 917380677
result:
ok 2 number(s): "917380677 917380677"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3836kb
input:
1 1 1
output:
1
result:
ok 1 number(s): "1"
Test #6:
score: -100
Wrong Answer
time: 1ms
memory: 3720kb
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:
59287259 319931781 989169783 52954807 665453541 70771977 83478284 582508752 194835980 188001245 148668220 410208433 761230919 622088301 994159788 374170728 405930981 851207095 42985194 860360209 513074859 975154835 872094039 44494344 975112068 29513021 283647483 225909327 667697675 218358080 3835684...
result:
wrong answer 1st numbers differ - expected: '375116230', found: '59287259'