이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define X first
#define Y second
#define MP make_pair
#define ll long long
using namespace std;
const int N = 1e5 + 12, M = 1e9;
const ll INF = 1e18;
struct node{
node *l, *r;
ll val = INF;
};
int n, m;
void upd(node *v, int tl, int tr, int pos, ll val){
if(tl > pos || pos > tr)
return;
if(tl == tr){
v->val = min(v->val, val);
return;
}
int tm = (tl + tr) / 2;
if(!v->l)
v->l = new node();
if(!v->r)
v->r = new node();
upd(v->l, tl, tm, pos, val);
upd(v->r, tm + 1, tr, pos, val);
v->val = min(v->l->val, v->r->val);
}
ll get(node *v, int tl, int tr, int l, int r){
if(tl > r || l > tr || !v)
return INF;
if(tl >= l && tr <= r)
return v->val;
int tm = (tl + tr) / 2;
return min(get(v->l, tl, tm, l, r), get(v->r, tm + 1, tr, l, r));
}
int main () {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> m >> n;
ll ans = INF;
node* root1 = new node();
node* root2 = new node();
for(int i = 1;i <= m;i++){
int l, r, c, cost;
cin >> l >> r >> c >> cost;
ll cL = get(root1, 1, n, l, r) + cost;
if(l == 1)
cL = cost;
ll cR = get(root2, 1, n, l, r) + cost;
if(r == n)
cR = cost;
ans = min(ans, cL + cR - cost);
upd(root1, 1, n, c, cL);
upd(root2, 1, n, c, cR);
}
if(ans == INF)
ans = -1;
cout << ans;
}
# | 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... |