結果

問題 No.2197 Same Dish
ユーザー 👑 chro_96chro_96
提出日時 2023-01-20 22:21:16
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 77 ms / 2,000 ms
コード長 1,938 bytes
コンパイル時間 1,154 ms
コンパイル使用メモリ 30,328 KB
実行使用メモリ 5,152 KB
最終ジャッジ日時 2023-09-05 14:40:11
合計ジャッジ時間 2,888 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,624 KB
testcase_01 AC 2 ms
4,652 KB
testcase_02 AC 2 ms
4,732 KB
testcase_03 AC 2 ms
4,544 KB
testcase_04 AC 1 ms
4,596 KB
testcase_05 AC 2 ms
4,540 KB
testcase_06 AC 2 ms
4,640 KB
testcase_07 AC 2 ms
4,724 KB
testcase_08 AC 2 ms
4,620 KB
testcase_09 AC 3 ms
4,648 KB
testcase_10 AC 2 ms
4,732 KB
testcase_11 AC 2 ms
4,608 KB
testcase_12 AC 3 ms
4,656 KB
testcase_13 AC 14 ms
4,836 KB
testcase_14 AC 69 ms
4,940 KB
testcase_15 AC 75 ms
5,080 KB
testcase_16 AC 52 ms
4,840 KB
testcase_17 AC 45 ms
4,732 KB
testcase_18 AC 77 ms
5,080 KB
testcase_19 AC 77 ms
4,956 KB
testcase_20 AC 77 ms
5,080 KB
testcase_21 AC 74 ms
5,152 KB
testcase_22 AC 70 ms
5,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>

#define SEGT_SIZE 262144

int cmp_int (const void *ap, const void *bp) {
  int a = *(int *)ap;
  int b = *(int *)bp;
  
  if (a < b) {
    return -1;
  }
  
  if (a > b) {
    return 1;
  }
  
  return 0;
}

long long power_mod (long long a, long long b, long long mod_num) {
  long long ans = 1LL;
  
  if (b > 0LL) {
    ans = power_mod(a, b/2LL, mod_num);
    ans = (ans * ans) % mod_num;
    if (b%2LL == 1LL) {
      ans = (ans * (a % mod_num)) % mod_num;
    }
  }
  
  return ans;
}

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

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

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

int main () {
  int n = 0;
  long long k = 0LL;
  int lr[100000][2] = {};
  
  int res = 0;
  
  long long ans = 1LL;
  long long mod_num = 998244353LL;
  
  int t[2*SEGT_SIZE-1] = {};
  
  res = scanf("%d", &n);
  res = scanf("%lld", &k);
  for (int i = 0; i < n; i++) {
    res = scanf("%d", lr[i]);
    res = scanf("%d", lr[i]+1);
  }
  
  qsort(lr, n, sizeof(int)*2, cmp_int);
  
  for (int i = 0; i < n; i++) {
    int cnt = sum_segt(t, 0, lr[i][0], SEGT_SIZE);
    int num = sum_segt(t, lr[i][1]-1, lr[i][1], SEGT_SIZE);
    if (k >= ((long long)(i-cnt))) {
      ans *= k-((long long)(i-cnt));
      ans %= mod_num;
    } else {
      ans = 0LL;
    }
    set_segt(t, lr[i][1]-1, num+1, SEGT_SIZE);
  }
  
  ans = mod_num-ans;
  ans += power_mod(k, (long long)n, mod_num);
  printf("%lld\n", ans%mod_num);
  return 0;
}
0