1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
| #include <bits/stdc++.h>
using f64 = long double;
const int kMaxN = 2e5 + 5;
int n, m, q; f64 ans; int l[kMaxN], p[kMaxN], t[kMaxN]; std::multiset<std::pair<f64, int>> st[2];
f64 getdet(int x, int v) { return (f64)p[x] * l[x] / (l[x] + t[x]) / (l[x] + t[x] + v); }
void add(int x) { --m; st[1].erase({getdet(x, 1), x}); if (t[x]) st[0].erase({getdet(x, -1), x}); ans += getdet(x, 1), ++t[x]; st[0].emplace(getdet(x, -1), x); if (t[x] < l[x]) st[1].emplace(getdet(x, 1), x); }
void del(int x) { ++m; if (t[x] < l[x]) st[1].erase({getdet(x, 1), x}); st[0].erase({getdet(x, -1), x}); ans -= getdet(x, -1), --t[x]; if (t[x]) st[0].emplace(getdet(x, -1), x); st[1].emplace(getdet(x, 1), x); }
void dickdreamer() { std::cin >> n >> m >> q; for (int i = 1; i <= n; ++i) std::cin >> p[i]; for (int i = 1; i <= n; ++i) std::cin >> l[i]; for (int i = 1; i <= n; ++i) st[1].emplace(getdet(i, 1), i); for (; m && !st[1].empty();) add(st[1].rbegin()->second); for (int i = 1; i <= q; ++i) { int op, x; std::cin >> op >> x; if (op == 1) { if (t[x]) st[0].erase({getdet(x, -1), x}); if (t[x] < l[x]) st[1].erase({getdet(x, 1), x}); ans -= (f64)p[x] * t[x] / (t[x] + l[x]); ++l[x]; } else { if (t[x] == l[x]) del(x); if (t[x]) st[0].erase({getdet(x, -1), x}); if (t[x] < l[x]) st[1].erase({getdet(x, 1), x}); ans -= (f64)p[x] * t[x] / (t[x] + l[x]); --l[x]; } ans += (f64)p[x] * t[x] / (t[x] + l[x]); if (t[x]) st[0].emplace(getdet(x, -1), x); if (t[x] < l[x]) st[1].emplace(getdet(x, 1), x); for (; m && !st[1].empty();) add(st[1].rbegin()->second); if (!st[0].empty() && !st[1].empty()) { auto [det1, j1] = *st[0].begin(); auto [det2, j2] = *st[1].rbegin(); if (det1 < det2) del(j1), add(j2); } std::cout << std::fixed << std::setprecision(10) << ans << '\n'; } }
int32_t main() { #ifdef ORZXKR freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif std::ios::sync_with_stdio(0), std::cin.tie(0), std::cout.tie(0); int T = 1; while (T--) dickdreamer(); return 0; }
|