Submission #1034024

# Submission time Handle Problem Language Result Execution time Memory
1034024 2024-07-25T08:52:40 Z vjudge1 Pinball (JOI14_pinball) C++17
100 / 100
193 ms 31448 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<long long, long long>
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define lwb lower_bound
#define upb upper_bound

#define TASKNAME "NAME"

void init()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ///freopen(TASKNAME".INP","r",stdin); freopen(TASKNAME".OUT","w",stdout);
}

const int maxN = 3e5+5;
const ll INF = INT_MAX / 2, MOD = 1e9+7, INFLL = 2e18;
const double epsilon = 1e-3;

struct Device
{
    ll a,b,c,d;
    Device(ll _a = 0, ll _b = 0, ll _c = 0, ll _d = 0) : a(_a), b(_b), c(_c), d(_d) {}
};

int m, n;
Device x[maxN];
vector<int> cprs;

int pos(int k)
{
    return lwb(all(cprs),k) - cprs.begin() + 1;
}

struct SegTree
{
    ll nodes[4*maxN];

    void build(int id, int lo, int hi, int t)
    {
        if(lo == hi)
        {
            if(lo == t) nodes[id] = 0;
            else nodes[id] = INFLL;
            return;
        }
        int mid = (lo + hi) / 2;
        build(2*id, lo, mid, t);
        build(2*id+1, mid+1, hi, t);
        nodes[id] = min(nodes[2*id], nodes[2*id+1]);
    }

    void update(int id, int lo, int hi, int pos, ll val)
    {
        if(lo == hi)
        {
            nodes[id] = min(nodes[id], val);
            return;
        }
        int mid = (lo + hi) / 2;
        if(pos <= mid) update(2*id, lo, mid, pos, val);
        else update(2*id+1, mid+1, hi, pos, val);
        nodes[id] = min(nodes[2*id], nodes[2*id+1]);
    }

    ll query(int id, int lo, int hi, int u, int v)
    {
        if(lo >= u && hi <= v) return nodes[id];
        if(lo > v || hi < u) return INFLL;
        int mid = (lo + hi) / 2;
        return min(query(2*id, lo, mid, u, v), query(2*id+1, mid+1, hi, u, v));
    }
} seg1, seg2;

int main()
{
    init();
    cin >> n >> m;
    cprs.pb(1);
    cprs.pb(m);
    for(int i = 1; i <= n; i++)
    {
        ll a,b,c,d;
        cin >> a >> b >> c >> d;
        cprs.pb(a);
        cprs.pb(b);
        cprs.pb(c);
        x[i] = {a, b, c, d};
    }
    sort(all(cprs));
    unique(all(cprs));
    seg1.build(1, 1, pos(m), 1);
    seg2.build(1, 1, pos(m), pos(m));
    ll res = INFLL;
    for(int i = 1; i <= n; i++)
    {
        ll a = pos(x[i].a), b = pos(x[i].b), c = pos(x[i].c), d = x[i].d;
        ll cur1 = seg1.query(1, 1, pos(m), a, b), cur2 = seg2.query(1, 1, pos(m), a, b);
        res = min(res, cur1 + cur2 + d);
        seg1.update(1, 1, pos(m), c, cur1 + d);
        seg2.update(1, 1, pos(m), c, cur2 + d);
    }
    cout << (res == INFLL ? -1 : res);
}

# Verdict Execution time Memory Grader output
1 Correct 4 ms 9820 KB Output is correct
2 Correct 4 ms 9816 KB Output is correct
3 Correct 3 ms 9820 KB Output is correct
4 Correct 4 ms 9820 KB Output is correct
5 Correct 4 ms 9820 KB Output is correct
6 Correct 3 ms 9860 KB Output is correct
7 Correct 3 ms 9624 KB Output is correct
8 Correct 3 ms 9820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9820 KB Output is correct
2 Correct 4 ms 9816 KB Output is correct
3 Correct 3 ms 9820 KB Output is correct
4 Correct 4 ms 9820 KB Output is correct
5 Correct 4 ms 9820 KB Output is correct
6 Correct 3 ms 9860 KB Output is correct
7 Correct 3 ms 9624 KB Output is correct
8 Correct 3 ms 9820 KB Output is correct
9 Correct 5 ms 9816 KB Output is correct
10 Correct 4 ms 9740 KB Output is correct
11 Correct 4 ms 9816 KB Output is correct
12 Correct 4 ms 9820 KB Output is correct
13 Correct 4 ms 9820 KB Output is correct
14 Correct 4 ms 9852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9820 KB Output is correct
2 Correct 4 ms 9816 KB Output is correct
3 Correct 3 ms 9820 KB Output is correct
4 Correct 4 ms 9820 KB Output is correct
5 Correct 4 ms 9820 KB Output is correct
6 Correct 3 ms 9860 KB Output is correct
7 Correct 3 ms 9624 KB Output is correct
8 Correct 3 ms 9820 KB Output is correct
9 Correct 5 ms 9816 KB Output is correct
10 Correct 4 ms 9740 KB Output is correct
11 Correct 4 ms 9816 KB Output is correct
12 Correct 4 ms 9820 KB Output is correct
13 Correct 4 ms 9820 KB Output is correct
14 Correct 4 ms 9852 KB Output is correct
15 Correct 3 ms 9820 KB Output is correct
16 Correct 4 ms 9924 KB Output is correct
17 Correct 5 ms 9932 KB Output is correct
18 Correct 4 ms 9820 KB Output is correct
19 Correct 5 ms 9820 KB Output is correct
20 Correct 5 ms 9820 KB Output is correct
21 Correct 4 ms 9872 KB Output is correct
22 Correct 4 ms 9820 KB Output is correct
23 Correct 5 ms 9916 KB Output is correct
24 Correct 5 ms 9820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9820 KB Output is correct
2 Correct 4 ms 9816 KB Output is correct
3 Correct 3 ms 9820 KB Output is correct
4 Correct 4 ms 9820 KB Output is correct
5 Correct 4 ms 9820 KB Output is correct
6 Correct 3 ms 9860 KB Output is correct
7 Correct 3 ms 9624 KB Output is correct
8 Correct 3 ms 9820 KB Output is correct
9 Correct 5 ms 9816 KB Output is correct
10 Correct 4 ms 9740 KB Output is correct
11 Correct 4 ms 9816 KB Output is correct
12 Correct 4 ms 9820 KB Output is correct
13 Correct 4 ms 9820 KB Output is correct
14 Correct 4 ms 9852 KB Output is correct
15 Correct 3 ms 9820 KB Output is correct
16 Correct 4 ms 9924 KB Output is correct
17 Correct 5 ms 9932 KB Output is correct
18 Correct 4 ms 9820 KB Output is correct
19 Correct 5 ms 9820 KB Output is correct
20 Correct 5 ms 9820 KB Output is correct
21 Correct 4 ms 9872 KB Output is correct
22 Correct 4 ms 9820 KB Output is correct
23 Correct 5 ms 9916 KB Output is correct
24 Correct 5 ms 9820 KB Output is correct
25 Correct 16 ms 11356 KB Output is correct
26 Correct 43 ms 15068 KB Output is correct
27 Correct 120 ms 21456 KB Output is correct
28 Correct 162 ms 31156 KB Output is correct
29 Correct 81 ms 20688 KB Output is correct
30 Correct 173 ms 31432 KB Output is correct
31 Correct 175 ms 31432 KB Output is correct
32 Correct 179 ms 31428 KB Output is correct
33 Correct 25 ms 12764 KB Output is correct
34 Correct 77 ms 20684 KB Output is correct
35 Correct 108 ms 31332 KB Output is correct
36 Correct 193 ms 31432 KB Output is correct
37 Correct 146 ms 31448 KB Output is correct
38 Correct 153 ms 31432 KB Output is correct