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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
| #include <bits/stdc++.h>
#define x first #define y second #define y1 Y1 #define y2 Y2 #define mp make_pair #define pb push_back #define DEBUG(x) cout << #x << " = " << x << endl;
using namespace std;
typedef long long LL; typedef pair <int, int> pii;
template <typename T> inline int Chkmax (T &a, T b) { return a < b ? a = b, 1 : 0; } template <typename T> inline int Chkmin (T &a, T b) { return a > b ? a = b, 1 : 0; } template <typename T> inline T read () { T sum = 0, fl = 1; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == '-') fl = -1; for (; isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) + ch - '0'; return sum * fl; }
inline void proc_status () { ifstream t ("/proc/self/status"); cerr << string (istreambuf_iterator <char> (t), istreambuf_iterator <char> ()) << endl; }
const int Maxn = 1e5 + 100;
int N, M, K, Max = 1e5; struct item { int p, v, t, x; }; vector <item> A; priority_queue <pii, vector <pii>, greater <pii> > Q; LL Ans[Maxn];
namespace DSU { int fa[Maxn]; inline void init (int n = 1e5) { for (int i = 1; i <= n; ++i) fa[i] = i; } inline int get_fa (int x) { return fa[x] == x ? x : fa[x] = get_fa (fa[x]); } }
int Rest[Maxn];
inline int cmp (item a, item b) { return a.p > b.p; }
inline void Init () { DSU :: init (); for (int i = 1; i <= Max; ++i) Rest[i] = M; sort (A.begin(), A.end(), cmp);
for (int i = 0; i < A.size(); ++i) { int p = A[i].p, v = A[i].v, t = A[i].t, x = A[i].x; int res = 0, sum = 0; while (1) { int to = DSU :: get_fa (t); if (!to) break; res = min (v, res + (t - to + 1) * x); int now = min (Rest[to], res); res -= now, Rest[to] -= now, v -= now, sum += now; if (!v) break; if (!Rest[to]) DSU :: fa[to] = DSU :: fa[to - 1]; t = to - 1; if (!t) break; } Ans[Max] += (LL) p * sum; if (sum) Q.push (mp (p, sum)); } }
inline void Solve () { Init();
int sum = 0; for (int i = 1; i <= Max; ++i) sum += M - Rest[i], Rest[i] = 0; for (int i = 1; i <= Max; ++i) Rest[i] = min (sum, M), sum = max (0, sum - M);
for (int i = Max - 1; i >= 1; --i) { Ans[i] = Ans[i + 1];
while (!Q.empty() && Rest[i + 1]) { pii now = Q.top(); Q.pop(); int use = min (Rest[i + 1], now.y); Ans[i] -= (LL) now.x * use; if (use == Rest[i + 1]) { Q.push (mp (now.x, now.y - Rest[i + 1])); break; } Rest[i + 1] -= now.y; } }
for (int i = 1; i <= K; ++i) printf("%lld\n", Ans[read<int>()]); }
inline void Input () { N = read<int>(), M = read<int>(), K = read<int>(); for (int i = 1; i <= N; ++i) { int p = read<int>(), a = read<int>(), v = read<int>(), x = read<int>(); if (x) { int t = (v - 1 + x) / x; A.pb ((item){p, (t - 1) * x, t - 1, min (M, x)}); A.pb ((item){p + a, 1, t, 1}); A.pb ((item){p, (v - 1) % x, t, (v - 1) % x}); } else { A.pb ((item){p, v - 1, Max, M}); A.pb ((item){p + a, 1, Max, 1}); } } }
int main() {
#ifndef ONLINE_JUDGE freopen("A.in", "r", stdin); freopen("A.out", "w", stdout); #endif
Input (); Solve ();
return 0; }
|