Submission #105120

#TimeUsernameProblemLanguageResultExecution timeMemory
105120realityTwo Dishes (JOI19_dishes)C++17
100 / 100
8266 ms212512 KiB
#include "bits/stdc++.h" using namespace std; #define fi first #define se second #define ll long long #define dbg(v) cerr<<#v<<" = "<<v<<'\n' #define vi vector<int> #define vl vector <ll> #define pii pair<int,int> #define vii vector < pii > #define mp make_pair #define db long double #define pb push_back #define all(s) s.begin(),s.end() template < class P , class Q > ostream& operator<<(ostream& stream, pair < P , Q > v){ stream << "(" << v.fi << ',' << v.se << ")"; return stream;} template < class T > ostream& operator<<(ostream& stream, const vector<T> v){ stream << "[ "; for (int i=0; i<(int)v.size(); i++) stream << v[i] << " "; stream << "]"; return stream;} template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;} template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;} const int N = 1e6 + 5; ll A[N],C[N],D[N]; ll B[N],E[N],F[N]; map < pii , ll > M; ll T[N * 4]; ll Lz[N * 4]; void llz(int l,int r,int node) { T[node] += Lz[node]; if (l != r) { Lz[node * 2] += Lz[node]; Lz[node * 2 + 1] += Lz[node]; } Lz[node] = 0; } void update(int l,int r,int pos,ll val,int node) { llz(l,r,node); if (l == r) T[node] = val; else { int m = (l + r) / 2; if (pos <= m) update(l,m,pos,val,node * 2),llz(m+1,r,node * 2 + 1); else update(m+1,r,pos,val,node * 2 + 1),llz(l,m,node * 2); T[node] = max(T[node * 2],T[node * 2 + 1]); } } void Add(int l,int r,int l1,int r1,ll Val,int node) { llz(l,r,node); if (l1 <= l && r <= r1) { Lz[node] += Val; llz(l,r,node); } else { int m = (l + r) / 2; if (l1 <= m) Add(l,m,l1,r1,Val,node * 2); else llz(l,m,node * 2); if (m+1<=r1) Add(m+1,r,l1,r1,Val,node * 2 + 1); else llz(m+1,r,node * 2 + 1); T[node] = max(T[node * 2],T[node * 2 + 1]); } } ll query(int l,int r,int l1,int r1,int node) { llz(l,r,node); if (l1 <= l && r <= r1) return T[node]; int m = (l + r) / 2; ll ans = -1e18; if (l1 <= m) smax(ans,query(l,m,l1,r1,node * 2)); if (m+1<=r1) smax(ans,query(m+1,r,l1,r1,node * 2 + 1)); return ans; } char c; ll Get(void) { while (c != '-' && !('0' <= c && c <= '9')) c = getchar(); int sign = c == '-' ? -1 : 1; ll ans = 0; if (c == '-') c = getchar(); while ('0' <= c && c <= '9') ans = ans * 10 + c - '0',c = getchar(); return ans * sign; } int main(void) { int n,m; c = getchar(); n = Get(); m = Get(); for (int i = 1;i <= n;++i) A[i] = Get(),C[i] = Get(),D[i] = Get(),A[i] += A[i - 1]; for (int i = 1;i <= m;++i) B[i] = Get(),E[i] = Get(),F[i] = Get(),B[i] += B[i - 1]; ll bst = 0; for (int i = 1;i <= n;++i) { if (A[i] > C[i]) { continue; } if (A[i] + B[m] <= C[i]) { bst += D[i]; continue; } int Index = lower_bound(B + 1,B + 1 + m,C[i] - A[i] + 1) - B; --Index; M[mp(i - 1,- 1 - Index)] += D[i]; } for (int i = 1;i <= m;++i) { if (B[i] > E[i]) { continue; } if (A[n] + B[i] <= E[i]) { bst += F[i]; continue; } int Index = lower_bound(A + 1,A + 1 + n,E[i] - B[i] + 1) - A; --Index; M[mp(Index,-i)] -= F[i]; bst += F[i]; } for (auto It : M) { const int Pos = -It.fi.se; update(0,m + 1,Pos,query(0,m + 1,0,Pos,1),1); Add(0,m + 1,0,Pos - 1,It.se,1); } cout << query(0,m + 1,0,m + 1,1) + bst << '\n'; return 0; }
#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...