結果

問題 No.2250 Split Permutation
ユーザー 👑 chro_96chro_96
提出日時 2023-03-17 23:19:50
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 403 ms / 3,000 ms
コード長 1,559 bytes
コンパイル時間 923 ms
コンパイル使用メモリ 31,512 KB
実行使用メモリ 12,484 KB
最終ジャッジ日時 2023-10-18 16:23:29
合計ジャッジ時間 6,937 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
12,484 KB
testcase_01 AC 5 ms
12,484 KB
testcase_02 AC 4 ms
12,484 KB
testcase_03 AC 4 ms
12,484 KB
testcase_04 AC 5 ms
12,484 KB
testcase_05 AC 5 ms
12,484 KB
testcase_06 AC 4 ms
12,484 KB
testcase_07 AC 4 ms
12,484 KB
testcase_08 AC 4 ms
12,484 KB
testcase_09 AC 5 ms
12,484 KB
testcase_10 AC 4 ms
12,484 KB
testcase_11 AC 5 ms
12,484 KB
testcase_12 AC 4 ms
12,484 KB
testcase_13 AC 5 ms
12,484 KB
testcase_14 AC 4 ms
12,484 KB
testcase_15 AC 5 ms
12,484 KB
testcase_16 AC 4 ms
12,484 KB
testcase_17 AC 4 ms
12,484 KB
testcase_18 AC 396 ms
12,484 KB
testcase_19 AC 389 ms
12,484 KB
testcase_20 AC 340 ms
12,484 KB
testcase_21 AC 221 ms
12,484 KB
testcase_22 AC 326 ms
12,484 KB
testcase_23 AC 52 ms
12,484 KB
testcase_24 AC 318 ms
12,484 KB
testcase_25 AC 402 ms
12,484 KB
testcase_26 AC 148 ms
12,484 KB
testcase_27 AC 36 ms
12,484 KB
testcase_28 AC 73 ms
12,484 KB
testcase_29 AC 403 ms
12,484 KB
testcase_30 AC 79 ms
12,484 KB
testcase_31 AC 20 ms
12,484 KB
testcase_32 AC 82 ms
12,484 KB
testcase_33 AC 227 ms
12,484 KB
testcase_34 AC 51 ms
12,484 KB
testcase_35 AC 161 ms
12,484 KB
testcase_36 AC 93 ms
12,484 KB
testcase_37 AC 400 ms
12,484 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

void add_segt (long long *t, int idx, long long val, int size, long long mod_num) {
  idx = idx+size-1;
  t[idx] += val;
  t[idx] %= mod_num;
  
  while (idx > 0) {
    idx = (idx-1)/2;
    t[idx] += val;
    t[idx] %= mod_num;
  }
  
  return;
}

long long sum_segt_rec (long long *t, int a, int b, int k, int l, int r, long long mod_num) {
  long long ans = 0LL;
  
  if (r <= a || b <= l) {
    return 0LL;
  }
  
  if (a <= l && r <= b) {
    return t[k];
  }
  
  ans = sum_segt_rec(t, a, b, 2*k+1, l, (l+r)/2, mod_num);
  ans += sum_segt_rec(t, a, b, 2*k+2, (l+r)/2, r, mod_num);
  
  return ans%mod_num;
}

long long sum_segt (long long *t, int a, int b, int size, long long mod_num) {
  return sum_segt_rec(t, a, b, 0, 0, size, mod_num);
}

int main () {
  int n = 0;
  int p[200000] = {};
  
  int res = 0;
  
  long long ans = 0LL;
  long long mod_num = 998244353LL;
  
  long long pow2[200001] = {};
  
  long long t[2][524288] = {};
  int size = 1;
  
  res = scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    res = scanf("%d", p+i);
    p[i]--;
  }

  pow2[0] = 1LL;
  for (int i = 0; i < n; i++) {
    pow2[i+1] = (pow2[i]*2LL)%mod_num;
  }
  
  while (size <= n) {
    size *= 2;
  }
  
  for (int i = 0; i < n; i++) {
    ans += (sum_segt(t[0], p[i], n, size, mod_num)*pow2[n-1])%mod_num;
    ans += mod_num-(sum_segt(t[1], p[i], n, size, mod_num)*pow2[n-i-1])%mod_num;
    add_segt(t[0], p[i], 1LL, size, mod_num);
    add_segt(t[1], p[i], pow2[i], size, mod_num);
  }
  
  printf("%lld\n", ans%mod_num);
  return 0;
}
0