Submission #970379

# Submission time Handle Problem Language Result Execution time Memory
970379 2024-04-26T13:09:13 Z Beerus13 Pinball (JOI14_pinball) C++14
100 / 100
204 ms 28360 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(v) v.begin(), v.end()
const int N = 3e5 + 5;

int n, m;
int a[N], b[N], c[N], d[N];
vector<int> num;
ll st[2][N << 2];

void update(int u, ll val, int t) {
    int id = 1, l = 1, r = n;
    while(l < r) {
        int mid = l + r >> 1;
        if(u > mid) id = id << 1 | 1, l = mid + 1;
        else id = id << 1, r = mid;
    }
    st[t][id] = min(st[t][id], val);
    while(id > 1) id = id >> 1, st[t][id] = min(st[t][id << 1], st[t][id << 1 | 1]);
}

ll get(int u, int v, int t, int id = 1, int l = 1, int r = n) {
    if(u > r || v < l) return 1e18;
    if(u <= l && r <= v) return st[t][id];
    int mid = l + r >> 1;
    ll tmp1 = get(u, v, t, id << 1, l, mid);
    ll tmp2 = get(u, v, t, id << 1 | 1, mid + 1, r);
    return min(tmp1, tmp2);
}

void solve() {
    cin >> m >> n;
    num.push_back(1);
    num.push_back(n);
    for(int i = 1; i <= m; ++i) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        num.push_back(a[i]);
        num.push_back(b[i]);
        num.push_back(c[i]);
    }
    sort(all(num));
    num.resize(unique(all(num)) - num.begin());
    n = lower_bound(all(num), n) - num.begin() + 1;
    ll ans = 1e18;

    memset(st, 0x3f, sizeof(st));
    for(int i = 1; i <= m; ++i) {
        a[i] = lower_bound(all(num), a[i]) - num.begin() + 1;
        b[i] = lower_bound(all(num), b[i]) - num.begin() + 1;
        c[i] = lower_bound(all(num), c[i]) - num.begin() + 1;
        ll lcost = 0, rcost = 0;
        if(a[i] != 1) lcost = get(a[i], b[i], 0);
        if(b[i] != n) rcost = get(a[i], b[i], 1);
        ans = min(ans, lcost + rcost + d[i]);
        update(c[i], lcost + d[i], 0);
        update(c[i], rcost + d[i], 1);
    }
    cout << (ans == 1e18 ? -1 : ans) << '\n';
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int test = 1;
    // cin >> test;
    while(test--) solve();
    return 0;
}

Compilation message

pinball.cpp: In function 'void update(int, long long int, int)':
pinball.cpp:15:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   15 |         int mid = l + r >> 1;
      |                   ~~^~~
pinball.cpp: In function 'long long int get(int, int, int, int, int, int)':
pinball.cpp:26:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   26 |     int mid = l + r >> 1;
      |               ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 23184 KB Output is correct
2 Correct 4 ms 23128 KB Output is correct
3 Correct 3 ms 23132 KB Output is correct
4 Correct 3 ms 23132 KB Output is correct
5 Correct 3 ms 23128 KB Output is correct
6 Correct 4 ms 23132 KB Output is correct
7 Correct 3 ms 23132 KB Output is correct
8 Correct 4 ms 23180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 23184 KB Output is correct
2 Correct 4 ms 23128 KB Output is correct
3 Correct 3 ms 23132 KB Output is correct
4 Correct 3 ms 23132 KB Output is correct
5 Correct 3 ms 23128 KB Output is correct
6 Correct 4 ms 23132 KB Output is correct
7 Correct 3 ms 23132 KB Output is correct
8 Correct 4 ms 23180 KB Output is correct
9 Correct 4 ms 23132 KB Output is correct
10 Correct 3 ms 23224 KB Output is correct
11 Correct 3 ms 23132 KB Output is correct
12 Correct 4 ms 23208 KB Output is correct
13 Correct 5 ms 23132 KB Output is correct
14 Correct 4 ms 23228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 23184 KB Output is correct
2 Correct 4 ms 23128 KB Output is correct
3 Correct 3 ms 23132 KB Output is correct
4 Correct 3 ms 23132 KB Output is correct
5 Correct 3 ms 23128 KB Output is correct
6 Correct 4 ms 23132 KB Output is correct
7 Correct 3 ms 23132 KB Output is correct
8 Correct 4 ms 23180 KB Output is correct
9 Correct 4 ms 23132 KB Output is correct
10 Correct 3 ms 23224 KB Output is correct
11 Correct 3 ms 23132 KB Output is correct
12 Correct 4 ms 23208 KB Output is correct
13 Correct 5 ms 23132 KB Output is correct
14 Correct 4 ms 23228 KB Output is correct
15 Correct 3 ms 23132 KB Output is correct
16 Correct 4 ms 23220 KB Output is correct
17 Correct 5 ms 23132 KB Output is correct
18 Correct 4 ms 23132 KB Output is correct
19 Correct 5 ms 23128 KB Output is correct
20 Correct 4 ms 23132 KB Output is correct
21 Correct 4 ms 23132 KB Output is correct
22 Correct 4 ms 23132 KB Output is correct
23 Correct 4 ms 23132 KB Output is correct
24 Correct 6 ms 23132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 23184 KB Output is correct
2 Correct 4 ms 23128 KB Output is correct
3 Correct 3 ms 23132 KB Output is correct
4 Correct 3 ms 23132 KB Output is correct
5 Correct 3 ms 23128 KB Output is correct
6 Correct 4 ms 23132 KB Output is correct
7 Correct 3 ms 23132 KB Output is correct
8 Correct 4 ms 23180 KB Output is correct
9 Correct 4 ms 23132 KB Output is correct
10 Correct 3 ms 23224 KB Output is correct
11 Correct 3 ms 23132 KB Output is correct
12 Correct 4 ms 23208 KB Output is correct
13 Correct 5 ms 23132 KB Output is correct
14 Correct 4 ms 23228 KB Output is correct
15 Correct 3 ms 23132 KB Output is correct
16 Correct 4 ms 23220 KB Output is correct
17 Correct 5 ms 23132 KB Output is correct
18 Correct 4 ms 23132 KB Output is correct
19 Correct 5 ms 23128 KB Output is correct
20 Correct 4 ms 23132 KB Output is correct
21 Correct 4 ms 23132 KB Output is correct
22 Correct 4 ms 23132 KB Output is correct
23 Correct 4 ms 23132 KB Output is correct
24 Correct 6 ms 23132 KB Output is correct
25 Correct 18 ms 23644 KB Output is correct
26 Correct 42 ms 24284 KB Output is correct
27 Correct 117 ms 26616 KB Output is correct
28 Correct 125 ms 28084 KB Output is correct
29 Correct 85 ms 25672 KB Output is correct
30 Correct 142 ms 28360 KB Output is correct
31 Correct 184 ms 28192 KB Output is correct
32 Correct 204 ms 28204 KB Output is correct
33 Correct 25 ms 24032 KB Output is correct
34 Correct 93 ms 25836 KB Output is correct
35 Correct 149 ms 28360 KB Output is correct
36 Correct 194 ms 28360 KB Output is correct
37 Correct 176 ms 28360 KB Output is correct
38 Correct 161 ms 28356 KB Output is correct