Submission #380495

# Submission time Handle Problem Language Result Execution time Memory
380495 2021-03-22T04:53:41 Z pure_mem Pinball (JOI14_pinball) C++14
100 / 100
670 ms 172524 KB
#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
1 Correct 1 ms 512 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 2 ms 620 KB Output is correct
12 Correct 2 ms 884 KB Output is correct
13 Correct 2 ms 876 KB Output is correct
14 Correct 2 ms 876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 2 ms 620 KB Output is correct
12 Correct 2 ms 884 KB Output is correct
13 Correct 2 ms 876 KB Output is correct
14 Correct 2 ms 876 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 2 ms 748 KB Output is correct
17 Correct 5 ms 1920 KB Output is correct
18 Correct 3 ms 492 KB Output is correct
19 Correct 6 ms 2668 KB Output is correct
20 Correct 5 ms 1664 KB Output is correct
21 Correct 2 ms 1004 KB Output is correct
22 Correct 6 ms 2540 KB Output is correct
23 Correct 6 ms 2924 KB Output is correct
24 Correct 6 ms 2796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 2 ms 620 KB Output is correct
12 Correct 2 ms 884 KB Output is correct
13 Correct 2 ms 876 KB Output is correct
14 Correct 2 ms 876 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 2 ms 748 KB Output is correct
17 Correct 5 ms 1920 KB Output is correct
18 Correct 3 ms 492 KB Output is correct
19 Correct 6 ms 2668 KB Output is correct
20 Correct 5 ms 1664 KB Output is correct
21 Correct 2 ms 1004 KB Output is correct
22 Correct 6 ms 2540 KB Output is correct
23 Correct 6 ms 2924 KB Output is correct
24 Correct 6 ms 2796 KB Output is correct
25 Correct 32 ms 7020 KB Output is correct
26 Correct 129 ms 29336 KB Output is correct
27 Correct 410 ms 65004 KB Output is correct
28 Correct 324 ms 5868 KB Output is correct
29 Correct 291 ms 66028 KB Output is correct
30 Correct 531 ms 23432 KB Output is correct
31 Correct 666 ms 125688 KB Output is correct
32 Correct 622 ms 102508 KB Output is correct
33 Correct 71 ms 23532 KB Output is correct
34 Correct 343 ms 83436 KB Output is correct
35 Correct 471 ms 172524 KB Output is correct
36 Correct 670 ms 167060 KB Output is correct
37 Correct 629 ms 167160 KB Output is correct
38 Correct 563 ms 167148 KB Output is correct