結果

問題 No.868 ハイパー部分和問題
ユーザー 👑 hos.lyrichos.lyric
提出日時 2019-08-17 01:03:25
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3,772 ms / 7,000 ms
コード長 2,517 bytes
コンパイル時間 1,935 ms
コンパイル使用メモリ 128,860 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-24 16:38:25
合計ジャッジ時間 33,920 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,372 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 2 ms
4,372 KB
testcase_03 AC 2 ms
4,372 KB
testcase_04 AC 2 ms
4,372 KB
testcase_05 AC 2 ms
4,372 KB
testcase_06 AC 2 ms
4,372 KB
testcase_07 AC 2 ms
4,372 KB
testcase_08 AC 2 ms
4,372 KB
testcase_09 AC 2 ms
4,372 KB
testcase_10 AC 2 ms
4,372 KB
testcase_11 AC 2 ms
4,372 KB
testcase_12 AC 2 ms
4,372 KB
testcase_13 AC 2 ms
4,372 KB
testcase_14 AC 2,710 ms
4,372 KB
testcase_15 AC 2,696 ms
4,372 KB
testcase_16 AC 2,707 ms
4,372 KB
testcase_17 AC 2,685 ms
4,372 KB
testcase_18 AC 2,689 ms
4,372 KB
testcase_19 AC 529 ms
4,372 KB
testcase_20 AC 530 ms
4,372 KB
testcase_21 AC 534 ms
4,372 KB
testcase_22 AC 529 ms
4,372 KB
testcase_23 AC 529 ms
4,372 KB
testcase_24 AC 528 ms
4,372 KB
testcase_25 AC 530 ms
4,372 KB
testcase_26 AC 530 ms
4,372 KB
testcase_27 AC 528 ms
4,372 KB
testcase_28 AC 528 ms
4,372 KB
testcase_29 AC 354 ms
4,372 KB
testcase_30 AC 350 ms
4,372 KB
testcase_31 AC 359 ms
4,372 KB
testcase_32 AC 707 ms
4,372 KB
testcase_33 AC 706 ms
4,372 KB
testcase_34 AC 3,772 ms
4,372 KB
testcase_35 AC 3,750 ms
4,372 KB
testcase_36 AC 757 ms
4,372 KB
testcase_37 AC 758 ms
4,372 KB
testcase_38 AC 2 ms
4,372 KB
testcase_39 AC 2 ms
4,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx")

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#include <random>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> void chmin(T &t, const T &f) { if (t > f) t = f; }
template <class T> void chmax(T &t, const T &f) { if (t < f) t = f; }

int N, K;
int A[20010];
int Q;
int X[20010], V[20010];

int a[20010];

constexpr int H = 4;
int MOs[10];
int dp[10][20010];

void init() {
  for (int h = 0; h < H; ++h) {
    fill(dp[h], dp[h] + K + 1, 0);
    dp[h][0] = 1;
  }
}
void add(int x) {
  if (x != 0) {
    for (int h = 0; h < H; ++h) {
      for (int j = K; j >= x; --j) {
        if ((dp[h][j] += dp[h][j - x]) >= MOs[h]) {
          dp[h][j] -= MOs[h];
        }
      }
    }
  }
}
void remove(int x) {
  if (x != 0) {
    for (int h = 0; h < H; ++h) {
      for (int j = x; j <= K; ++j) {
        if ((dp[h][j] -= dp[h][j - x]) < 0) {
          dp[h][j] += MOs[h];
        }
      }
    }
  }
}
int get() {
  for (int h = 0; h < H; ++h) {
    if (dp[h][K] != 0) {
      return 1;
    }
  }
  return 0;
}

int main() {
  MOs[0] = 998244353;
  MOs[1] = 1000000009;
  
  random_device device;
  mt19937 rng(device());
  uniform_int_distribution<int> distr(505005005, 1001001001);
  for (int h = 2; h < H; ++h) {
    MOs[h] = distr(rng);
  }
// cerr<<"MOs = ";pv(MOs,MOs+H);
  
  for (; ~scanf("%d%d", &N, &K); ) {
    for (int i = 0; i < N; ++i) {
      scanf("%d", &A[i]);
    }
    scanf("%d", &Q);
    for (int q = 0; q < Q; ++q) {
      scanf("%d%d", &X[q], &V[q]);
      --X[q];
    }
    
    init();
    for (int i = 0; i < N; ++i) {
      add(A[i]);
    }
    copy(A, A + N, a);
    
    for (int q = 0; q < Q; ++q) {
      remove(a[X[q]]);
      a[X[q]] = V[q];
      add(a[X[q]]);
// pv(a,a+N);
// pv(dp[0],dp[0]+K+1);
// pv(dp[1],dp[1]+K+1);
      printf("%d\n", get());
    }
  }
  return 0;
}
0