結果

問題 No.2250 Split Permutation
ユーザー SSRSSSRS
提出日時 2023-03-17 21:45:32
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 114 ms / 3,000 ms
コード長 1,428 bytes
コンパイル時間 4,457 ms
コンパイル使用メモリ 176,468 KB
実行使用メモリ 8,088 KB
最終ジャッジ日時 2023-10-18 14:17:35
合計ジャッジ時間 4,448 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 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 1 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 114 ms
8,088 KB
testcase_19 AC 106 ms
7,560 KB
testcase_20 AC 90 ms
7,032 KB
testcase_21 AC 54 ms
5,712 KB
testcase_22 AC 85 ms
6,768 KB
testcase_23 AC 17 ms
4,348 KB
testcase_24 AC 85 ms
6,768 KB
testcase_25 AC 114 ms
8,088 KB
testcase_26 AC 41 ms
5,184 KB
testcase_27 AC 11 ms
4,348 KB
testcase_28 AC 21 ms
4,348 KB
testcase_29 AC 114 ms
8,088 KB
testcase_30 AC 22 ms
4,392 KB
testcase_31 AC 6 ms
4,348 KB
testcase_32 AC 27 ms
4,656 KB
testcase_33 AC 63 ms
5,976 KB
testcase_34 AC 17 ms
4,348 KB
testcase_35 AC 44 ms
5,184 KB
testcase_36 AC 27 ms
4,656 KB
testcase_37 AC 114 ms
8,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
template <typename T>
struct invertible_binary_indexed_tree{
  int N;
  vector<T> BIT;
  function<T(T, T)> f;
  function<T(T)> inv;
  T E;
  invertible_binary_indexed_tree(int N, function<T(T, T)> f, function<T(T)> inv, T E): N(N), BIT(N + 1, E), f(f), inv(inv), E(E){
  }
  void add(int i, T x){
    i++;
    while (i <= N){
      BIT[i] = f(BIT[i], x);
      i += i & -i;
    }
  }
  T sum(int i){
    T ans = E;
    while (i > 0){
      ans = f(ans, BIT[i]);
      i -= i & -i;
    }
    return ans;
  }
  T sum(int l, int r){
    return f(sum(r), inv(sum(l)));
  }
};
int main(){
  int N;
  cin >> N;
  vector<int> P(N);
  for (int i = 0; i < N; i++){
    cin >> P[i];
    P[i]--;
  }
  vector<long long> POW(N);
  POW[0] = 1;
  for (int i = 0; i < N - 1; i++){
    POW[i + 1] = POW[i] * 2 % MOD;
  }
  invertible_binary_indexed_tree<int> BIT1(N, plus<int>(), negate<int>(), 0);
  auto sum = [](long long x, long long y){
    return (x + y) % MOD;
  };
  auto inv = [](long long x){
    return (MOD - x) % MOD;
  };
  invertible_binary_indexed_tree<long long> BIT2(N, sum, inv, 0);
  long long ans = 0;
  for (int i = 0; i < N; i++){
    ans += BIT1.sum(P[i] + 1, N) * POW[N - 1] % MOD;
    ans += MOD - BIT2.sum(P[i] + 1, N) * POW[N - 1 - i] % MOD;
    ans %= MOD;
    BIT1.add(P[i], 1);
    BIT2.add(P[i], POW[i]);
  }
  cout << ans << endl;
}
0