Submission #947663

# Submission time Handle Problem Language Result Execution time Memory
947663 2024-03-16T17:56:20 Z ND0322 Pinball (JOI14_pinball) C++17
100 / 100
280 ms 111804 KB
#include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <set>

#define int long long

using namespace std;

const int MAXN = 1e5+5;

int n, m;

long long st[MAXN*64][2];

vector<int> coord;

pair<pair<int,int>,pair<int,int>> a[MAXN];

//n^2
//for some filter have dpl representing path to 0 and dpr representing path to 1
//we look for some thing within this range we jump from
//update dp state as the position of the out part of the filter

//full just throw a sparse seg tree over that sh
//nvm sparse dont work coord compress

void update(int node, int l, int r, int i, long long x, bool t){
    if(l == r){

        st[node][t] = min(st[node][t], x);
        return;
    }

    int mid = (l+r)>>1;
    if(i <= mid) update(node<<1,l,mid,i,x,t);
    else update(node<<1|1, mid+1,r,i,x,t);
    

    st[node][t] = min(st[node<<1][t], st[node<<1|1][t]);
}

long long query(int node, int l, int r, int x, int y, bool t){
    if(x > r || y < l) return 1e18;
    if(x <= l && y >= r) return st[node][t];
    int mid = (l+r)>>1;
    return min(query(node<<1, l,mid, x, y, t), query(node<<1|1, mid+1,r,x,y,t));
}

int get(int x){
    return (int)(lower_bound(coord.begin(), coord.end(), x) - coord.begin())+1;
}

int32_t main(){
    cin >> n >> m;

    coord.push_back(1);
    coord.push_back(m);

    for(int i = 1; i <= n; i++){
        cin >> a[i].first.first >> a[i].first.second >> a[i].second.first >> a[i].second.second;

        coord.push_back(a[i].first.first);
        coord.push_back(a[i].first.second);
        coord.push_back(a[i].second.first);
    }

    sort(coord.begin(), coord.end());
    coord.erase(unique(coord.begin(), coord.end()), coord.end());

    memset(st, 0x3f, sizeof(st));

    int tmp = m;

    m = coord.size();

    update(1,1,m,get(1), 0, 0);
    update(1,1,m,get(tmp),0,1);

    //cout << query(1,1,m, 1, 3, 0) << "\n";

    long long ans = 1e18;

    for(int i = 1; i <= n; i++){
        auto [l,r] = a[i].first;

        l = get(l);
        r = get(r);

        

        long long x = query(1,1,m,l,r,0) + a[i].second.second;
        long long y = query(1,1,m,l,r,1) + a[i].second.second;

        //cout << l << " " << r << " " << x << " " << y << "\n";


        ans = min(ans, x + y - a[i].second.second);
        update(1,1,m,get(a[i].second.first), x, 0);
        update(1,1,m,get(a[i].second.first), y, 1);
    }

    cout << (ans >= 1e18 ? -1 : ans) << "\n";
}




# Verdict Execution time Memory Grader output
1 Correct 24 ms 101468 KB Output is correct
2 Correct 13 ms 101468 KB Output is correct
3 Correct 12 ms 101468 KB Output is correct
4 Correct 13 ms 101468 KB Output is correct
5 Correct 13 ms 101464 KB Output is correct
6 Correct 12 ms 101468 KB Output is correct
7 Correct 16 ms 101372 KB Output is correct
8 Correct 13 ms 101500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 101468 KB Output is correct
2 Correct 13 ms 101468 KB Output is correct
3 Correct 12 ms 101468 KB Output is correct
4 Correct 13 ms 101468 KB Output is correct
5 Correct 13 ms 101464 KB Output is correct
6 Correct 12 ms 101468 KB Output is correct
7 Correct 16 ms 101372 KB Output is correct
8 Correct 13 ms 101500 KB Output is correct
9 Correct 13 ms 101468 KB Output is correct
10 Correct 13 ms 101468 KB Output is correct
11 Correct 13 ms 101412 KB Output is correct
12 Correct 13 ms 101468 KB Output is correct
13 Correct 13 ms 101468 KB Output is correct
14 Correct 15 ms 101724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 101468 KB Output is correct
2 Correct 13 ms 101468 KB Output is correct
3 Correct 12 ms 101468 KB Output is correct
4 Correct 13 ms 101468 KB Output is correct
5 Correct 13 ms 101464 KB Output is correct
6 Correct 12 ms 101468 KB Output is correct
7 Correct 16 ms 101372 KB Output is correct
8 Correct 13 ms 101500 KB Output is correct
9 Correct 13 ms 101468 KB Output is correct
10 Correct 13 ms 101468 KB Output is correct
11 Correct 13 ms 101412 KB Output is correct
12 Correct 13 ms 101468 KB Output is correct
13 Correct 13 ms 101468 KB Output is correct
14 Correct 15 ms 101724 KB Output is correct
15 Correct 14 ms 101468 KB Output is correct
16 Correct 13 ms 101468 KB Output is correct
17 Correct 15 ms 101624 KB Output is correct
18 Correct 14 ms 101508 KB Output is correct
19 Correct 15 ms 101468 KB Output is correct
20 Correct 15 ms 101460 KB Output is correct
21 Correct 14 ms 101468 KB Output is correct
22 Correct 15 ms 101468 KB Output is correct
23 Correct 15 ms 101460 KB Output is correct
24 Correct 14 ms 101468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 101468 KB Output is correct
2 Correct 13 ms 101468 KB Output is correct
3 Correct 12 ms 101468 KB Output is correct
4 Correct 13 ms 101468 KB Output is correct
5 Correct 13 ms 101464 KB Output is correct
6 Correct 12 ms 101468 KB Output is correct
7 Correct 16 ms 101372 KB Output is correct
8 Correct 13 ms 101500 KB Output is correct
9 Correct 13 ms 101468 KB Output is correct
10 Correct 13 ms 101468 KB Output is correct
11 Correct 13 ms 101412 KB Output is correct
12 Correct 13 ms 101468 KB Output is correct
13 Correct 13 ms 101468 KB Output is correct
14 Correct 15 ms 101724 KB Output is correct
15 Correct 14 ms 101468 KB Output is correct
16 Correct 13 ms 101468 KB Output is correct
17 Correct 15 ms 101624 KB Output is correct
18 Correct 14 ms 101508 KB Output is correct
19 Correct 15 ms 101468 KB Output is correct
20 Correct 15 ms 101460 KB Output is correct
21 Correct 14 ms 101468 KB Output is correct
22 Correct 15 ms 101468 KB Output is correct
23 Correct 15 ms 101460 KB Output is correct
24 Correct 14 ms 101468 KB Output is correct
25 Correct 33 ms 104408 KB Output is correct
26 Correct 73 ms 105248 KB Output is correct
27 Correct 183 ms 107968 KB Output is correct
28 Correct 203 ms 111200 KB Output is correct
29 Correct 136 ms 106768 KB Output is correct
30 Correct 229 ms 110028 KB Output is correct
31 Correct 280 ms 111576 KB Output is correct
32 Correct 261 ms 111032 KB Output is correct
33 Correct 52 ms 104976 KB Output is correct
34 Correct 135 ms 106828 KB Output is correct
35 Correct 219 ms 110596 KB Output is correct
36 Correct 276 ms 111548 KB Output is correct
37 Correct 252 ms 111804 KB Output is correct
38 Correct 254 ms 111544 KB Output is correct