Submission #986916

# Submission time Handle Problem Language Result Execution time Memory
986916 2024-05-21T14:46:53 Z vjudge1 Pinball (JOI14_pinball) C++17
100 / 100
288 ms 28348 KB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
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);
}
int main() {
    int t = 1;
    while(t--){
        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(num.begin(), num.end());
        num.resize(unique(num.begin(), num.end()) - num.begin());
        n = lower_bound(num.begin(), num.end(), n) - num.begin() + 1;
        ll ans = 1e18;

        memset(st, 0x3f, sizeof(st));
        for(int i = 1; i <= m; ++i) {
            a[i] = lower_bound(num.begin(), num.end(), a[i]) - num.begin() + 1;
            b[i] = lower_bound(num.begin(), num.end(), b[i]) - num.begin() + 1;
            c[i] = lower_bound(num.begin(), num.end(), 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';
    }
    return 0;
}

Compilation message

pinball.cpp: In function 'void update(int, ll, int)':
pinball.cpp:12:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   12 |         int mid = l + r >> 1;
      |                   ~~^~~
pinball.cpp: In function 'll get(int, int, int, int, int, int)':
pinball.cpp:22:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   22 |     int mid = l + r >> 1;
      |               ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 23132 KB Output is correct
2 Correct 6 ms 23132 KB Output is correct
3 Correct 5 ms 23048 KB Output is correct
4 Correct 5 ms 23132 KB Output is correct
5 Correct 6 ms 23384 KB Output is correct
6 Correct 5 ms 22976 KB Output is correct
7 Correct 6 ms 23132 KB Output is correct
8 Correct 5 ms 23132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 23132 KB Output is correct
2 Correct 6 ms 23132 KB Output is correct
3 Correct 5 ms 23048 KB Output is correct
4 Correct 5 ms 23132 KB Output is correct
5 Correct 6 ms 23384 KB Output is correct
6 Correct 5 ms 22976 KB Output is correct
7 Correct 6 ms 23132 KB Output is correct
8 Correct 5 ms 23132 KB Output is correct
9 Correct 6 ms 23128 KB Output is correct
10 Correct 5 ms 23132 KB Output is correct
11 Correct 5 ms 22980 KB Output is correct
12 Correct 6 ms 23132 KB Output is correct
13 Correct 6 ms 23132 KB Output is correct
14 Correct 6 ms 23132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 23132 KB Output is correct
2 Correct 6 ms 23132 KB Output is correct
3 Correct 5 ms 23048 KB Output is correct
4 Correct 5 ms 23132 KB Output is correct
5 Correct 6 ms 23384 KB Output is correct
6 Correct 5 ms 22976 KB Output is correct
7 Correct 6 ms 23132 KB Output is correct
8 Correct 5 ms 23132 KB Output is correct
9 Correct 6 ms 23128 KB Output is correct
10 Correct 5 ms 23132 KB Output is correct
11 Correct 5 ms 22980 KB Output is correct
12 Correct 6 ms 23132 KB Output is correct
13 Correct 6 ms 23132 KB Output is correct
14 Correct 6 ms 23132 KB Output is correct
15 Correct 5 ms 23132 KB Output is correct
16 Correct 6 ms 23132 KB Output is correct
17 Correct 7 ms 23132 KB Output is correct
18 Correct 7 ms 23132 KB Output is correct
19 Correct 8 ms 23132 KB Output is correct
20 Correct 8 ms 23132 KB Output is correct
21 Correct 6 ms 23384 KB Output is correct
22 Correct 7 ms 23132 KB Output is correct
23 Correct 9 ms 23128 KB Output is correct
24 Correct 7 ms 23132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 23132 KB Output is correct
2 Correct 6 ms 23132 KB Output is correct
3 Correct 5 ms 23048 KB Output is correct
4 Correct 5 ms 23132 KB Output is correct
5 Correct 6 ms 23384 KB Output is correct
6 Correct 5 ms 22976 KB Output is correct
7 Correct 6 ms 23132 KB Output is correct
8 Correct 5 ms 23132 KB Output is correct
9 Correct 6 ms 23128 KB Output is correct
10 Correct 5 ms 23132 KB Output is correct
11 Correct 5 ms 22980 KB Output is correct
12 Correct 6 ms 23132 KB Output is correct
13 Correct 6 ms 23132 KB Output is correct
14 Correct 6 ms 23132 KB Output is correct
15 Correct 5 ms 23132 KB Output is correct
16 Correct 6 ms 23132 KB Output is correct
17 Correct 7 ms 23132 KB Output is correct
18 Correct 7 ms 23132 KB Output is correct
19 Correct 8 ms 23132 KB Output is correct
20 Correct 8 ms 23132 KB Output is correct
21 Correct 6 ms 23384 KB Output is correct
22 Correct 7 ms 23132 KB Output is correct
23 Correct 9 ms 23128 KB Output is correct
24 Correct 7 ms 23132 KB Output is correct
25 Correct 26 ms 23644 KB Output is correct
26 Correct 63 ms 24280 KB Output is correct
27 Correct 175 ms 26420 KB Output is correct
28 Correct 191 ms 28192 KB Output is correct
29 Correct 138 ms 25796 KB Output is correct
30 Correct 228 ms 28228 KB Output is correct
31 Correct 270 ms 28348 KB Output is correct
32 Correct 270 ms 28144 KB Output is correct
33 Correct 41 ms 24064 KB Output is correct
34 Correct 137 ms 25572 KB Output is correct
35 Correct 218 ms 28156 KB Output is correct
36 Correct 288 ms 28096 KB Output is correct
37 Correct 254 ms 28340 KB Output is correct
38 Correct 247 ms 28140 KB Output is correct