Submission #529868

# Submission time Handle Problem Language Result Execution time Memory
529868 2022-02-23T22:22:55 Z c28dnv9q3 Mixture (BOI20_mixture) C++17
0 / 100
1 ms 288 KB
#include <iostream>
#include <bits/stdc++.h>
#define lli long long int

using namespace std;

lli mod = 1000000007;
lli pow(lli b, lli e) {
    if (e == 0) return 1;
    lli h = pow(b, e / 2);
    return ((((e % 2 == 1 ? b : 1) * h) % mod) * h) % mod;
}

lli inv(lli n) {
    return pow(n, mod - 2);
}

struct frac {
    lli z;
    lli d;
    lli t;

    bool operator < (const frac& other) const {
        if (z * other.d == other.z * d) return t < other.t;
        return z * other.d < other.z * d;
    }

    bool operator > (const frac& other) const {
        if (z * other.d == other.z * d) return t > other.t;
        return z * other.d > other.z * d;
    }

    bool operator <= (const frac& other) const {
        return z * other.d <= other.z * d;
    }

    bool operator >= (const frac& other) const {
        return z * other.d >= other.z * d;
    }

    frac operator - () const {
        return frac({-z, d, t});
    }
};

template <class T> struct les {
    bool operator() (const T& x, const T& y) const {
        return x < y;
    }
    typedef T first_argument_type;
    typedef T second_argument_type;
    typedef bool result_type;
};

std::ostream & operator<<(std::ostream & Str, frac const & v) {
    Str << v.z << " " << v.d;
    return Str;
}

int main() {
    lli a, b, c;
    cin >> a >> b >> c;

    lli n;
    cin >> n;

    multiset<frac, les<frac>> pos, neg;
    vector<frac> regal;

    string op;

    lli ta, tb, tc, r, z, posZ, negZ;
    frac f;
    z = 0;
    posZ = 0;
    negZ = 0;

    for (int i = 0; i < n; ++i) {
        //cout << i << "\n";

        cin >> op;
        if (op == "A") {
            cin >> ta >> tb >> tc;
            ta *= a;
            tb *= a;
            tc *= a;
            tb -= ta / a * b;
            tc -= ta / a * c;

            f = frac({tb, tc, i});
            regal.push_back(f);

            if (f.z == 0 && f.d == 0) {
                z++;
            }

            if (f.d == 0) {
                if (f.z >= 0) posZ++; else negZ++;
            }

            if (f.d >= 0) {
                pos.insert(f);
            } else {
                neg.insert(f);
            }
        } else {
            cin >> r;
            f = regal[r - 1];

            if (f.z == 0 && f.d == 0) {
                z--;
            }

            if (f.d == 0) {
                if (f.z >= 0) posZ++; else negZ--;
            }

            if (f.d >= 0) {
                pos.erase(f);
            } else {
                neg.erase(f);
            }
        }

        /*
        cout << "pos\n";
        for (auto a: pos) {
            cout << a << "\n";
        }
        cout << "neg\n";
        for (auto a: neg) {
            cout << a << "\n";
        }
         */


        if (z > 0) {
            cout << 1;
        } else {
            if (posZ > 0 && negZ > 0) cout << 2;
            else if (pos.size() != 0 && neg.size() != 0) {
                /*
                cout << *neg.begin() << " " << *--neg.end() << "\n";
                cout << *pos.begin() << " " << *--pos.end() << "\n";
                cout << ((*neg.begin()) <= (*--pos.end())) << ((*neg.begin()) >= (*pos.begin())) << ((*--neg.end()) <= (*--pos.end())) << ((*--neg.end()) >= (*pos.begin())) << "\n";
                 */
                if (((*neg.begin()) <= (*--pos.end()) && (*neg.begin()) >= (*pos.begin())) || ((*--neg.end()) <= (*--pos.end()) && (*--neg.end()) >= (*pos.begin()))) {
                    cout << 2;
                } else {
                    cout << 0;
                }
            } else {
                cout << 0;
            }
        }

        cout << "\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 288 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 288 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 288 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 288 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -