結果

問題 No.868 ハイパー部分和問題
コンテスト
ユーザー tiger2005
提出日時 2026-07-03 17:21:26
言語 C++23
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 5,319 ms / 7,000 ms
コード長 870 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,687 ms
コンパイル使用メモリ 330,552 KB
実行使用メモリ 6,528 KB
最終ジャッジ日時 2026-07-03 17:22:40
合計ジャッジ時間 70,918 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;

using i64 = long long;
const i64 mods[3] = {
   998244353,
  1000000007,
  1000000009,
};

i64 ways[3][15010];

int n, k, q;
int a[15010];

void add(int x) {
  if (x == 0)
    return;
  for (int c = 0; c < 3; c ++) {
    for (int j = k; j >= x; j --)
      (ways[c][j] += ways[c][j - x]) %= mods[c];
  }
}

void del(int x) {
  if (x == 0)
    return;
  for (int c = 0; c < 3; c ++) {
    for (int j = x; j <= k; j ++)
      (ways[c][j] += mods[c] - ways[c][j - x]) %= mods[c];
  }
}

int main() {
  ways[0][0] = ways[1][0] = ways[2][0] = 1;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i ++)
    scanf("%d", &a[i]), add(a[i]);
  scanf("%d", &q);

  while (q --) {
    int p, x;
    scanf("%d%d", &p, &x);
    del(a[p]);
    add(a[p] = x);
    printf("%d\n", ways[0][k] || ways[1][k] || ways[2][k]);
  }
  return 0;
}
0