Submission #583558

#TimeUsernameProblemLanguageResultExecution timeMemory
583558JohannTwo Dishes (JOI19_dishes)C++14
5 / 100
902 ms40740 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pii pair<ll,ll> #define tiii tuple<int,int,int> #define vi vector<ll> #define vpii vector<pii> #define vtiii vector<tiii> #define vvi vector<vi> #define sz(x) (int) (x).size() #define all(x) (x).begin(), (x).end() const ll inf = 1LL << 60; const int MAXN = 1e6 + 7; ll N[2]; ll A[2][MAXN],T[2][MAXN],P[2][MAXN]; typedef ll data; struct operation { ll addopt=0; ll maxopt=-inf; }; struct segtree { vector<data> arr; vector<operation> opt; int size; segtree(int N) { size = 1; while (size < N) size *= 2; arr.resize(2*size); opt.resize(2*size); } void apply(int x, operation & o) { arr[x] += o.addopt; arr[x] = max(arr[x], o.maxopt); } void push(int x) { apply(x, opt[x]); if (x < size) { opt[2 * x].maxopt = max(opt[2 * x].maxopt, opt[x].maxopt); opt[2*x+1].maxopt = max(opt[2*x+1].maxopt, opt[x].maxopt); opt[2 * x].addopt += opt[x].addopt; opt[2*x+1].addopt += opt[x].addopt; } opt[x].addopt = 0; opt[x].maxopt = -inf; } data combine(data ld, data rd) { return max(ld, rd); } void apply(int l, int r, operation o, int x, int lx, int rx) { // add or max push(x); if (l <= lx && rx <= r) { opt[x] = o; return; } if (rx <= l || r <= lx) { return; } int m = ( lx + rx ) / 2; apply(l, r, o, 2 * x, lx, m); apply(l, r, o, 2*x+1, m, rx); push(2*x), push(2*x+1); arr[x] = combine(arr[2 * x], arr[2*x+1]); } void apply(ll l, ll r, operation o) { apply(l, r, o, 1, 0, size); } data query(int l, int r, int x, int lx, int rx) { push(x); if (l <= lx && rx <= r) { return arr[x]; } if (rx <= l || r <= lx) { return -inf; } int m = ( lx + rx ) / 2; data lv = query(l, r, 2 * x, lx, m); data rv = query(l, r, 2*x+1, m, rx); return combine(lv, rv); } data query(int l, int r){ return query(l, r, 1, 0, size); } }; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> N[0] >> N[1]; for (int j = 0; j < 2; ++j) { for (int i = 0; i < N[j]; ++i) cin >> A[j][i] >> T[j][i] >> P[j][i]; partial_sum(A[j], A[j]+N[j], A[j]); // A ist eine Präfixsumme for(int i = 0; i < N[j]; ++i) T[j][i] -= A[j][i]; // Wie viel darf ich vom anderen machen, ich keine Punkte bekomme? } // Segmentbaum auf N[1] aufgebaut segtree seg = segtree(N[1]+1); // Index shift bei j um 1! // init 0th layer: ll points = 0; priority_queue<pii, vpii, greater<pii>> q; for (int j = 0; j < N[1]; ++j) { if (T[1][j] >= 0) { points += P[1][j]; q.push({ T[1][j], j }); } } seg.apply(0, N[1]+1, { points, -inf }); // ernst for (int i = 0; i < N[0]; ++i) { vi cuts; while (!q.empty() && q.top().first < A[0][i]) { int j = q.top().second; q.pop(); seg.apply(0, j+1, { - P[1][j], -inf }); cuts.push_back(j+1); // for (int i = 0; i <= N[1]; ++i) cout << seg.query(i, i+1) << " "; cout << endl; } if (T[0][i] >= 0) { ll r = upper_bound(A[1], A[1] + N[1], T[0][i]) - A[1]; seg.apply(0, r+1, { P[0][i], -inf }); cuts.push_back(r+1); // for (int i = 0; i <= N[1]; ++i) cout << seg.query(i, i+1) << " "; cout << endl; } for (int x : cuts) { data v = seg.query(0, x); seg.apply(x, N[1]+1, { 0, v }); } } cout << seg.query(0, N[1]+1) << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...