Submission #142858

# Submission time Handle Problem Language Result Execution time Memory
142858 2019-08-11T15:15:01 Z popovicirobert MP3 Player (CEOI10_mp3player) C++14
60 / 100
70 ms 6896 KB
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long



/*const int MOD = 998244353;

inline int lgput(int a, int b) {
    int ans = 1;
    while(b > 0) {
        if(b & 1) ans = (1LL * ans * a) % MOD;
        b >>= 1;
        a = (1LL * a * a) % MOD;
    }
    return ans;
}

inline void mod(int &x) {
    if(x >= MOD)
        x -= MOD;
}

inline void add(int &x, int y) {
    x += y;
    mod(x);
}

inline void sub(int &x, int y) {
    x += MOD - y;
    mod(x);
}

inline void mul(int &x, int y) {
    x = (1LL * x * y) % MOD;
}

inline int inv(int x) {
    return lgput(x, MOD - 2);
}*/

/*int fact[], invfact[];

inline void prec(int n) {
    fact[0] = 1;
    for(int i = 1; i <= n; i++) {
        fact[i] = (1LL * fact[i - 1] * i) % MOD;
    }
    invfact[n] = lgput(fact[n], MOD - 2);
    for(int i = n - 1; i >= 0; i--) {
        invfact[i] = (1LL * invfact[i + 1] * (i + 1)) % MOD;
    }
}

inline int comb(int n, int k) {
    if(n < k) return 0;
    return (1LL * fact[n] * (1LL * invfact[k] * invfact[n - k] % MOD)) % MOD;
}*/

using namespace std;


struct SegTree {
    struct Node {
        int mn, mx;
        int sum;
    };

    vector <Node> aint;
    int n;

    inline void init(int _n) {
        n = _n;
        aint.resize(4 * n + 1);
    }

    inline void refresh(int nod) {
        aint[nod].sum = aint[2 * nod].sum + aint[2 * nod + 1].sum;
        aint[nod].mn = min(aint[2 * nod + 1].mn, aint[2 * nod + 1].sum + aint[2 * nod].mn);
        aint[nod].mx = max(aint[2 * nod + 1].mx, aint[2 * nod + 1].sum + aint[2 * nod].mx);
    }

    void update(int nod, int left, int right, int pos, int val) {
        if(left == right) {
            aint[nod] = {val, val, val};
        }
        else {
            int mid = (left + right) / 2;
            if(pos <= mid) update(2 * nod, left, mid, pos, val);
            else update(2 * nod + 1, mid + 1, right, pos, val);
            refresh(nod);
        }
    }
};


int main() {
#if 0
    ifstream cin("A.in");
    ofstream cout("A.out");
#endif
    int i, n, vmax, v2;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    cin >> n >> vmax >> v2;
    vector <int> sgn(n + 1), c(n + 1);
    for(i = 1; i <= n; i++) {
        char ch;
        cin >> ch >> c[i];
        sgn[i] = (ch == '-' ? -1 : 1);
    }

    vector < pair <int, int> > t;
    for(i = 2; i <= n; i++) {
        t.push_back({c[i] - c[i - 1], i});
    }
    sort(t.begin(), t.end());

    SegTree st; st.init(n);
    int ans = t[0].first - 1; i = 0;
    while(i < t.size()) {
        int j = i;
        while(j < t.size() && t[i].first == t[j].first) {
            st.update(1, 1, n, t[j].second, sgn[t[j].second]);
            j++;
        }
        int mn = st.aint[1].mn;
        int mx = st.aint[1].mx;
        bool bad = 0;
        if(mn < 0) {
            if(v2 == 0 || v2 - mn <= vmax) {

            }
            else {
                bad = 1;
            }
        }
        if(mx > 0) {
            if(v2 == vmax || v2 - mx >= 0) {

            }
            else {
                bad = 1;
            }
        }
        if(!bad) {
            ans = (j < t.size() ? t[j].first - 1 : t[i].first);
        }
        i = j;
    }

    if(ans == t.back().first) {
        cout << "infinity";
        return 0;
    }

    auto get = [&](int cur) {
        for(int i = 2; i <= n; i++) {
            if(c[i] - c[i - 1] <= ans) {
                cur += sgn[i];
            }
            cur = min(cur, vmax);
            cur = max(cur, 0);
        }
        return cur;
    };

    int v1 = 0;
    for(int step = 1 << 12; step; step >>= 1) {
        int cur = v1 + step;
        if(cur <= vmax && get(cur) <= v2) {
            v1 = cur;
        }
    }

    while(v1 <= vmax && get(v1) <= v2) {
        v1++;
    }
    cout << ans << " " << v1 - 1;

    return 0;
}

Compilation message

mp3player.cpp: In function 'int main()':
mp3player.cpp:123:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while(i < t.size()) {
           ~~^~~~~~~~~~
mp3player.cpp:125:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while(j < t.size() && t[i].first == t[j].first) {
               ~~^~~~~~~~~~
mp3player.cpp:149:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             ans = (j < t.size() ? t[j].first - 1 : t[i].first);
                    ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 636 KB Output is correct
2 Correct 3 ms 632 KB Output is correct
3 Correct 3 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 660 KB Output is correct
2 Correct 4 ms 632 KB Output is correct
3 Correct 4 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 1876 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 2036 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 27 ms 3316 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 65 ms 6696 KB Output is correct
2 Correct 48 ms 6768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 70 ms 6896 KB Output is correct
2 Correct 47 ms 6792 KB Output is correct