#include <iostream> #include <cstdio> #include <cctype> #include <algorithm> #include "segmenttree.h" using namespace std; typedef long long ll; int read() { int out = 0; char c; while (!isdigit(c = getchar())); for (; isdigit(c); c = getchar()) out = out * 10 + c - '0'; return out; } const int N = 300010; const ll INF = 1e18; int n, m; ll pre[N], ans; struct Girl { int l, r, p, id; bool operator<(const Girl& y) const { return p > y.p; } } g[N]; struct Value { ll mn, mx; bool inv; Value(ll _mn = INF, ll _mx = -INF, int _inv = false) { mn = _mn; mx = _mx; inv = _inv; } }; vector<Value> a; Value merge(Value x, Value y) { return Value(min(x.mn, y.mn), max(x.mx, y.mx), x.inv || y.inv || x.mx > y.mn); } void update(segmentTreeNode<Value, int>& u, int x) { u.val.mx += x; u.val.mn += x; u.tag += x; } int main() { n = read(); m = read(); for (int i = 1; i <= m; ++i) pre[i] = pre[i - 1] + read(); a.resize(n + 1); for (int i = 1; i <= n; ++i) { g[i].l = read(); g[i].r = read(); g[i].p = read(); g[i].id = i; a[i].mn = pre[g[i].r]; a[i - 1].mx = pre[g[i].l - 1]; } sort(g + 1, g + n + 1); segmentTree<Value, int, merge, update> t(0, n + 1, a, Value()); for (int i = 1; i <= n; ++i) { t.modify(g[i].id, n + 1, -1); if (t.query(0, n + 1).inv) t.modify(g[i].id, n + 1, 1); else ans += g[i].p; } cout << ans; return 0; }
|
评论正在加载中...如果评论较长时间无法加载,你可以 搜索对应的 issue 或者 新建一个 issue 。