版本比较
杂题做题记录4
正文
增加 41 行删除 2 行
12345678854 行未改动全部展开863864865866## 2025.11.26前几天过了一堆板子,做了点 NOIP 真题,没做什么杂题。### [CF1408D Searchlights](https://codeforces.com/problemset/problem/1408/D)两个操作之间没有偏序关系。所以所有操作可以视为每个人进行:854 行未改动全部展开cout << ans << endl;return 0;}```123456854 行未改动全部展开861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905## 2025.11.26### [CF1408D Searchlights](https://codeforces.com/problemset/problem/1408/D)两个操作之间没有偏序关系。所以所有操作可以视为每个人进行:854 行未改动全部展开cout << ans << endl;return 0;}```### [CF1098D Eels](https://codeforces.com/problemset/problem/1098/D)神仙题。一个贪心的想法,每次从集合中挑出权值最小的两个操作,答案一定不劣。于是考虑按照 $\{a_i\}$ 排序。如果一条鱼 $i$ 有贡献,需要满足:$$a_i\le 2\cdot \sum_{j<i}a_j$$按照 $a_i$ 的大小划分到集合 $[2^0,2^1),[2^1,2^2),\cdots,[2^{30},2^{31})$。注意到一个集合中如果有数无贡献,那么一定是集合中最小的。用 multiset 维护即可做到 $O(n\log^2 n)$。```cppconst int LG = 30;int n, ans; ll sum[LG + 2];multiset<ll> a[LG + 2];int main() {ios::sync_with_stdio(0);cin >> n; char op; ll x; while (n--) {cin >> op >> x;int p; for (p = 1; (1 << p) <= x; ++p); --p;if (op == '+') sum[p]+= x, a[p].insert(x);else sum[p]-= x, a[p].erase(a[p].find(x));ans = 0; ll s = 0;for (int i = 0; i < 30; ++i) if (a[i].size()) {ans+= (int)a[i].size() - ((*a[i].begin()) > 2 * s);s+= sum[i];}cout << ans << endl;}return 0;}```