1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
#include <bits/stdc++.h> using namespace std; #define resetIO(x) \ freopen(#x ".in", "r", stdin), freopen(#x ".out", "w", stdout) #define debug(fmt, ...) \ fprintf(stderr, "[%s:%d] " fmt "\n", __FILE__, __LINE__, ##__VA_ARGS__) template <class _Tp> inline _Tp& read(_Tp& x) { bool sign = false; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) sign |= (ch == '-'); for (x = 0; isdigit(ch); ch = getchar()) x = x * 10 + (ch ^ 48); return sign ? (x = -x) : x; } template <class _Tp> inline void write(_Tp x) { if (x < 0) putchar('-'), x = -x; if (x > 9) write(x / 10); putchar((x % 10) ^ 48); } bool m_be; using ll = long long; using pii = pair<int, int>; #define fi first #define se second const int MAXN = 2e5 + 10; const int INF = 0x3f3f3f3f; int n; struct Node { int q, t, x, n; bool operator<(const Node& o) const { return x - t < o.x - o.t || (x - t == o.x - o.t && x > o.x); } } a[MAXN]; bool m_ed; signed main() { read(n); for (int i = 1; i <= n; ++i) read(a[i].q), read(a[i].t), read(a[i].x), read(a[i].n); sort(a + 1, a + n + 1); multiset<pii> st; ll ans = 0; for (int i = 1; i <= n; ++i) { if (a[i].q == 1) { auto it = st.lower_bound({a[i].t + a[i].x, 0}); while (a[i].n && it != st.end()) { int tmp = min(a[i].n, it->se); ans += tmp, a[i].n -= tmp; if (it->se == tmp) st.erase(it++); else st.insert({it->fi, it->se - tmp}), st.erase(it); } } else { if (a[i].n) st.insert({a[i].t + a[i].x, a[i].n}); } } write(ans), putchar('\n'); return 0; }
|