結果
| 問題 |
No.868 ハイパー部分和問題
|
| コンテスト | |
| ユーザー |
lumc_
|
| 提出日時 | 2019-08-17 10:58:21 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2,558 ms / 7,000 ms |
| コード長 | 1,383 bytes |
| コンパイル時間 | 1,035 ms |
| コンパイル使用メモリ | 108,936 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-09-24 19:02:15 |
| 合計ジャッジ時間 | 33,124 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 38 |
ソースコード
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;
constexpr int B = 300;
constexpr int N = 1.5e4;
int n, k, q;
int a[N];
int x[N], v[N];
int main() {
std::ios::sync_with_stdio(false), std::cin.tie(0);
cin >> n >> k;
for(int i = 0; i < n; i++) cin >> a[i];
cin >> q;
for(int i = 0; i < q; i++) {
cin >> x[i] >> v[i];
x[i]--;
}
vector<int> use(n, -1);
vector<int> after;
// O(Q/B)
for(int i = 0; i < q; i+=B) {
after.clear();
bitset<N + 1> dp;
dp[0] = 1;
// O(B)
for(int j = i; j < min<int>(q, i + B); j++) {
use[x[j]] = i;
}
// O(N^2 / 64)
for(int j = 0; j < n; j++) {
if(use[j] != i) dp |= dp << a[j];
else after.push_back(j);
}
// O(B)
for(int j = i; j < min<int>(q, i + B); j++) {
auto dp2 = dp;
// O(BN / 64)
for(auto p : after) if(p != x[j]) dp2 |= dp2 << a[p];
dp2 |= dp2 << v[j];
cout << dp2[k] << "\n";
a[x[j]] = v[j];
}
}
// O(Q/B(N^2 + B^2N) / 64)
// = O(N^2Q/B + QBN / 64)
return 0;
}
lumc_