QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#24569 | #1831. Bruteforce | weibooo | WA | 28ms | 147456kb | C++20 | 3.6kb | 2022-03-31 19:18:44 | 2022-04-30 06:12:30 |
Judging History
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)*mul[a.len][t-x])%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=8;
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;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 28ms
memory: 147456kb
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: 147368kb
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: -100
Wrong Answer
time: 20ms
memory: 147316kb
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:
0 0 0 0 0 0 0 0 0 0
result:
wrong answer 1st numbers differ - expected: '3511390', found: '0'