結果
| 問題 |
No.2898 Update Max
|
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2024-09-26 11:58:24 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 193 ms / 2,000 ms |
| コード長 | 1,171 bytes |
| コンパイル時間 | 1,765 ms |
| コンパイル使用メモリ | 176,636 KB |
| 実行使用メモリ | 18,768 KB |
| 最終ジャッジ日時 | 2024-09-26 11:58:32 |
| 合計ジャッジ時間 | 6,615 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 28 |
ソースコード
#include <algorithm>
#include<bits/stdc++.h>
using namespace std;
const int MAXN=2e5+100,mod=998244353;
int n;
int a[MAXN];
long long fac[MAXN],ans,inv[MAXN],facinv[MAXN];
map<int,int> mp;
long long A(int n, int m) {
if(n<m) {
return 0;
}
return fac[n]*facinv[n-m]%mod;
}
int main() {
cin >> n;
fac[0]=1,inv[1]=1,facinv[0]=1;
for (int i=1; i<=n; i++) {
fac[i]=fac[i-1]*i%mod;
if (i>1) inv[i]=inv[mod%i]*(mod-mod/i)%mod;
facinv[i]=facinv[i-1]*inv[i]%mod;
cin >> a[i];
mp[a[i]]++;
}
vector<int> s;
for (int i=1; i<=n; i++) {
if (!mp[i]) {
s.push_back(i);
}
}
int cnt=s.size(),max1=0,c=0;
for (int i=1; i<=n; i++) {
max1=max(max1,a[i]);
if (a[i]!=-1) {
if (a[i]==max1) {
int o=lower_bound(s.begin(),s.end(),a[i])-s.begin();
(ans+=A(o,c)*fac[cnt-c])%=mod;
}
} else {
int o=lower_bound(s.begin(),s.end(),max1)-s.begin();
c++;
(ans+=(A(cnt,c)-A(o,c)+mod)%mod*inv[c]%mod*fac[cnt-c])%=mod;
}
}
cout << ans;
return 0;
}
vjudge1