题解 | #材料打印#
小红喜欢1
https://ac.nowcoder.com/acm/contest/88888/A
F(线段树+map)
代码
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 9;
struct node {
int l, r;
int v;
}tr[N << 2];
int minv[N];
void pushup(int u) {
tr[u].v = min(tr[u << 1].v, tr[u << 1 | 1].v);
}
void build(int u, int l, int r) {
tr[u] = {l, r};
if (l == r) tr[u] = {l, r, minv[l]};
else {
int mid = l + r >> 1;
build(u << 1, l, mid), build(u << 1 | 1, mid + 1, r);
pushup(u);
}
}
int query(int u, int l, int r) {
if (tr[u]. l >= l && tr[u].r <= r) return tr[u].v;
int mid = tr[u].l + tr[u].r >> 1;
int val = 1e9 + 7;
if (l <= mid) val = query(u << 1, l, r);
if (r > mid) val = min(val, query(u << 1 | 1, l, r));
return val;
}
void modify(int u, int x, int val) {
if (tr[u].l == x && tr[u].r == x) tr[u].v = val;
else {
int mid = tr[u].l + tr[u].r >> 1;
if (x <= mid) modify(u << 1, x, val);
else modify(u << 1 | 1, x, val);
pushup(u);
}
}
int main() {
int n; cin >> n;
vector<vector<int>> a(n + 1);
vector<map<int, int>> b(n + 1);
vector<int> num(n + 1);
for (int i = 1; i <= n; i ++ ) {
cin >> num[i];
int mn = (int)1e9 + 7;
for (int j = 1; j <= num[i]; j ++ ) {
int x; cin >> x;
mn = min(mn, x);
b[i][x] += 1;
a[i].push_back(x);
}
minv[i] = mn;
}
build(1, 1, n);
int q; cin >> q;
while (q -- ) {
int op; cin >> op;
if (op == 1) {
int i, j, val; cin >> i >> j >> val;
j -= 1;
b[i][a[i][j]] -= 1;
if (b[i][a[i][j]] == 0) b[i].erase(a[i][j]);
b[i][val] += 1;
a[i][j] = val;
auto t = b[i].begin();
modify(1, i, t->first);
}else {
int i; cin >> i;
cout << query(1, 1, i) << endl;
}
}
return 0;
}