結果

問題 No.868 ハイパー部分和問題
ユーザー pekempeypekempey
提出日時 2019-08-17 00:15:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 116 ms / 7,000 ms
コード長 1,061 bytes
コンパイル時間 1,629 ms
コンパイル使用メモリ 172,268 KB
実行使用メモリ 6,184 KB
最終ジャッジ日時 2023-10-24 16:14:33
合計ジャッジ時間 4,353 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,536 KB
testcase_01 AC 3 ms
4,536 KB
testcase_02 AC 3 ms
4,536 KB
testcase_03 AC 3 ms
4,532 KB
testcase_04 AC 3 ms
4,532 KB
testcase_05 AC 2 ms
4,532 KB
testcase_06 AC 3 ms
4,532 KB
testcase_07 AC 3 ms
4,532 KB
testcase_08 AC 3 ms
4,532 KB
testcase_09 AC 3 ms
4,532 KB
testcase_10 AC 3 ms
4,532 KB
testcase_11 AC 3 ms
4,532 KB
testcase_12 AC 3 ms
4,532 KB
testcase_13 AC 2 ms
4,532 KB
testcase_14 AC 110 ms
6,176 KB
testcase_15 AC 110 ms
6,180 KB
testcase_16 AC 109 ms
6,184 KB
testcase_17 AC 109 ms
6,184 KB
testcase_18 AC 109 ms
6,180 KB
testcase_19 AC 31 ms
5,444 KB
testcase_20 AC 31 ms
5,444 KB
testcase_21 AC 34 ms
5,472 KB
testcase_22 AC 34 ms
5,472 KB
testcase_23 AC 37 ms
5,492 KB
testcase_24 AC 37 ms
5,492 KB
testcase_25 AC 39 ms
5,512 KB
testcase_26 AC 39 ms
5,512 KB
testcase_27 AC 41 ms
5,528 KB
testcase_28 AC 41 ms
5,528 KB
testcase_29 AC 92 ms
6,176 KB
testcase_30 AC 91 ms
6,180 KB
testcase_31 AC 92 ms
6,184 KB
testcase_32 AC 108 ms
6,180 KB
testcase_33 AC 109 ms
6,176 KB
testcase_34 AC 116 ms
6,176 KB
testcase_35 AC 116 ms
6,180 KB
testcase_36 AC 61 ms
5,956 KB
testcase_37 AC 60 ms
5,956 KB
testcase_38 AC 3 ms
4,532 KB
testcase_39 AC 4 ms
4,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)

using namespace std;
using ll = long long;

const int U = 1 << 14;
int K;
vector<int> items[U * 2];

void add(int l, int r, int v) {
  l += U;
  r += U - 1;
  while (l <= r) {
    if ((l & 1) == 1) items[l++].push_back(v);
    if ((r & 1) == 0) items[r--].push_back(v);
    l >>= 1;
    r >>= 1;
  }
}

int ans[U];

void dfs(int k, bitset<15001> dp) {
  for (int x : items[k]) dp |= dp << x;
  if (k >= U) {
    k -= U;
    ans[k] = dp[K];
    return;
  }
  dfs(k * 2 + 0, dp);
  dfs(k * 2 + 1, dp);
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N; cin >> N >> K;
  vector<int> A(N); rep(i, N) cin >> A[i];
  vector<int> prev(N, 0);
  int Q; cin >> Q;
  for (int i = 1; i <= Q; i++) {
    int x, v; cin >> x >> v; x--;
    add(prev[x], i, A[x]);
    A[x] = v;
    prev[x] = i;
  }
  rep(i, N) add(prev[i], U, A[i]);
  bitset<15001> dp;
  dp[0] = true;
  dfs(1, dp);
  rep(i, Q) cout << ans[i+1] << '\n';
}
0