Submission #595796

# Submission time Handle Problem Language Result Execution time Memory
595796 2022-07-14T07:02:22 Z dooompy MP3 Player (CEOI10_mp3player) C++17
20 / 100
50 ms 8904 KB
#include "bits/stdc++.h"

using namespace std;

void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T a, U ...b) {
    cout << a << ' ', abc(b...);
}
template <typename T> void printv(T l, T r) {
    while (l != r) cout << *l << " \n"[++l == r];
}
template <typename A, typename B> istream& operator >> (istream& o, pair<A, B> &a) {
    return o >> a.first >> a.second;
}
template <typename A, typename B> ostream& operator << (ostream& o, pair<A, B> a) {
    return o << '(' << a.first << ", " << a.second << ')';
}
template <typename T> ostream& operator << (ostream& o, vector<T> a) {
    bool is = false;
    for (T i : a) {o << (is ? ' ' : '{'), is = true, o << i;}
    return o << '}';
}

#ifdef local
#define test(args...) abc("[" + string(#args) + "]", args)
#else
#define test(args...) void(0)
#endif

#define int long long

using ll = long long;

char k[100005]; int t[100005];
int d[100005];
int s[100005];
int n, vm, v;

struct node {
    int ls, rs, x;
};

node tree[8 * 100005];

void combine(int x) {
    tree[x].ls = max(tree[2 * x].ls, tree[2 * x + 1].ls - tree[2 * x].x);
    tree[x].rs = min(tree[2 * x].rs, tree[ 2 * x + 1].rs - tree[2 * x].x);

    if (tree[x].ls <= tree[x].rs) {
        tree[x].x = tree[2 * x].x + tree[2 *x + 1].x;
    } else if (tree[2 * x].ls + tree[2*x].x > tree[2*x+1].rs) {
        tree[x] = {tree[2*x+1].rs, tree[2*x+1].rs, tree[2*x+1].x};
    } else {
        tree[x] = {tree[2*x+1].ls, tree[2*x+1].ls, tree[2*x+1].x};
    }
}

void build(int x, int l, int r) {
    tree[x] = {0, vm, 0};
    if (l == r) {
        return;
    }

    int mid = (l + r) / 2;
    build(2*x, l, mid);
    build(2* x + 1, mid + 1, r);
}

void update(int x, int l, int r, int p) {
    if (l == r) {
        if (k[p] == '+') {
            tree[x] = {0, vm-1, 1};
        } else {
            tree[x] = {1, vm, -1};
        }
        return;
    }

    int mid = (l + r) / 2;
    if (p <= mid) {
        update(2 * x, l, mid, p);
    } else {
        update(2 * x + 1, mid + 1, r, p);
    }

    combine(x);
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
//    freopen("", "r", stdin);
//    freopen("", "w", stdout);
    cin >> n >> vm >> v;
    assert(n <= 100000);
    for (int i = 0; i < n; i++) {
        cin >> k[i] >> t[i];
    }

    for (int i = 0; i < n; i++) {
        d[i+1] = t[i+1] - t[i];
    }

    for (int i = 0; i < n - 1;i ++) {
        s[i] = i + 1;
    }

    sort(s, s+n-1, [](int a, int b) {
        return d[a] < d[b];
    });

//    for (int i = 0; i < n-1; i++) {
//        cout << s[i] << endl;
//    }

    build(1, 1, n-1);

    pair<int, int> ans = {-1, v};

    for (int i = 0; i < n-1; i++) {
        update(1, 1, n-1, s[i]);

        if (i == n-2 || t[s[i]] != t[s[i+1]]) {
            if (tree[1].ls + tree[1].x <= v && v < tree[1].rs + tree[1].x) {
                ans = {i, v - tree[1].x};
            } else if (tree[1].rs + tree[1].x == v) {
                ans = {i, vm};
            }
        }
    }
    
    if (ans.first == n-2) {
        cout << "infinity";
    } else {
        cout << d[s[ans.first + 1]] - 1 << " " << ans.second;
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Incorrect 1 ms 468 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 596 KB Output is correct
2 Correct 4 ms 596 KB Output is correct
3 Incorrect 2 ms 596 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 2388 KB Output is correct
2 Correct 8 ms 2388 KB Output is correct
3 Incorrect 20 ms 2424 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 2388 KB Output is correct
2 Correct 20 ms 2352 KB Output is correct
3 Incorrect 9 ms 2496 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 2516 KB Output is correct
2 Correct 13 ms 2516 KB Output is correct
3 Correct 13 ms 4176 KB Output is correct
4 Correct 8 ms 2548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 4468 KB Output is correct
2 Correct 17 ms 4524 KB Output is correct
3 Correct 16 ms 4412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 50 ms 8872 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 50 ms 8904 KB Output isn't correct
2 Halted 0 ms 0 KB -