QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#258365#5547. Short Functionhank55663#WA 1ms4172kbC++143.5kb2023-11-19 17:31:512023-11-19 17:31:52

Judging History

你现在查看的是最新测评结果

  • [2023-11-19 17:31:52]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4172kb
  • [2023-11-19 17:31:51]
  • 提交

answer

#include<bits/stdc++.h>
#define pb push_back
#define x first
#define y second
#define pdd pair<double,double>
#define pii pair<int,int>
#define pll pair<LL,LL>
#define mp make_pair
#define LL long long
#define ULL unsigned long long
#define sqr(x) ((x)*(x))
#define pi acos(-1)
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
using namespace std;
const int mod=998244353;
LL f_pow(LL a,LL b,LL mod){
    LL res=1,temp=a;
    while(b){
        if(b&1)res=res*temp%mod;
        temp=temp*temp%mod;
        b>>=1;
    }
    return res;
}
LL pre[100005];
int root=3;
pll mgcd(int a, int b){
    if(b == 0) return mp(1, 0);
    else{
        LL p = a / b;
        pll q = mgcd(b, a % b);
        return make_pair(q.y, q.x - q.y * p);
    }
}

void solve(int T){
    int n,k;
    scanf("%d %d",&n,&k);
    int a[100005];
    pre[0]=1;
    for(int i = 1;i<=n;i++){
        scanf("%d",&a[i]);
        pre[i]=pre[i-1]*a[i]%mod;
    }
    if(k<30){
        LL tot=1ll<<k;
        LL x=tot/n,y=tot%n;
        for(int i=1;i<=n;i++){
            int l=i,r=i+y-1;
            if(l>r){
                printf("%lld ",f_pow(pre[n],x,mod));
            }
            else{
                LL a=f_pow(pre[n],x,mod);
                if(r<=n)a=a*pre[r]%mod*f_pow(pre[l-1],mod-2,mod)%mod;
                else {
                    r-=n;
                    a=a*pre[n]%mod*f_pow(pre[l-1],mod-2,mod)%mod*pre[r]%mod;
                }
                printf("%lld ",a);
            }
        }
        printf("\n");
    }
    else{
        LL y=f_pow(2,k,n);
        LL x=(f_pow(2,k,mod-1)-y+(mod-1))%(mod-1);
        LL tot;//=f_pow(pre[n],x,mod);
        {
            /*map<int,int> m;
            LL tmp=1;
            for(int i = 0;i<100000;i++){
                m[tmp]=i;
                tmp=tmp*root%mod;
            }
            LL aa=f_pow(f_pow(root,10000,mod),mod-2,mod);
            LL res=tot;
            LL ans=-1;
            for(int i = 0;i<100000;i++){
                if(m.find(tot)!=m.end()){
                    ans=i*10000+m[tot];
                    break;
                }
                tot=tot*aa%mod;
            }
            assert(ans!=-1);*/
          //  printf("%lld %lld\n",x,y);
            LL a=x,b=n;
          //  assert(f_pow(3,a,mod)==tot);
            LL gcd=__gcd(a,b);
            a/=gcd;
            b/=gcd;
          //  printf("%lld %lld\n",a,b);
            assert(__gcd(b,mod-1ll)==1);
            pll p=mgcd(b,mod-1);
            LL qans=(p.x%(mod-1)+mod-1)%(mod-1)*a%(mod-1);
          //  printf("%lld\n",qans);
            tot=f_pow(pre[n],qans,mod);
           // printf("%lld %lld\n",a,qans);
            //tot=f_pow(root,a*qans%(mod-1),mod);
           // printf("%lld\n",f_pow(2,99,mod-1));
        }
        for(int i=1;i<=n;i++){
            int l=i,r=i+y-1;
            if(l>r){
                printf("%lld ",tot);
            }
            else{
                LL a=tot;
                if(r<=n)a=a*pre[r]%mod*f_pow(pre[l-1],mod-2,mod)%mod;
                else {
                    r-=n;
                    a=a*pre[n]%mod*f_pow(pre[l-1],mod-2,mod)%mod*pre[r]%mod;
                }
                printf("%lld ",a);
            }
        }
        printf("\n");
    }
} 

int main(){
    int t=1;
     //scanf("%d",&t);
    for(int i = 1;i<=t;i++){
     //   cerr<<i<<endl;
        solve(i);
    }
}
/*
1227076727
1919786269
1261786217
1924134973
1051246577

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 4172kb

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: 3984kb

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: 4004kb

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: 3960kb

input:

2 100
1 2

output:

917380677 917380677 

result:

ok 2 number(s): "917380677 917380677"

Test #5:

score: 0
Accepted
time: 0ms
memory: 3948kb

input:

1 1
1

output:

1 

result:

ok 1 number(s): "1"

Test #6:

score: -100
Wrong Answer
time: 1ms
memory: 3952kb

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:

130496279 280371344 132400003 788072831 872387552 719639833 295240273 569464122 70826108 839714790 947283502 703124649 302625431 556946726 162513360 324275316 122844792 141477341 515299430 657102991 738180667 360981250 712794858 402871122 807437663 739759377 936030844 741034588 98032031 783979993 17...

result:

wrong answer 1st numbers differ - expected: '375116230', found: '130496279'