QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#838141 | #9886. Long Sequence Inversion 2 | Prosperity | WA | 22ms | 14800kb | C++23 | 1.4kb | 2024-12-30 21:41:11 | 2024-12-30 21:41:12 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
inline ll read(){
ll s=0,k=1;
char c=getchar();
while(c>'9'||c<'0'){
if(c=='-') k=-1;
c=getchar();
}
while(c>='0'&&c<='9'){
s=(s<<3)+(s<<1)+(c^48);
c=getchar();
}
return s*k;
}
const int mod=998244353;
vector<ll>c,p;
vector<vector<ll> >v;
ll n;
void Add(ll &x,ll y){
x+=y;
if(x>=mod) x-=mod;
}
void add(ll x,ll v){
x++;
while(x<=n){
c[x]+=v;
x+=x&-x;
}
}
ll query(ll x){
ll res=0;
x++;
while(x>0){
res+=c[x];
x-=x&-x;
}
return res;
}
ll ksm(ll a,ll b){
ll t=1;
for(;b;b>>=1,a=a*a%mod)
if(b&1) t=t*a%mod;
return t;
}
int main(){
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
ll L=read(),B=read();
n=max(L,B);
p.resize(L);
for(int i=0;i<L;i++) p[i]=read();
ll ans=ksm(B,L);
ans=ans*(ans-1)%mod*((mod+1)/2)%mod;
vector<ll>tmp(B,0);
for(int i=0;i<L;i++){
v.push_back(tmp);
for(int j=0;j<B;j++) v[i][j]=read();
}
c.resize(n+3);
vector<ll>X(L);
for(int i=0;i<L;i++){
X[i]=query(p[i]-1);
add(p[i],1);
}
for(int i=0;i<=n;i++) c[i]=0;
for(int i=0;i<L;i++){
for(int i=0;i<=B;i++) c[i]=0;
ll res=0;
for(int j=B-1;j>=0;j--){
res+=query(v[i][j]-1);
add(v[i][j],1);
}
Add(res,res);
Add(res,mod-B*(B-1)%mod*((mod+1)/2)%mod);
(res*=ksm(B,L-1+X[i]))%=mod;
Add(ans,res);
}
(ans*=mod+1>>1)%=mod;
printf("%lld",ans);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3800kb
input:
3 2 2 0 1 1 0 1 0 0 1
output:
14
result:
ok "14"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3800kb
input:
2 4 1 0 2 0 3 1 1 2 3 0
output:
60
result:
ok "60"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3728kb
input:
9 10 2 5 7 3 8 1 4 6 0 9 2 4 0 1 6 7 3 5 8 4 1 6 7 8 0 5 9 2 3 1 9 2 4 6 8 5 7 0 3 9 0 8 2 5 1 6 7 3 4 1 6 0 7 3 9 2 4 5 8 4 5 2 9 1 6 7 3 0 8 7 0 5 6 1 9 2 4 3 8 3 2 1 6 7 0 8 9 4 5 9 2 4 3 5 8 0 6 7 1
output:
138876070
result:
ok "138876070"
Test #4:
score: 0
Accepted
time: 22ms
memory: 14800kb
input:
1 499999 0 29619 375702 37496 460566 304389 460489 39603 7903 258016 288263 472075 22596 331493 275661 56064 364938 166384 286514 449089 71295 83634 202532 408346 34349 425929 67826 14897 21894 481996 394928 368071 394991 213881 134433 345718 371785 68019 323247 290861 175555 464454 99312 318279 474...
output:
633597495
result:
ok "633597495"
Test #5:
score: -100
Wrong Answer
time: 22ms
memory: 11028kb
input:
2 249999 0 1 58555 86505 217289 160736 134400 101021 40586 62145 139626 85795 167411 201337 98 206983 47713 102694 69929 120989 89299 38007 101502 27064 176770 192694 169507 5163 4199 146210 77723 135393 61474 73326 132827 234968 141265 84204 225082 101831 136349 51115 81706 174808 187315 54745 2076...
output:
-31667573
result:
wrong answer 1st words differ - expected: '434358382', found: '-31667573'