Submission #856982

# Submission time Handle Problem Language Result Execution time Memory
856982 2023-10-05T03:15:14 Z thanh913 Pinball (JOI14_pinball) C++14
100 / 100
179 ms 31644 KB
#include <bits/stdc++.h>
using namespace std;
 
#define fi first
#define se second
#define ll long long
#define int long long
 
const int N = 1e5+5;
 
struct interval {
    int l, r, pos, cost;
};
 
//-------------------------------
interval a[N];
int n, len;
 
vector<int> vals;
 
struct SegmentTree {
    ll seg[N*12];
    SegmentTree() {
        memset(seg, 0x3f, sizeof(seg));
    }
 
    void update(int pos, ll val, int l = 0, int r = vals.size() - 1, int id = 1) {
        if (l > pos || r < pos) return;
        if (l == r) {
            seg[id] = min(seg[id], val);
            return;
        }
        int mid = (l+r) / 2;
        update(pos, val, l, mid, id*2);
        update(pos, val, mid+1, r, id*2 + 1);
        seg[id] = min(seg[id*2], seg[id*2 + 1]);
    }
 
    ll get(int u, int v, int l = 0, int r = vals.size() - 1, int id = 1) {
        if (l > v || r < u) return 4e18;
        if (l >= u && r <= v) return seg[id];
        int mid = (l+r) / 2;
        return min(get(u, v, l, mid, id*2),
                   get(u, v, mid+1, r, id*2 + 1));
    }
} lTree, rTree;
 
int idx(int val) {
    return lower_bound(vals.begin(), vals.end(), val) - vals.begin();
};
 
signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    cin >> n >> len;
    for (int i = 1; i <= n; i++) {
        cin >> a[i].l >> a[i].r >> a[i].pos >> a[i].cost;
        vals.push_back(a[i].l);
        vals.push_back(a[i].r);
      	vals.push_back(a[i].pos);
    }
    vals.push_back(1); vals.push_back(len);
    sort(vals.begin(), vals.end());
    vals.erase(unique(vals.begin(), vals.end()), vals.end());
    for (int i = 1; i <= n; i++) {
        a[i].l = idx(a[i].l); a[i].r = idx(a[i].r); a[i].pos = idx(a[i].pos);
    }
 
    ll ans = 4e18;
    lTree.update(idx(1), 0); rTree.update(idx(len), 0);
    for (int i = 1; i <= n; i++) {
        ll v1 = lTree.get(a[i].l, a[i].r) + a[i].cost;
        ll v2 = rTree.get(a[i].l, a[i].r) + a[i].cost;
        ans = min(ans, v1+v2 - a[i].cost);
        lTree.update(a[i].pos, v1);
        rTree.update(a[i].pos, v2);
    }
    cout << (ans > 1e18 ? -1 : ans);
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 21080 KB Output is correct
2 Correct 3 ms 21084 KB Output is correct
3 Correct 3 ms 21084 KB Output is correct
4 Correct 3 ms 21084 KB Output is correct
5 Correct 3 ms 21084 KB Output is correct
6 Correct 3 ms 21084 KB Output is correct
7 Correct 3 ms 21084 KB Output is correct
8 Correct 3 ms 21084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 21080 KB Output is correct
2 Correct 3 ms 21084 KB Output is correct
3 Correct 3 ms 21084 KB Output is correct
4 Correct 3 ms 21084 KB Output is correct
5 Correct 3 ms 21084 KB Output is correct
6 Correct 3 ms 21084 KB Output is correct
7 Correct 3 ms 21084 KB Output is correct
8 Correct 3 ms 21084 KB Output is correct
9 Correct 3 ms 21084 KB Output is correct
10 Correct 3 ms 21084 KB Output is correct
11 Correct 3 ms 21084 KB Output is correct
12 Correct 3 ms 21084 KB Output is correct
13 Correct 3 ms 21084 KB Output is correct
14 Correct 3 ms 21084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 21080 KB Output is correct
2 Correct 3 ms 21084 KB Output is correct
3 Correct 3 ms 21084 KB Output is correct
4 Correct 3 ms 21084 KB Output is correct
5 Correct 3 ms 21084 KB Output is correct
6 Correct 3 ms 21084 KB Output is correct
7 Correct 3 ms 21084 KB Output is correct
8 Correct 3 ms 21084 KB Output is correct
9 Correct 3 ms 21084 KB Output is correct
10 Correct 3 ms 21084 KB Output is correct
11 Correct 3 ms 21084 KB Output is correct
12 Correct 3 ms 21084 KB Output is correct
13 Correct 3 ms 21084 KB Output is correct
14 Correct 3 ms 21084 KB Output is correct
15 Correct 3 ms 21084 KB Output is correct
16 Correct 3 ms 21084 KB Output is correct
17 Correct 4 ms 21084 KB Output is correct
18 Correct 3 ms 21084 KB Output is correct
19 Correct 4 ms 21084 KB Output is correct
20 Correct 4 ms 21084 KB Output is correct
21 Correct 3 ms 21084 KB Output is correct
22 Correct 4 ms 21160 KB Output is correct
23 Correct 4 ms 21084 KB Output is correct
24 Correct 4 ms 21084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 21080 KB Output is correct
2 Correct 3 ms 21084 KB Output is correct
3 Correct 3 ms 21084 KB Output is correct
4 Correct 3 ms 21084 KB Output is correct
5 Correct 3 ms 21084 KB Output is correct
6 Correct 3 ms 21084 KB Output is correct
7 Correct 3 ms 21084 KB Output is correct
8 Correct 3 ms 21084 KB Output is correct
9 Correct 3 ms 21084 KB Output is correct
10 Correct 3 ms 21084 KB Output is correct
11 Correct 3 ms 21084 KB Output is correct
12 Correct 3 ms 21084 KB Output is correct
13 Correct 3 ms 21084 KB Output is correct
14 Correct 3 ms 21084 KB Output is correct
15 Correct 3 ms 21084 KB Output is correct
16 Correct 3 ms 21084 KB Output is correct
17 Correct 4 ms 21084 KB Output is correct
18 Correct 3 ms 21084 KB Output is correct
19 Correct 4 ms 21084 KB Output is correct
20 Correct 4 ms 21084 KB Output is correct
21 Correct 3 ms 21084 KB Output is correct
22 Correct 4 ms 21160 KB Output is correct
23 Correct 4 ms 21084 KB Output is correct
24 Correct 4 ms 21084 KB Output is correct
25 Correct 16 ms 21472 KB Output is correct
26 Correct 41 ms 22236 KB Output is correct
27 Correct 120 ms 23256 KB Output is correct
28 Correct 111 ms 26568 KB Output is correct
29 Correct 84 ms 23272 KB Output is correct
30 Correct 140 ms 26568 KB Output is correct
31 Correct 179 ms 26312 KB Output is correct
32 Correct 165 ms 27348 KB Output is correct
33 Correct 24 ms 21728 KB Output is correct
34 Correct 89 ms 25300 KB Output is correct
35 Correct 123 ms 30568 KB Output is correct
36 Correct 175 ms 30920 KB Output is correct
37 Correct 163 ms 31644 KB Output is correct
38 Correct 147 ms 31180 KB Output is correct