結果

問題 No.2250 Split Permutation
ユーザー Nzt3Nzt3
提出日時 2023-03-31 17:08:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 76 ms / 3,000 ms
コード長 1,028 bytes
コンパイル時間 2,527 ms
コンパイル使用メモリ 205,928 KB
実行使用メモリ 10,336 KB
最終ジャッジ日時 2023-10-24 04:03:05
合計ジャッジ時間 5,679 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 75 ms
10,336 KB
testcase_19 AC 69 ms
9,544 KB
testcase_20 AC 59 ms
8,752 KB
testcase_21 AC 35 ms
6,904 KB
testcase_22 AC 54 ms
8,224 KB
testcase_23 AC 11 ms
4,348 KB
testcase_24 AC 55 ms
8,224 KB
testcase_25 AC 76 ms
10,336 KB
testcase_26 AC 27 ms
5,848 KB
testcase_27 AC 7 ms
4,348 KB
testcase_28 AC 13 ms
4,528 KB
testcase_29 AC 72 ms
10,336 KB
testcase_30 AC 14 ms
4,792 KB
testcase_31 AC 5 ms
4,348 KB
testcase_32 AC 16 ms
5,056 KB
testcase_33 AC 41 ms
7,168 KB
testcase_34 AC 10 ms
4,348 KB
testcase_35 AC 28 ms
6,112 KB
testcase_36 AC 17 ms
5,056 KB
testcase_37 AC 73 ms
10,336 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
const int mod=998244353;

long long modpow(int a,int n){
  long long ret=1,t=a;
  for(int i=0;i<30;i++){
    if(n>>i&1)ret=ret*t%mod;
    t=t*t%mod;
  }
  return ret;
}
void add(int p,int v,vector<long long>& BIT){
  for(;p<BIT.size();p+=p&-p){
    BIT[p]=(BIT[p]+v)%mod;
  }
}
long long getsum(int l,int r,vector<long long>& BIT){
  long long ret=0;
  for(--l;l>0;l-=l&-l)ret=(ret-BIT[l])%mod;
  for(;r>0;r-=r&-r)ret=(ret+BIT[r])%mod;
  return ret;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin>>N;
  vector<int>P(N);
  for(int &i:P)cin>>i;
  long long ans=0;
  const long long inv2=modpow(2,mod-2);
  vector<long long>v2(N),rv2(N),cnt(N+1),mi(N+1);
  v2[0]=rv2[0]=1;
  for(int i=1;i<N;i++){
    v2[i]=v2[i-1]*2%mod;
    rv2[i]=rv2[i-1]*inv2%mod;
  }
  for(int i=0;i<N;i++){
    ans=(ans+(getsum(P[i],N,cnt)*v2[i]%mod-getsum(P[i],N,mi))%mod*v2[N-1-i])%mod;
    add(P[i],1,cnt);
    add(P[i],v2[i],mi);
  }
  if(ans<0)ans+=mod;
  cout<<ans<<'\n';
}
0