This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<stdio.h>
#include<algorithm>
using namespace std;
typedef long long ll;
int n, m;
struct st {
ll mini[2] = { (ll)1e18,(ll)1e18 };
st *left=NULL, *right=NULL;
}tree;
void update(st *h, int l, int r, int g,ll x, int type) {
if (r < g || g < l) return;
h->mini[type] = min(h->mini[type], x);
if (l != r) {
if (!h->left) h->left = new st;
if (!h->right) h->right = new st;
update(h->left, l, (l + r) / 2, g, x, type);
update(h->right, (l + r) / 2+1,r, g, x, type);
}
}
ll query(st *h, int l, int r, int gl, int gr, int type) {
if (r < gl || gr < l) return 1e18;
if (gl <= l && r <= gr) return h->mini[type];
if (!h->left) h->left = new st;
if (!h->right) h->right = new st;
return min(query(h->left, l, (l + r) / 2, gl, gr, type),
query(h->right, (l + r) / 2 + 1, r, gl, gr, type));
}
int main() {
scanf("%d %d", &m, &n);
st *rt = new st;
update(rt, 1, n, 1, 0, 0);
update(rt, 1, n, n, 0, 1);
ll res = 1e18;
for (int i = 0; i < m; i++) {
int a, b, c, d;
scanf("%d %d %d %d", &a, &b, &c, &d);
ll ql = query(rt, 1, n, a, b, 0), qr = query(rt, 1, n, a, b, 1);
res = min(res, ql+qr+d);
update(rt, 1, n, c, ql+d, 0);
update(rt, 1, n, c, qr+d, 1);
}
printf("%lld", res==1e18?-1:res);
return 0;
}
Compilation message (stderr)
pinball.cpp: In function 'int main()':
pinball.cpp:33:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &m, &n);
~~~~~^~~~~~~~~~~~~~~~~
pinball.cpp:40:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d %d", &a, &b, &c, &d);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |