답안 #463729

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
463729 2021-08-11T16:06:11 Z Nima_Naderi Pinball (JOI14_pinball) C++14
100 / 100
209 ms 19164 KB
///In the name of GOD
//#pragma GCC optimize("O2")
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef tuple<ll, ll, ll, ll> tpl;
const ll MXN = 2e5 + 10;
const ll MXS = MXN * 4;
const ll INF = 1e18;
ll n, m, k, ans;
ll A[MXN], B[MXN], C[MXN], D[MXN];
vector<ll> Num;
inline int GetId(ll x){
    return lower_bound(Num.begin(), Num.end(), x) - Num.begin() + 1;
}
struct Segtree {
    ll seg[MXS], lim;//lim as size
    void init(){
        lim = k + 1;
        for(int i = lim << 1; -- i; ) seg[i] = INF;
    }
    void Upd(ll p, ll x){
        p += lim;
        while(p) seg[p] = min(seg[p], x), p >>= 1;
    }
    ll Get(ll l, ll r){
        ll res = INF; l += lim, r += lim;
        while(l <= r){
            if((l & 1) == 1) res = min(res, seg[l]), l ++;
            if((r & 1) == 0) res = min(res, seg[r]), r --;
            l >>= 1, r >>= 1;
        }
        return res;
    }
} SL, SR;
int main(){
    ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
    cin >> n >> m, ans = INF;
    for(int i = 1; i <= n; 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]);
    }
    Num.push_back(1), Num.push_back(m);
    sort(Num.begin(), Num.end());
    Num.resize(k = unique(Num.begin(), Num.end()) - Num.begin());
    SL.init(), SR.init();
    SL.Upd(1, 0), SR.Upd(k, 0);
    for(int i = 1; i <= n; i ++){
        A[i] = GetId(A[i]), B[i] = GetId(B[i]), C[i] = GetId(C[i]);
        ll cl = SL.Get(A[i], B[i]), cr = SR.Get(A[i], B[i]);
        ans = min(ans, cl + cr + D[i]);
        cl += D[i], cr += D[i];
        SL.Upd(C[i], cl), SR.Upd(C[i], cr);
    }
    cout << (ans == INF ? -1 : ans) << '\n';
    return 0;
}
/*!
    HE'S AN INSTIGATOR,
    ENEMY ELIMINATOR,
    AND WHEN HE KNOCKS YOU BETTER
    YOU BETTER LET HIM IN.
*/
//! N.N
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 328 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 328 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 328 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 2 ms 460 KB Output is correct
18 Correct 2 ms 460 KB Output is correct
19 Correct 3 ms 540 KB Output is correct
20 Correct 2 ms 460 KB Output is correct
21 Correct 1 ms 460 KB Output is correct
22 Correct 2 ms 588 KB Output is correct
23 Correct 2 ms 588 KB Output is correct
24 Correct 2 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 328 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 2 ms 460 KB Output is correct
18 Correct 2 ms 460 KB Output is correct
19 Correct 3 ms 540 KB Output is correct
20 Correct 2 ms 460 KB Output is correct
21 Correct 1 ms 460 KB Output is correct
22 Correct 2 ms 588 KB Output is correct
23 Correct 2 ms 588 KB Output is correct
24 Correct 2 ms 588 KB Output is correct
25 Correct 14 ms 1872 KB Output is correct
26 Correct 43 ms 4452 KB Output is correct
27 Correct 120 ms 9916 KB Output is correct
28 Correct 114 ms 10852 KB Output is correct
29 Correct 84 ms 7968 KB Output is correct
30 Correct 145 ms 10788 KB Output is correct
31 Correct 186 ms 15000 KB Output is correct
32 Correct 173 ms 13552 KB Output is correct
33 Correct 23 ms 4044 KB Output is correct
34 Correct 79 ms 9724 KB Output is correct
35 Correct 116 ms 19136 KB Output is correct
36 Correct 209 ms 19116 KB Output is correct
37 Correct 163 ms 19116 KB Output is correct
38 Correct 157 ms 19164 KB Output is correct