0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-24 03:31:59 +00:00

#1530. 【2022 正睿 NOIP 十连测 Day 2】砝码称重(weight)

https://sjzezoj.com/submission/60512
This commit is contained in:
Baoshuo Ren 2022-10-17 20:44:39 +08:00
parent 27d663a4df
commit c6e9fefa08
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
22 changed files with 207 additions and 0 deletions

144
S2OJ/1530/1530.cpp Normal file
View File

@ -0,0 +1,144 @@
#include <iostream>
#include <algorithm>
#include <map>
#include <tuple>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 1e6 + 5,
M = 1e5 + 5;
int n, m, q, cnt, a[N];
std::map<int, int> map;
std::tuple<int, int, int, int> ops[N];
bool f[(1 << 10) + 5][M];
struct node {
int l, r, d, s;
node(int _l = 0, int _r = 0)
: l(_l), r(_r), d(0), s(0) {}
} tr[N << 2];
void pushup(int u) {
tr[u].s = tr[u << 1].s | tr[u << 1 | 1].s;
}
void pushdown(int u) {
if (!tr[u].d) return;
tr[u << 1].s = tr[u << 1 | 1].s = 1 << map[tr[u].d];
tr[u << 1].d = tr[u << 1 | 1].d = tr[u].d;
tr[u].d = 0;
}
void build(int u, int l, int r) {
tr[u] = node(l, r);
if (l == r) {
tr[u].s = 1 << map[a[l]];
return;
}
int mid = (l + r) >> 1;
build(u << 1, l, mid);
build(u << 1 | 1, mid + 1, r);
pushup(u);
}
void modify(int u, int l, int r, int x) {
if (l <= tr[u].l && tr[u].r <= r) {
tr[u].s = 1 << map[x];
tr[u].d = x;
return;
}
pushdown(u);
int mid = (tr[u].l + tr[u].r) >> 1;
if (l <= mid) modify(u << 1, l, r, x);
if (r > mid) modify(u << 1 | 1, l, r, x);
pushup(u);
}
int query(int u, int l, int r) {
if (l <= tr[u].l && tr[u].r <= r) return tr[u].s;
pushdown(u);
int mid = (tr[u].l + tr[u].r) >> 1;
int res = 0;
if (l <= mid) res |= query(u << 1, l, r);
if (r > mid) res |= query(u << 1 | 1, l, r);
return res;
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m >> q;
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (!map.count(a[i])) map[a[i]] = -1;
}
for (int i = 1, op, l, r, x; i <= q; i++) {
cin >> op >> l >> r >> x;
if (op == 1) {
if (!map.count(x)) map[x] = -1;
}
ops[i] = std::make_tuple(op, l, r, x);
}
std::vector<int> nums;
for (auto &item : map) {
nums.emplace_back(item.first);
item.second = cnt++;
}
f[0][0] = true;
for (int s = 1; s < 1 << cnt; s++) {
int p = __builtin_ctz(s);
for (int i = 0; i <= m; i++) {
f[s][i] |= f[s ^ (1 << p)][i];
}
for (int i = nums[p]; i <= m; i++) {
f[s][i] |= f[s][i - nums[p]];
}
}
build(1, 1, n);
for (int i = 1, op, l, r, x; i <= q; i++) {
std::tie(op, l, r, x) = ops[i];
if (op == 1) {
modify(1, l, r, x);
} else { // op == 2
int s = query(1, l, r);
cout << (f[s][x] ? "Yes" : "No") << endl;
}
}
return 0;
}

BIN
S2OJ/1530/data/problem.conf (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1530/data/weight1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1530/data/weight1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1530/data/weight10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1530/data/weight10.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1530/data/weight2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1530/data/weight2.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1530/data/weight3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1530/data/weight3.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1530/data/weight4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1530/data/weight4.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1530/data/weight5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1530/data/weight5.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1530/data/weight6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1530/data/weight6.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1530/data/weight7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1530/data/weight7.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1530/data/weight8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1530/data/weight8.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1530/data/weight9.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1530/data/weight9.out (Stored with Git LFS) Normal file

Binary file not shown.