답안 #314269

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
314269 2020-10-19T10:03:40 Z Vladth11 Pinball (JOI14_pinball) C++14
100 / 100
759 ms 90668 KB
#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << "\n"
#define debug_with_space(x) cerr << #x << " " << x << " "


using namespace std;
typedef long long ll;
typedef pair <ll, ll> pii;
typedef pair <ll, pii> piii;

const ll NMAX = 100001;
const ll INF = (1LL << 60);
const ll MOD = 1000000007;
const ll BLOCK = 101;
const ll nr_of_bits = 18;

ll n, m;

struct AllDinamic {
    struct Node {
        ll x;
        Node *l;
        Node *r;
        Node(ll _x) {
            x = _x;
            l = r = NULL;
        }
    };
    ll query(Node* &node, ll st, ll dr, ll a, ll b) {
        if(node == NULL){
            return INF;
        }
        if(a <= st && dr <= b) {

            return node->x;
        }
        ll mid = (st + dr) / 2;
        ll minim = INF;
        if(a <= mid) {
            minim = min(minim, query(node->l, st, mid, a, b));
        }
        if(b > mid) {
            minim = min(minim, query(node->r, mid + 1, dr, a, b));
        }
        return minim;
    }
    void update(Node* &node, ll st, ll dr, ll poz, ll val){
        if(node == NULL){
            node = new Node(val);
        }
        node->x = min(node->x, val);
        if(st == dr){
            //node->x = val;
            return;
        }

        ll mid = (st + dr) / 2;
        if(poz <= mid){
            update(node->l, st, mid, poz, val);
        }else{
            update(node->r, mid + 1, dr, poz, val);
        }
    }
public:
    Node *root;
    ll q(ll a, ll b){
        return query(root, 1, n, a, b);
    }
    void up(ll a, ll b){
        update(root, 1, n, a, b);
    }
}pref, suff;

int main() {
    cin >> m >> n;
    ll maxim = (1LL << 55);
   // debug(suff.q(2, 4));
    for(ll i = 1; i <= m; i++) {
        ll a, b, c, d;
        cin >> a >> b >> c >> d;
        ll cost = 0, sum = 0;
        cost = pref.q(a, b) + d;
        if(a == 1){
            cost = d;
        }
        sum += cost;
        pref.up(c, cost);
        cost = suff.q(a, b) + d;
        if(b == n){
            cost = d;
        }
        sum += cost;
        suff.up(c, cost);
       // debug(sum);
        maxim = min(maxim, sum - d);
    }
    if(maxim < (1LL << 55)){
        cout << maxim;
    }else{
        cout << -1;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 288 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 288 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 2 ms 640 KB Output is correct
14 Correct 2 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 288 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 2 ms 640 KB Output is correct
14 Correct 2 ms 640 KB Output is correct
15 Correct 1 ms 288 KB Output is correct
16 Correct 2 ms 512 KB Output is correct
17 Correct 6 ms 1152 KB Output is correct
18 Correct 6 ms 384 KB Output is correct
19 Correct 8 ms 1536 KB Output is correct
20 Correct 6 ms 1024 KB Output is correct
21 Correct 3 ms 640 KB Output is correct
22 Correct 6 ms 1408 KB Output is correct
23 Correct 6 ms 1664 KB Output is correct
24 Correct 8 ms 1664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 1 ms 288 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 2 ms 640 KB Output is correct
14 Correct 2 ms 640 KB Output is correct
15 Correct 1 ms 288 KB Output is correct
16 Correct 2 ms 512 KB Output is correct
17 Correct 6 ms 1152 KB Output is correct
18 Correct 6 ms 384 KB Output is correct
19 Correct 8 ms 1536 KB Output is correct
20 Correct 6 ms 1024 KB Output is correct
21 Correct 3 ms 640 KB Output is correct
22 Correct 6 ms 1408 KB Output is correct
23 Correct 6 ms 1664 KB Output is correct
24 Correct 8 ms 1664 KB Output is correct
25 Correct 45 ms 3960 KB Output is correct
26 Correct 152 ms 15688 KB Output is correct
27 Correct 461 ms 34168 KB Output is correct
28 Correct 529 ms 1484 KB Output is correct
29 Correct 345 ms 34424 KB Output is correct
30 Correct 638 ms 10360 KB Output is correct
31 Correct 759 ms 65528 KB Output is correct
32 Correct 732 ms 52984 KB Output is correct
33 Correct 95 ms 12792 KB Output is correct
34 Correct 342 ms 44028 KB Output is correct
35 Correct 544 ms 90668 KB Output is correct
36 Correct 748 ms 88056 KB Output is correct
37 Correct 668 ms 87996 KB Output is correct
38 Correct 640 ms 88184 KB Output is correct