結果

問題 No.2250 Split Permutation
ユーザー prism17prism17
提出日時 2023-03-29 18:44:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 159 ms / 3,000 ms
コード長 1,723 bytes
コンパイル時間 1,608 ms
コンパイル使用メモリ 171,596 KB
実行使用メモリ 6,376 KB
最終ジャッジ日時 2023-10-21 09:18:37
合計ジャッジ時間 5,426 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 3 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 3 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 153 ms
6,376 KB
testcase_19 AC 138 ms
6,112 KB
testcase_20 AC 117 ms
5,584 KB
testcase_21 AC 66 ms
4,792 KB
testcase_22 AC 104 ms
5,584 KB
testcase_23 AC 19 ms
4,348 KB
testcase_24 AC 108 ms
5,584 KB
testcase_25 AC 156 ms
6,376 KB
testcase_26 AC 46 ms
4,348 KB
testcase_27 AC 13 ms
4,348 KB
testcase_28 AC 23 ms
4,348 KB
testcase_29 AC 159 ms
6,376 KB
testcase_30 AC 25 ms
4,348 KB
testcase_31 AC 7 ms
4,348 KB
testcase_32 AC 31 ms
4,348 KB
testcase_33 AC 76 ms
5,056 KB
testcase_34 AC 18 ms
4,348 KB
testcase_35 AC 51 ms
4,528 KB
testcase_36 AC 29 ms
4,348 KB
testcase_37 AC 154 ms
6,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// Problem: No.2250 Split Permutation
// Contest: yukicoder
// URL: https://yukicoder.me/problems/no/2250
// Memory Limit: 512 MB
// Time Limit: 3000 ms

#include <bits/stdc++.h>

#define fastio ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define dbg(x) cout << #x << " = " << (x) << "\n";
#define popcount(x) __builtin_popcountll((x))
#define all(v) (v).begin(), (v).end()
#define pb emplace_back
#define x first
#define y second

using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

const int inf = 0x3f3f3f3f;
const int mod = 998244353;

int n;
struct BIT {
  int sz;
  vector<ll> bit;
  BIT(int _n) {
    sz = _n;
    bit = vector<ll>(sz + 1, 0);
  }
  int lowbit(int x) { return x & -x; }
  void add(int x, ll v) {
    for (int i = x; i <= sz; i += lowbit(i)) {
      bit[i] += v;
      bit[i] %= mod;
    }
  }
  ll ask(int x) {
    ll ret = 0;
    for (int i = x; i >= 1; i -= lowbit(i)) {
      ret = ret + bit[i];
      ret %= mod;
    }
    return ret;
  }
};
ll ksm(ll x, ll n) {
  if (n < 0) n += mod - 1;
  ll res = 1;
  while (n) {
    if (n & 1) res = (res * x) % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}
ll inv(ll x) { return ksm(x, mod - 2); }
void solve() {
  cin >> n;
  BIT bit1(n), bit2(n);
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    ans = ans + ksm(2, n - 1) * (bit1.ask(n) - bit1.ask(x)) % mod;
    ans %= mod;
    ans = ans - (bit2.ask(n) - bit2.ask(x)) * ksm(2, n - 1) % mod *
                    inv(ksm(2, i)) % mod;
    ans = (ans + mod) % mod;
    bit1.add(x, 1);
    bit2.add(x, ksm(2, i));
  }
  cout << ans << "\n";
}

int main() {
  fastio;
  int t = 1;
  // cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
0