Submission #484609

# Submission time Handle Problem Language Result Execution time Memory
484609 2021-11-04T18:12:27 Z Alexandruabcde Pinball (JOI14_pinball) C++14
0 / 100
1 ms 332 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

constexpr int NMAX = 1e5 + 5;
constexpr int VALMAX = 3 * NMAX + 5;
constexpr LL INF = 100000000000000000;

int N, M;

int A[NMAX], B[NMAX], C[NMAX];
LL cost[NMAX];

LL AINT[4*VALMAX];

int vf = 0;
LL BestLeft[VALMAX];
LL BestRight[VALMAX];

void Read () {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> N >> M;

    for (int i = 1; i <= N; ++ i )
        cin >> A[i] >> B[i] >> C[i] >> cost[i];
}

map <int, int> mp;

void Normalize () {
    for (int i = 1; i <= N; ++ i ) {
        mp[A[i]] = 1;
        mp[B[i]] = 1;
        mp[C[i]] = 1;
    }
    mp[1] = mp[M] = 1;

    vf = 0;

    for (auto &it : mp)
        it.second = ++vf;

    for (int i = 1; i <= N; ++ i ) {
        A[i] = mp[A[i]];
        B[i] = mp[B[i]];
        C[i] = mp[C[i]];
    }
}

void ResetTree () {
    for (int i = 1; i <= 4 * vf; ++ i )
        AINT[i] = INF;
}

void Update (int nod, int a, int b, int poz, LL val) {
    if (a == b) {
        AINT[nod] = val;

        return;
    }

    int mij = (a + b) / 2;

    if (poz <= mij) Update(2*nod, a, mij, poz, val);
    else Update(2*nod+1, mij+1, b, poz, val);

    AINT[nod] = min(AINT[2*nod], AINT[2*nod+1]);
}

LL Query (int nod, int a, int b, int qa, int qb) {
    if (qa <= a && b <= qb) return AINT[nod];

    int mij = (a + b) / 2;
    LL ans_left = INF, ans_right = INF;

    if (qa <= mij) ans_left = Query(2*nod, a, mij, qa, qb);
    if (mij < qb) ans_right = Query(2*nod+1, mij+1, b, qa, qb);

    return min(ans_left, ans_right);
}

void Solve_Left () {
    ResetTree();

    Update(1, 1, vf, mp[1], 0);

    for (int i = 1; i <= N; ++ i ) {
        BestLeft[i] = Query(1, 1, vf, A[i], B[i]);
        Update(1, 1, vf, C[i], cost[i] + BestLeft[i]);
    }
}

void Solve_Right () {
    ResetTree();

    Update(1, 1, vf, mp[M], 0);

    for (int i = 1; i <= N; ++ i ) {
        BestRight[i] = Query(1, 1, vf, A[i], B[i]);
        Update(1, 1, vf, C[i], cost[i] + BestRight[i]);
    }
}

void Solve () {
    Solve_Left();
    Solve_Right();

    LL ans = INF;
    for (int i = 1; i <= N; ++ i )
        ans = min(ans, BestLeft[i] + BestRight[i] + cost[i]);

    cout << (ans == INF ? -1 : ans) << '\n';
}

int main()
{
    Read();
    Normalize();
    Solve();

    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -