版本比较
min(max, max) = max + max - max
正文
增加 7 行删除 7 行
7 行未改动89101112131415166 行未改动23242526272829303187 行未改动11912012112212312412512612718 行未改动1461471481491501511521531541551561571582 行未改动7 行未改动现在的问题变成如何计算所有序列的前缀 $\max$ 的和。直接 dp,设 $f_{i, j}$ 为考虑前 $i$ 个位置,此时的前缀 $\max = j$ 的方案数,不妨设 $a_i < b_i$,则转移相当于:- $f_{i - 1, [0, a_i - 1]} \to f_{i, a_i}$- $f_{i - 1, [0, b_i - 1]} \to f_{i, b_i}$。- $\forall a_i \le j < b_i, f_{i - 1, j} \to f_{i, j}$6 行未改动```cpp#include<bits/stdc++.h>#define ll long long#define il inline#define pir pair<ll, ll>#define mkpir make_pair#define umap unordered_map#define pb emplace_back#define fi first87 行未改动for(int i = 1; i <= n; i++){ll sa = tr.getsum(1, 0, V, 0, a[i] - 1), sb = tr.getsum(1, 0, V, 0, b[i] - 1);tr.Segmul(1, 0, V, 0, a[i] - 1, 0ll); tr.Segmul(1, 0, V, b[i], V, 2ll);tr.Segadd(1, 0, V, a[i], a[i], sa); tr.Segadd(1, 0, V, b[i], b[i], sb);ADD(ret, pw2[n - i] * tr.ANS[1] % mod);} return ret;}void clr(){18 行未改动ll ans = 0, res = 1, lst = 0;for(int i = 1; i <= n; i++) ADD(ans, pw2[n - 1] * (rk[a[i]] + rk[b[i]]) % mod);int cnt = 0;for(int i = 1; i <= V; i++){cnt += cnt0[i]; MUL(res, pw2[cnt1[i]]);ll rel = res * (cnt == n);ADD(ans, (rel - lst + mod) * rk[i] % mod * n % mod); lst = rel;}ans = mod - ans;ADD(ans, solve()); reverse(a + 1, a + n + 1); reverse(b + 1, b + n + 1);ADD(ans, solve()); cout << ans;return 0;2 行未改动7 行未改动89101112131415166 行未改动23242526272829303187 行未改动11912012112212312412512612718 行未改动1461471481491501511521531541551561571582 行未改动7 行未改动现在的问题变成如何计算所有序列的前缀 $\max$ 的和。直接 dp,设 $f_{i, j}$ 为考虑前 $i$ 个位置,此时的前缀 $\max = j$ 的方案数,不妨设 $a_i < b_i$,则转移相当于:- $f_{i - 1, [0, a_i - 1]} \to f_{i, a_i}$- $f_{i - 1, [0, b_i - 1]} \to f_{i, b_i}$。- $\forall a_i \le j < b_i, f_{i - 1, j} \to f_{i, j}$6 行未改动```cpp#include<bits/stdc++.h>#define ll long long#define il inline#define pir pair<ll, ll>#define mkpir make_pair#define umap unordered_map#define pb emplace_back#define fi first87 行未改动for(int i = 1; i <= n; i++){ll sa = tr.getsum(1, 0, V, 0, a[i] - 1), sb = tr.getsum(1, 0, V, 0, b[i] - 1);tr.Segmul(1, 0, V, 0, a[i] - 1, 0ll); tr.Segmul(1, 0, V, b[i], V, 2ll);tr.Segadd(1, 0, V, a[i], a[i], sa); tr.Segadd(1, 0, V, b[i], b[i], sb);ADD(ret, pw2[n - i] * tr.ANS[1] % mod);} return ret;}void clr(){18 行未改动ll ans = 0, res = 1, lst = 0;for(int i = 1; i <= n; i++) ADD(ans, pw2[n - 1] * (rk[a[i]] + rk[b[i]]) % mod);int cnt = 0;for(int i = 1; i <= V; i++){cnt += cnt0[i]; MUL(res, pw2[cnt1[i]]);ll rel = res * (cnt == n);ADD(ans, (rel - lst + mod) * rk[i] % mod * n % mod); lst = rel;}ans = mod - ans;ADD(ans, solve()); reverse(a + 1, a + n + 1); reverse(b + 1, b + n + 1);ADD(ans, solve()); cout << ans;return 0;2 行未改动