結果
| 問題 | No.868 ハイパー部分和問題 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-06-24 22:46:10 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 2,914 ms / 7,000 ms |
| コード長 | 1,112 bytes |
| 記録 | |
| コンパイル時間 | 2,577 ms |
| コンパイル使用メモリ | 330,676 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-06-24 22:46:56 |
| 合計ジャッジ時間 | 45,847 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 38 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
const int N = 15000 + 5, M = 15000;
const int inf = 1e9, mod = 1000000321;
const ll INF = 1e18;
int n, k, a[N], f[N << 1];
void del(int x){
if (!x) return ;
for (int i = 0; i + x <= k + M; i ++ ) f[i + x] = ((f[i + x] - f[i]) % mod + mod) % mod;
}
void add(int x){
if (!x) return ;
for (int i = k - x + M; i >= 0; i -- ) f[i + x] = ((f[i + x] + f[i]) % mod + mod) % mod;
}
void init(){
}
void solve(){
cin >> n >> k;
f[0] = 1;
for (int i = 1; i <= n; i ++ ) cin >> a[i], add(a[i]);
int q; cin >> q;
while (q -- ){
int pos, x; cin >> pos >> x;
del(a[pos]), a[pos] = x, add(a[pos]);
if (f[k]) cout << "1\n";
else cout << "0\n";
}
}
signed main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int T = 1; //cin >> T;
while (T -- ) init(), solve();
}
/*
这题是唐吧,经典的结论,删数字用完全背包类型,加数字用 01 背包类型
我在洛谷上做过一个删,加的,没想到还有高手啊。
*/