QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#69661#4411. Equipment Upgradeq234rtyAC ✓1732ms15192kbC++143.2kb2022-12-30 00:20:322022-12-30 00:20:34

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-12-30 00:20:34]
  • 评测
  • 测评结果:AC
  • 用时:1732ms
  • 内存:15192kb
  • [2022-12-30 00:20:32]
  • 提交

answer

#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;
inline ll getint(){
    int val;
    cin >> val;
    return val;
}
const int maxn=(1<<19)+2;
const int mod=998244353;
const int g=3;
ll power(ll x,ll y){
    ll res=1;
    while(y){
        if (y&1)
            res=res*x%mod;
        x=x*x%mod;
        y>>=1;
    }
    return res;
}
struct fft{
    int n,k;
    int polish(int n){
        int qwq=1;
        while(qwq<=n)
            qwq<<=1;
        return qwq;
    }
    ll omega[maxn];
    int bitrev[maxn];
    void init(int n){
        this->n=n=polish(n);
        k=__builtin_ctz(n);
        ll wn=power(g,(mod-1)/n);
        for(int i=0;i<n;i++){
            omega[i]=i?omega[i-1]*wn%mod:1;
            bitrev[i]=(bitrev[i>>1]>>1)|((i&1)<<(k-1));
        }
    }
    void trans(ll* a,bool inv){
        for(int i=0;i<n;i++)
            if (bitrev[i]<i)
                swap(a[i],a[bitrev[i]]);
        for(int i=1,qwq=1<<(k-1);i<n;i<<=1,qwq>>=1)
            for(int j=0;j<n;j+=i<<1){
                for(int k=j,now=0;k<j+i;k++,now+=qwq){
                    ll t=omega[now]*a[k+i]%mod;
                    a[k+i]=(a[k]-t)%mod;
                    a[k]=(a[k]+t)%mod;
                }
            }
        if (inv){
            ll qwq=power(n,mod-2);
            for(int i=0;i<n;i++)
                a[i]=a[i]*qwq%mod;
            reverse(a+1,a+n);
        }
    }
}t;
ll p[maxn],c[maxn],w[maxn],pre[maxn],invpre[maxn],f[maxn],h[maxn];
ll ans[maxn];
void solve(int l,int r){
    if (l==r){
        ans[l]=((ans[l]+1)*power(p[l],mod-2))%mod;
        return;
    }
    int mid=(l+r)/2;
    solve(mid+1,r);
    ll tot=0;
    t.init((r-l+1)*2);
    for(int i=0;i<t.n;i++)
        f[i]=h[i]=0;
    for(int i=0;i<=r-l-1;i++)
        h[i]=pre[r-l-1-i];
    for(int i=mid+1;i<=r;i++){
        ll tmp=(ans[i]*(1-p[i]))%mod;
        tot=(tot+tmp)%mod;
        f[i-mid-1]=(tmp*invpre[i])%mod;
    }
    t.trans(f, 0);
    t.trans(h, 0);
    for(int i=0;i<t.n;i++)
        f[i]=(f[i]*h[i])%mod;
    t.trans(f, 1);
    for(int i=l;i<=mid;i++){
        // if (i==1)
            // printf("i=1 %lld %lld %lld\n",ans[i],f[r-l-1+i-mid],tot);
        ans[i]=(ans[i]-f[r-l-1+i-mid]+tot)%mod;
    }
    solve(l,mid);
}
int main(){
    #ifdef LOCAL
        freopen("a.txt","r",stdin);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int T=getint();
    ll inv100=power(100,mod-2);
    while(T--){
        int n=getint();
        for(int i=0;i<=n;i++)
            ans[i]=0;
        for(int i=1;i<=n;i++){
            p[i-1]=((ll)getint()*inv100)%mod;
            c[i-1]=getint();
        }
        p[n]=c[n]=0;
        for(int i=1;i<n;i++){
            w[i]=getint();
            pre[i]=(pre[i-1]+w[i])%mod;
        }
        for(int i=1;i<n;i++)
            invpre[i]=power(pre[i],mod-2);
        pre[n]=invpre[n]=0;
        solve(0,n);
        ll sum=0;
        for(int i=0;i<n;i++){
            // printf("%lld\n",(ans[i]+mod)%mod);
            sum=(sum+c[i]*ans[i])%mod;
        }
        cout << (sum%mod+mod)%mod << '\n';
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1732ms
memory: 15192kb

input:

208
2
100 41
28 64
28
3
100 48
91 13
73 3
78 92
4
100 22
15 85
26 50
41 15
90 85 77
5
100 39
51 97
83 41
4 86
36 70
49 24 17 33
6
100 53
53 45
92 2
36 40
61 61
76 52
18 37 75 49 96
7
100 5
21 47
39 58
78 1
82 93
59 82
56 90
1 41 76 64 84 27
8
100 14
38 77
66 20
1 63
47 47
3 12
87 16
99 62
14 81 75 2...

output:

375
243619761
141260443
516768753
850749960
897481401
602765935
510391586
689398435
784190268
697129546
505176530
687991734
16121189
684750916
616413796
324645467
60836964
997265902
829124402
135215114
115586183
566051860
45973142
577302112
438599189
808712026
903587073
180745041
931933480
429669755...

result:

ok 208 lines