답안 #529132

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
529132 2022-02-22T09:44:36 Z c28dnv9q3 Mixture (BOI20_mixture) C++17
0 / 100
0 ms 204 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;
    }
};

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;
};

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;
    frac f;

    for (int i = 0; i < n; ++i) {
        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++;
            } else {
                if (f.z >= 0) {
                    pos.insert(f);
                } else {
                    neg.insert(f);
                }
            }
        } else {
            cin >> r;
            f = regal[r - 1];
            if (f.z == 0 && f.d == 0) {
                z--;
            } else {
                if (f.z >= 0) {
                    pos.erase(f);
                } else {
                    neg.erase(f);
                }
            }
        }

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

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

Compilation message

Mixture.cpp: In function 'int main()':
Mixture.cpp:72:18: warning: 'z' may be used uninitialized in this function [-Wmaybe-uninitialized]
   72 |                 z++;
      |                 ~^~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -