Submission #135456

# Submission time Handle Problem Language Result Execution time Memory
135456 2019-07-24T05:52:43 Z imeimi2000 MP3 Player (CEOI10_mp3player) C++17
0 / 100
101 ms 5112 KB
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
typedef long long llong;
typedef pair<int, int> pii;

int n, Vmax, V2;
struct node {
    int L, R, A;
    node() : L(0), R(Vmax), A(0) {}
    void add(int v) {
        A += v;
        L += v;
        R += v;
        if (L > Vmax) --L;
        if (R > Vmax) --R;
        if (L + A < 0) ++L;
        if (R + A < 0) ++R;
    }
    void add(node &c) const {
        c.L += A;
        c.R += A;
        c.A += A;
        c.L = min(max(c.L, L), R);
        c.R = min(max(c.R, L), R);
    }
} seg[1 << 18];

void init(int i, int s, int e) {
    seg[i] = node();
    if (s == e) return;
    int m = (s + e) / 2;
    init(i << 1, s, m);
    init(i << 1 | 1, m + 1, e);
}

const int inf = 2e9 + 5;
char T[100001];
int C[100001];
vector<int> cp;

int find(int x) {
    return upper_bound(cp.begin(), cp.end(), x) - cp.begin();
}

void update(int i, int s, int e, int x, int v) {
    if (e < x) return;
    if (x <= s) {
        seg[i].add(v);
        return;
    }
    seg[i].add(seg[i << 1]);
    seg[i].add(seg[i << 1 | 1]);
    seg[i] = node();
    int m = (s + e) / 2;
    update(i << 1, s, m, x, v);
    update(i << 1 | 1, m + 1, e, x, v);
}

pii get_ans(int i, int s, int e) {
    if (s == e) {
        if (seg[i].L <= V2 && V2 <= seg[i].R) {
            if (V2 == seg[i].R) return pii(s, Vmax);
            return pii(s, V2 - seg[i].A);
        }
        else return pii(1, V2);
    }
    seg[i].add(seg[i << 1]);
    seg[i].add(seg[i << 1 | 1]);
    seg[i] = node();
    int m = (s + e) / 2;
    return max(get_ans(i << 1, s, m), get_ans(i << 1 | 1, m + 1, e));
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> Vmax >> V2;
    for (int i = 1; i <= n; ++i) {
        char in[10];
        cin >> in >> C[i];
        T[i] = in[0];
        if (i > 1) cp.push_back(C[i] - C[i - 1]);
    }
    cp.push_back(0);
    cp.push_back(inf);
    sort(cp.begin(), cp.end());
    cp.erase(unique(cp.begin(), cp.end()), cp.end());
    int m = cp.size();
    init(1, 1, m);
    for (int i = 2; i <= n; ++i) {
        int t = find(C[i] - C[i - 1]);
        update(1, 1, m, t, T[i] == '+' ? 1 : -1);
    }
    pii ans = get_ans(1, 1, m);
    if (ans.first == m) printf("infinity\n");
    else printf("%d %d\n", cp[ans.first - 1], ans.second);
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 3448 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 3476 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 3448 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 3552 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 3960 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 4088 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 4164 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 43 ms 4240 KB Output is correct
2 Incorrect 31 ms 4512 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 88 ms 4724 KB Output is correct
2 Incorrect 64 ms 5084 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 101 ms 4728 KB Output is correct
2 Incorrect 63 ms 5112 KB Output isn't correct