Submission #236013

# Submission time Handle Problem Language Result Execution time Memory
236013 2020-05-30T20:40:33 Z DS007 Pinball (JOI14_pinball) C++14
100 / 100
455 ms 97696 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define inf 1e17

const int N = 3e5, M = 1e5;
int m, n, a[M], b[M], c[M], d[M], ans = 1e17;

struct node {
    int val;
    node *left, *right;

    node() {
        val = inf;
        left = nullptr;
        right = nullptr;
    }
};

class SegmentTree {
public:
    node *root = new node();

    int query(node *cur, int l, int r, int tl, int tr) {
        if (cur == nullptr || tl > tr)
            return inf;
        else if (l == tl && r == tr)
            return cur->val;
        int mid = (l + r) / 2;
        return min(query(cur->left, l, mid, tl, min(mid, tr)), query(cur->right, mid + 1, r, max(mid + 1, tl), tr));
    }

    void update(node *cur, int l, int r, int tl, int nv) {
        if (l == r) {
            assert(l == tl);
            cur->val = min(cur->val, nv);
            return;
        }

        int mid = (l + r) / 2;
        if (tl <= mid) {
            if (cur->left == nullptr)
                cur->left = new node();
            update(cur->left, l, mid, tl, nv);
        } else {
            if (cur->right == nullptr)
                cur->right = new node();
            update(cur->right, mid + 1, r, tl, nv);
        }
        cur->val = min(query(cur->left, l, mid, l, mid), query(cur->right, mid + 1, r, mid + 1, r));
    }
} t1, t2;

int solveTestCase(int test) {
    cin >> m >> n;
    for (int i = 0; i < m; i++) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        int lc = a[i] == 1 ? 0 : t1.query(t1.root, 0, 1e9, a[i], b[i]);
        int rc = b[i] == n ? 0 : t2.query(t2.root, 0, 1e9, a[i], b[i]);
        ans = min(ans, lc + rc + d[i]);

        t1.update(t1.root, 0, 1e9, c[i], lc + d[i]);
        t2.update(t2.root, 0, 1e9, c[i], rc + d[i]);
    }

    cout << (ans >= inf ? -1 : ans);
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int test = 1;
    //cin >> test;
    for (int i = 1; i <= test; i++)
        solveTestCase(i);
}

Compilation message

pinball.cpp: In function 'long long int solveTestCase(long long int)':
pinball.cpp:67:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 512 KB Output is correct
11 Correct 5 ms 512 KB Output is correct
12 Correct 5 ms 640 KB Output is correct
13 Correct 5 ms 640 KB Output is correct
14 Correct 5 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 512 KB Output is correct
11 Correct 5 ms 512 KB Output is correct
12 Correct 5 ms 640 KB Output is correct
13 Correct 5 ms 640 KB Output is correct
14 Correct 5 ms 640 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 640 KB Output is correct
17 Correct 9 ms 1280 KB Output is correct
18 Correct 7 ms 512 KB Output is correct
19 Correct 8 ms 1664 KB Output is correct
20 Correct 8 ms 1152 KB Output is correct
21 Correct 6 ms 768 KB Output is correct
22 Correct 8 ms 1536 KB Output is correct
23 Correct 8 ms 1792 KB Output is correct
24 Correct 8 ms 1664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 512 KB Output is correct
11 Correct 5 ms 512 KB Output is correct
12 Correct 5 ms 640 KB Output is correct
13 Correct 5 ms 640 KB Output is correct
14 Correct 5 ms 640 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 640 KB Output is correct
17 Correct 9 ms 1280 KB Output is correct
18 Correct 7 ms 512 KB Output is correct
19 Correct 8 ms 1664 KB Output is correct
20 Correct 8 ms 1152 KB Output is correct
21 Correct 6 ms 768 KB Output is correct
22 Correct 8 ms 1536 KB Output is correct
23 Correct 8 ms 1792 KB Output is correct
24 Correct 8 ms 1664 KB Output is correct
25 Correct 29 ms 4608 KB Output is correct
26 Correct 119 ms 17436 KB Output is correct
27 Correct 297 ms 38804 KB Output is correct
28 Correct 257 ms 8184 KB Output is correct
29 Correct 201 ms 38008 KB Output is correct
30 Correct 336 ms 17400 KB Output is correct
31 Correct 450 ms 72552 KB Output is correct
32 Correct 432 ms 59896 KB Output is correct
33 Correct 57 ms 14204 KB Output is correct
34 Correct 195 ms 47644 KB Output is correct
35 Correct 297 ms 97696 KB Output is correct
36 Correct 455 ms 95308 KB Output is correct
37 Correct 389 ms 95056 KB Output is correct
38 Correct 374 ms 95120 KB Output is correct