正文
增加 5 行删除 5 行
29 行未改动3031323334353637383940414243444546474849505152535455565758596012 行未改动7374757677787980818229 行未改动#define int long long#define mid (l + r >> 1)const int N = 2e5 + 5, inf = -1e15;int n, _n, m, ans, idw[N], f[N];struct node{int _a, _b;} a[N];inline bool cmp(node A, node B) {return A._b < B._b;}inline bool cmpp(int A, int B) {return A > B;}namespace Zx_Tree{struct node{int ls, rs, s, siz;} t[N * 30];int rot[N], tot;inline void psup(int u) {t[u].s = t[t[u].ls].s + t[t[u].rs].s, t[u].siz = t[t[u].ls].siz + t[t[u].rs].siz;}inline int S(int x, int y) {return t[y].s - t[x].s;}inline int Siz(int x, int y) {return t[y].siz - t[x].siz;}inline void upd(int ua, int &ub, int l, int r, int k, int p){t[ub = ++tot] = t[ua];if(l == r) {t[ub].s += p, ++t[ub].siz; return ;}if(k <= mid) upd(t[ua].ls, t[ub].ls, l, mid, k, p);else upd(t[ua].rs, t[ub].rs, mid + 1, r, k, p);psup(ub);}inline int qry(int ua, int ub, int l, int r, int p){if(Siz(ua, ub) <= p) return S(ua, ub);if(l == r) return p * idw[l];if(Siz(t[ua].rs, t[ub].rs) >= p) return qry(t[ua].rs, t[ub].rs, mid + 1, r, p);else return S(t[ua].rs, t[ub].rs) + qry(t[ua].ls, t[ub].ls, l, mid, p - Siz(t[ua].rs, t[ub].rs));}}using namespace Zx_Tree;inline int w(int x, int y) {return qry(rot[x - 1], rot[y], 1, n, m - 2);}inline void calc(int l, int r, int kl, int kr){12 行未改动for(int i = 1; i <= n; ++i) idw[i] = a[i]._a, f[i] = inf;sort(idw + 1, idw + 1 + n), _n = unique(idw + 1, idw + 1 + n) - idw - 1;for(int i = 1; i <= n; ++i) a[i]._a = lower_bound(idw + 1, idw + 1 + _n, a[i]._a) - idw;for(int i = 1; i <= n; ++i) upd(rot[i - 1], rot[i], 1, n, a[i]._a, idw[a[i]._a]);calc(1, n, 1, n);ans = inf; for(int i = 1; i <= n; ++i) ans = max(ans, f[i]);cout << ans;return 0;}```29 行未改动3031323334353637383940414243444546474849505152535455565758596012 行未改动7374757677787980818229 行未改动#define int long long#define mid (l + r >> 1)const int N = 2e5 + 5, inf = -1e15;int n, _n, m, ans, idw[N], f[N];struct node{int _a, _b;} a[N];inline bool cmp(node A, node B) {return A._b < B._b;}inline bool cmpp(int A, int B) {return A > B;}namespace Zx_Tree{struct node{int ls, rs, s, siz;} t[N * 30];int rot[N], tot;inline void psup(int u) {t[u].s = t[t[u].ls].s + t[t[u].rs].s, t[u].siz = t[t[u].ls].siz + t[t[u].rs].siz;}inline int S(int x, int y) {return t[y].s - t[x].s;}inline int Siz(int x, int y) {return t[y].siz - t[x].siz;}inline void upd(int ua, int &ub, int l, int r, int k, int p){t[ub = ++tot] = t[ua];if(l == r) {t[ub].s += p, ++t[ub].siz; return ;}if(k <= mid) upd(t[ua].ls, t[ub].ls, l, mid, k, p);else upd(t[ua].rs, t[ub].rs, mid + 1, r, k, p);psup(ub);}inline int qry(int ua, int ub, int l, int r, int p){if(Siz(ua, ub) <= p) return S(ua, ub);if(l == r) return p * idw[l];if(Siz(t[ua].rs, t[ub].rs) >= p) return qry(t[ua].rs, t[ub].rs, mid + 1, r, p);else return S(t[ua].rs, t[ub].rs) + qry(t[ua].ls, t[ub].ls, l, mid, p - Siz(t[ua].rs, t[ub].rs));}}using namespace Zx_Tree;inline int w(int x, int y) {return qry(rot[x - 1], rot[y], 1, n, m - 2);}inline void calc(int l, int r, int kl, int kr){12 行未改动for(int i = 1; i <= n; ++i) idw[i] = a[i]._a, f[i] = inf;sort(idw + 1, idw + 1 + n), _n = unique(idw + 1, idw + 1 + n) - idw - 1;for(int i = 1; i <= n; ++i) a[i]._a = lower_bound(idw + 1, idw + 1 + _n, a[i]._a) - idw;for(int i = 1; i <= n; ++i) upd(rot[i - 1], rot[i], 1, n, a[i]._a, idw[a[i]._a]);calc(1, n, 1, n);ans = inf; for(int i = 1; i <= n; ++i) ans = max(ans, f[i]);cout << ans;return 0;}```