답안 #463731

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
463731 2021-08-11T16:07:11 Z Nima_Naderi Pinball (JOI14_pinball) C++14
100 / 100
211 ms 15316 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 = 3e5 + 10;
const ll MXS = MXN * 2;
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 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 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 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 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 332 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 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 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 332 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 1 ms 332 KB Output is correct
19 Correct 2 ms 460 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 460 KB Output is correct
23 Correct 1 ms 460 KB Output is correct
24 Correct 1 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 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 332 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 1 ms 332 KB Output is correct
19 Correct 2 ms 460 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 460 KB Output is correct
23 Correct 1 ms 460 KB Output is correct
24 Correct 1 ms 460 KB Output is correct
25 Correct 15 ms 1488 KB Output is correct
26 Correct 46 ms 3528 KB Output is correct
27 Correct 125 ms 7428 KB Output is correct
28 Correct 112 ms 7304 KB Output is correct
29 Correct 93 ms 6004 KB Output is correct
30 Correct 140 ms 7232 KB Output is correct
31 Correct 199 ms 11164 KB Output is correct
32 Correct 190 ms 9648 KB Output is correct
33 Correct 22 ms 3404 KB Output is correct
34 Correct 80 ms 7796 KB Output is correct
35 Correct 116 ms 15280 KB Output is correct
36 Correct 211 ms 15316 KB Output is correct
37 Correct 160 ms 15216 KB Output is correct
38 Correct 160 ms 15300 KB Output is correct