QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#24571#1831. BruteforceweiboooWA 46ms147484kbC++203.6kb2022-03-31 19:21:072022-04-30 06:12:39

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-04-30 06:12:39]
  • 评测
  • 测评结果:WA
  • 用时:46ms
  • 内存:147484kb
  • [2022-03-31 19:21:07]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

#define ll  long long
#define pll pair<ll,ll>
#define ff first
#define ss second
#define endl "\n"
#define pb push_back
#define F(i,a,b) for(ll i=a;i<=b;i++)

const ll maxn=1e5+10;
const ll base=3e18;
const ll mod= 998244353  ;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

/// have medal in APIO
/// goal 2/8

ll a[maxn];
struct tk
{
    ll a[6][6];
    ll f[6];
    ll len;
    tk()
    {
        memset(a,0,sizeof(a));
        len=0;
        memset(f,0,sizeof(f));
    }
};
ll w, k;
ll mul[maxn][10];
ll gt[maxn];
ll gtv[maxn];
ll mu(ll a,ll n)
{
    if (n==0)
        return 1;
    if (n==1)
        return a;
    ll t=mu(a,n/2);
    if (n%2==0)
        return (t*t)%mod;
    return ((t*t)%mod*a)%mod;
}
void setup()
{
    gt[0]=1;
    for (int i=1; i<maxn; i++)
    {
        gt[i]=(gt[i-1]*i)%mod;
    }
    gtv[maxn-1]=mu(gt[maxn-1],mod-2);
    for (int i=maxn-2; i>=0; i--)
    {
        gtv[i]=(gtv[i+1]*(i+1))%mod;
    }
}
ll nck(ll n,ll k)
{
    if (n<k)
        return 0;
    return ((gt[n]*gtv[k])%mod*gtv[n-k])%mod;
}

tk st[4*maxn];
tk mer(tk a,tk b)
{
    tk c;
    c.len=a.len+b.len;
    for (int t=0; t<w; t++)
    {
        for (int h=0; h<w; h++)
        {
            c.a[t][h]=a.a[t][h];
        }
    }
    for (int t=0; t<=k; t++)
        c.f[t]=a.f[t];
    for (int t=0; t<w; t++)
    {
        for (int h=0; h<w; h++)
        {
            ll k=(h+a.len)%w;
            c.a[t][k]=(c.a[t][k]+b.a[t][h]);
        }
    }
    for (int t=0; t<=k; t++)
    {
        for (int x=0; x<=t; x++)
        {
            c.f[t]=(c.f[t]+((b.f[x]*nck(t,x))%mod*mul[a.len][t-x])%mod)%mod;
        }
    }
    return c;
}
void update(ll id,ll left,ll right,ll x,ll diff)
{
    if (x>right||x<left)
        return ;
    if (left==right)
    {
        if (diff==-1)
        {
            st[id].a[x%w][st[id].len%w]--;
            for (int t=0; t<=k; t++)
            {
                st[id].f[t]=((st[id].f[t]-x*mul[st[id].len][t])%mod+mod)%mod;
            }
             st[id].len--;
        }
        else
        {
            st[id].len++;
            st[id].a[x%w][st[id].len%w]++;
            for (int t=0; t<=k; t++)
            {
                st[id].f[t]=((st[id].f[t]+x*mul[st[id].len][t])%mod+mod)%mod;
            }
        }
        return ;
    }
    ll mid=(left+right)/2;
    update(id*2,left,mid,x,diff);
    update(id*2+1,mid+1,right,x,diff);
    st[id]=mer(st[id*2],st[id*2+1]);
}
ll val;
ll get()
{
    ll ans=st[1].f[k];
    for (int t=0; t<w; t++)
    {
        for (int x=0; x<w; x++)
        {
            ll nw=t;
            for (int h=1; h<=k; h++)
                nw=(nw*x)%w;
            ans=((ans-st[1].a[t][x]*nw)%mod+mod)%mod;
        }
    }
    ans=(ans*val)%mod;
    return ans;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if (fopen("t.inp","r"))
    {
        freopen("test.inp","r",stdin);
        freopen("test.out","w",stdout);
    }
    setup();
    for (int t=0; t<maxn; t++)
    {
        for (int h=0; h<10; h++)
            mul[t][h]=mu(t,h);
    }
    ll len=1e5;
    ll n;
    cin>> n>> k>> w;
    for (int i=1; i<=n; i++)
    {
        cin>> a[i];
        update(1,1,len,a[i],1);
    }
    val=mu(w,mod-2);
   // cout <<get()<<endl;
  //  return 0 ;
    ll q;
    cin>> q;
    while (q--)
    {
        ll pos, x;
        cin>> pos>> x;
        update(1,1,len,a[pos],-1);
        a[pos]=x;
        update(1,1,len,a[pos],1);
        cout <<get()<<endl;
    }

}

详细

Test #1:

score: 100
Accepted
time: 24ms
memory: 147484kb

input:

3 1 1
2 2 8
2
2 5
3 6

output:

36
30

result:

ok 2 number(s): "36 30"

Test #2:

score: 0
Accepted
time: 24ms
memory: 147388kb

input:

4 2 2
1 3 3 7
4
1 1
2 4
3 8
4 8

output:

75
80
103
108

result:

ok 4 number(s): "75 80 103 108"

Test #3:

score: 0
Accepted
time: 16ms
memory: 147468kb

input:

10 1 1
16251 28898 58179 69362 48663 81443 34949 87167 16552 58931
10
6 89124
8 27159
4 7332
1 15852
9 67405
7 19413
10 97472
7 31114
6 31847
5 43794

output:

3511390
3107346
2780002
2779204
3079414
3018965
3365708
3406982
2970195
2936112

result:

ok 10 numbers

Test #4:

score: 0
Accepted
time: 11ms
memory: 147404kb

input:

100 2 2
44625 87890 57662 73552 89172 64466 22834 24089 60132 5187 88984 19022 67559 53954 42114 19018 80035 3367 50518 15479 72359 15452 38886 5945 34974 86214 16805 71388 48981 45377 34170 61384 88881 29453 94738 94669 56746 80508 79155 94505 82745 38134 41769 2032 23186 5636 39727 54400 86133 497...

output:

81216962
152846115
156547587
163221145
293598979
178882623
92185541
202208317
181562234
200670345
213033267
262881364
247600647
301317991
271334928
261885869
261690216
247578015
236998290
291971331
293746018
424418987
402413699
300515771
300819876
344295103
391424353
392633865
361623113
355154190
47...

result:

ok 100 numbers

Test #5:

score: 0
Accepted
time: 44ms
memory: 147380kb

input:

1000 5 5
67444 21858 17070 50937 22108 62205 2999 96284 84111 16255 69173 11611 84406 28349 95817 86160 87289 19642 22706 44359 31899 36187 15946 86429 23120 65928 81187 32204 37790 18497 52182 23455 59579 78480 45277 57706 60123 99315 19014 72404 35420 14632 12210 38628 1729 18606 23941 96652 80784...

output:

448982964
318631979
90368327
811603500
536477662
692557229
62990700
201293231
656272078
39300199
904902483
682330227
415437174
172036954
307435785
263728224
240392540
817310695
279181829
609019128
744046644
313110033
146349180
684606480
105663106
927540631
395442598
940076193
928045549
210861570
871...

result:

ok 1000 numbers

Test #6:

score: 0
Accepted
time: 46ms
memory: 147392kb

input:

1000 4 5
72227 53523 60356 75354 48348 59071 85117 86260 35140 27149 26706 84967 71598 76061 81453 53989 15316 82420 50695 46478 47536 10211 47703 57753 52396 25234 7015 28545 88953 3038 68077 40104 83546 75660 4206 97850 46721 49986 69628 79532 47269 93027 73722 38823 81502 9110 29754 24 19161 1699...

output:

188781625
762228616
136821592
674574163
347192262
485485871
629723820
280908647
588412565
725358221
863705098
659938578
242816623
893332458
843594911
548347865
837091341
189528539
686788524
27959019
161387564
209458902
58082579
541157908
634716980
370997719
711719499
222851922
266533026
468008815
12...

result:

ok 1000 numbers

Test #7:

score: -100
Wrong Answer
time: 40ms
memory: 147416kb

input:

1000 5 5
934 216 913 239 824 359 107 658 672 201 259 787 699 375 495 399 957 273 386 716 148 563 663 746 673 466 938 833 871 307 932 330 175 572 438 641 106 574 148 265 235 48 284 823 142 616 664 401 301 156 36 155 455 46 314 386 80 918 9 283 960 228 576 322 866 871 642 571 93 364 384 343 780 740 29...

output:

863298675
561844282
707253518
131162317
733366001
240959848
491331485
945999426
884095393
601677031
988828395
989129097
271230712
188285368
526283575
610318634
640662356
513566498
530541446
619910493
101188507
650095342
264873841
559625254
219249144
536317513
208763693
184423450
658893967
602055766
...

result:

wrong answer 30th numbers differ - expected: '186389056', found: '602055766'