CF626G Raffles 题解
1.CF505E Mr. Kitayuta vs. Bamboos 题解2.CF506E Mr. Kitayuta's Gift 题解3.CF512D Fox And Travelling 题解4.CF516D Drazil and Morning Exercise 题解5.CF516E Drazil and His Happy Friends 题解6.CF521D Shop 题解7.CF521E Cycling City 题解8.CF527E Data Center Drama 题解9.CF547D Mike and Fish 题解10.CF559E Gerald and Path 题解11.CF568C New Language 题解12.CF576D Flights for Regular Customers 题解13.CF578E Walking! 题解14.CF585F Digits of Number Pi 题解15.CF605E Intergalaxy Trips 题解16.CF613E Puzzle Lover 题解
17.CF626G Raffles 题解
18.CF526G Spiders Evil Plan 题解19.CF538G Berserk Robot 题解20.CF538H Summer Dichotomy 题解21.CF553E Kyoya and Train 题解22.CF566C Logistical Questions 题解23.CF566E Restoring Map 题解24.CF568E Longest Increasing Subsequence 题解25.CF571E Geometric Progressions 题解26.CF573E Bear and Bowling 题解27.CF578F Mirror Box 题解28.[AGC038E] Gachapon 题解29.CF666E Forensic Examination 题解30.CF671E Organizing a Race 题解Description
- 有
个奖池,第 个奖池的奖金是 ,已经有 张彩票押在上面。 - 现在你有
张彩票,你需要将你的彩票分配到这些奖池中,并且保证你在每个奖池中押的彩票数不能超过该奖池原有的彩票数。 - 若你在第
个奖池中押了 张彩票,则你中奖的概率为 ,若你中奖,你可以获得这个奖池的全部奖金 。 - 一共有
次事件,每次事件会使某个 加 或减 。 - 你需要在每个事件后求出在最佳方案下你获得的奖金总数的最大期望值。
, ,答案精度误差 。
Solution
首先单次
考虑怎么支持修改。
不妨设修改了
有一个结论是每次选出当前已经选择的
证明就考虑设
注意到
对于
时间复杂度:
Code
#include <bits/stdc++.h> // #define int int64_t 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; // std::cin >> T; while (T--) dickdreamer(); // std::cerr << 1.0 * clock() / CLOCKS_PER_SEC << "s\n"; return 0; }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步