This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define DEBUG 0
#include <bits/stdc++.h>
using namespace std;
#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}
// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
public:
template<typename T>
_Debug& operator,(T val) {
cout << val << endl;
return *this;
}
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif
// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back
// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;
// ---------- END OF TEMPLATE ----------
LLI A[1000001],S[1000001],P[1000001];
LLI B[1000001],T[1000001],Q[1000001];
LLI tree[1 << 21],lazy[1 << 21];
int prop(int s,int e,int i) {
tree[i] += lazy[i];
if (s != e) lazy[2*i+1] += lazy[i],lazy[2*i+2] += lazy[i];
lazy[i] = 0;
return 0;
}
LLI update(int s,int e,int as,int ae,int i,LLI num) {
prop(s,e,i);
if ((s > ae) || (e < as)) return tree[i];
else if ((s >= as) && (e <= ae)) {
lazy[i] += num;
prop(s,e,i);
return tree[i];
}
int mid = (s+e) / 2;
tree[i] = max(update(s,mid,as,ae,2*i+1,num),update(mid+1,e,as,ae,2*i+2,num));
return tree[i];
}
LLI update2(int s,int e,int ai,int i,LLI num) {
prop(s,e,i);
if ((s > ai) || (e < ai)) return tree[i];
else if (s == e) {
tree[i] = num;
return tree[i];
}
int mid = (s+e) / 2;
tree[i] = max(update2(s,mid,ai,2*i+1,num),update2(mid+1,e,ai,2*i+2,num));
return tree[i];
}
LLI query(int s,int e,int qs,int qe,int i) {
prop(s,e,i);
if ((s > qe) || (e < qs)) return -1e18;
else if ((s >= qs) && (e <= qe)) return tree[i];
int mid = (s+e) / 2;
return max(query(s,mid,qs,qe,2*i+1),query(mid+1,e,qs,qe,2*i+2));
}
struct event { int i,j,x; };
bool comp(event a,event b) {
if (a.i == b.i) {
if (a.j == b.j) return a.x < b.x;
else return a.j > b.j;
}
else return a.i < b.i;
}
event events[2000000];
int main() {
int i;
int N,M;
scanf("%d %d",&N,&M);
for (i = 1; i <= N; i++) scanf("%lld %lld %lld",&A[i],&S[i],&P[i]),A[i] += A[i-1];
for (i = 1; i <= M; i++) scanf("%lld %lld %lld",&B[i],&T[i],&Q[i]),B[i] += B[i-1];
LLI ans = 0;
for (i = 1; i <= N; i++) {
int p = upper_bound(B,B+M+1,S[i]-A[i])-B-1;
events[i-1] = {i,p,P[i]};
}
for (i = 1; i <= M; i++) {
int p = upper_bound(A,A+N+1,T[i]-B[i])-A-1;
if (p >= 0) ans += Q[i];
events[i+N-1] = {p+1,i-1,-Q[i]};
}
sort(events,events+N+M,comp);
for (i = 0; i < N+M; i++) {
if ((events[i].i > N) || (events[i].i == 0) || (events[i].j < 0)) continue;
LLI m = query(0,M,0,events[i].j+1,0);
update2(0,M,events[i].j+1,0,m),update(0,M,0,events[i].j,0,events[i].x);
}
ans += query(0,M,0,M,0);
printf("%lld\n",ans);
return 0;
}
Compilation message (stderr)
dishes.cpp: In function 'int main()':
dishes.cpp:119:31: warning: narrowing conversion of 'P[i]' from 'LLI {aka long long int}' to 'int' inside { } [-Wnarrowing]
events[i-1] = {i,p,P[i]};
~~~^
dishes.cpp:124:34: warning: narrowing conversion of '- Q[i]' from 'LLI {aka long long int}' to 'int' inside { } [-Wnarrowing]
events[i+N-1] = {p+1,i-1,-Q[i]};
^~~~~
dishes.cpp:112:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&N,&M);
~~~~~^~~~~~~~~~~~~~~
dishes.cpp:113:71: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for (i = 1; i <= N; i++) scanf("%lld %lld %lld",&A[i],&S[i],&P[i]),A[i] += A[i-1];
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
dishes.cpp:114:71: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for (i = 1; i <= M; i++) scanf("%lld %lld %lld",&B[i],&T[i],&Q[i]),B[i] += B[i-1];
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |