답안 #254806

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
254806 2020-07-30T15:52:02 Z imeimi2000 Mixture (BOI20_mixture) C++17
100 / 100
165 ms 8696 KB
#include <bits/stdc++.h>
#define x first
#define y second

using namespace std;
typedef long long llong;
typedef pair<llong, llong> pll;

int n;
llong V[3], Q[100001][3];
pll P[100001];
int I[3];

llong gcd(llong x, llong y) {
    for (; y; swap(x, y)) x %= y;
    return max(x, 1ll);
}

pll get(int it) {
    llong x = 0, m = 0, R[3] = {};
    for (int i = 0; i < 3; ++i) {
        x += V[i] * V[i];
        m += V[i] * Q[it][i];
    }
    for (int i = 0; i < 3; ++i) {
        R[i] = x * Q[it][i] - m * V[i];
    }
    llong g = gcd(abs(R[1]), abs(R[2]));
    return pll(R[1] / g, R[2] / g);
}

int ccw(pll a, pll b) {
    if (a == b) return 0;
    long double ld = 1.L * a.x * b.y - 1.L * a.y * b.x;
    if (ld > 0) return 1;
    return -1;
}

struct cmp {
    bool operator()(const pll &a, const pll &b) const {
        if (a.y < 0 && b.y > 0) return 0;
        if (a.y > 0 && b.y < 0) return 1;
        if (a.y == 0 && b.y == 0) return a.x > b.x;
        if (a.x > 0 && a.y == 0) return 1;
        if (b.x > 0 && b.y == 0) return 0;
        return ccw(a, b) > 0;
    }
};

pll operator-(pll a) {
    return pll(-a.x, -a.y);
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    for (int i = 0; i < 3; ++i) {
        cin >> V[i];
        I[i] = i;
    }
    for (int i = 0, j = 0; i < 3; ++i) {
        if (V[i] > 0) swap(V[i], V[j]), swap(I[i], I[j]), ++j;
    }
    int idx = 0;
    int cnt0 = 0, cnt180 = 0;
    llong cntP = 0;
    map<pll, int, cmp> mp;
    cin >> n;
    for (int it = 1; it <= n; ++it) {
        char T[5];
        cin >> T;
        if (T[0] == 'A') {
            ++idx;
            llong in[3];
            for (int i = 0; i < 3; ++i) cin >> in[i];
            for (int i = 0; i < 3; ++i) Q[idx][i] = in[I[i]];
            P[idx] = get(idx);
            if (P[idx] == pll(0, 0)) ++cnt0;
            else {
                if (++mp[P[idx]] == 1) {
                    auto it = mp.find(P[idx]);
                    if (it != mp.begin() && next(it) != mp.end()) {
                        if (ccw(prev(it)->x, next(it)->x) < 0) --cnt180;
                    }
                    if (it != mp.begin()) {
                        if (ccw(prev(it)->x, it->x) < 0) ++cnt180;
                    }
                    if (next(it) != mp.end()) {
                        if (ccw(it->x, next(it)->x) < 0) ++cnt180;
                    }
                }
                if (mp.count(-P[idx])) cntP += mp[-P[idx]];
            }
        }
        else {
            int idx;
            cin >> idx;
            if (P[idx] == pll(0, 0)) --cnt0;
            else {
                if (--mp[P[idx]] == 0) {
                    auto it = mp.find(P[idx]);
                    if (it != mp.begin() && next(it) != mp.end()) {
                        if (ccw(prev(it)->x, next(it)->x) < 0) ++cnt180;
                    }
                    if (it != mp.begin()) {
                        if (ccw(prev(it)->x, it->x) < 0) --cnt180;
                    }
                    if (next(it) != mp.end()) {
                        if (ccw(it->x, next(it)->x) < 0) --cnt180;
                    }
                    mp.erase(it);
                }
                if (mp.count(-P[idx])) cntP -= mp[-P[idx]];
            }
        }
        if (cnt0) printf("1\n");
        else if (cntP) printf("2\n");
        else if (int(mp.size()) <= 1 || cnt180) printf("0\n");
        else if (ccw(mp.rbegin()->x, mp.begin()->x) < 0) printf("0\n");
        else printf("3\n"); 
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 0 ms 256 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 0 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 0 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 0 ms 256 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 0 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 0 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 1 ms 384 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
41 Correct 1 ms 384 KB Output is correct
42 Correct 1 ms 416 KB Output is correct
43 Correct 2 ms 384 KB Output is correct
44 Correct 3 ms 384 KB Output is correct
45 Correct 2 ms 384 KB Output is correct
46 Correct 6 ms 512 KB Output is correct
47 Correct 4 ms 512 KB Output is correct
48 Correct 2 ms 384 KB Output is correct
49 Correct 4 ms 384 KB Output is correct
50 Correct 2 ms 384 KB Output is correct
51 Correct 5 ms 640 KB Output is correct
52 Correct 5 ms 640 KB Output is correct
53 Correct 5 ms 640 KB Output is correct
54 Correct 5 ms 640 KB Output is correct
55 Correct 2 ms 512 KB Output is correct
56 Correct 2 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 0 ms 256 KB Output is correct
21 Correct 0 ms 384 KB Output is correct
22 Correct 0 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 0 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 1 ms 384 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
41 Correct 1 ms 384 KB Output is correct
42 Correct 1 ms 416 KB Output is correct
43 Correct 2 ms 384 KB Output is correct
44 Correct 3 ms 384 KB Output is correct
45 Correct 2 ms 384 KB Output is correct
46 Correct 6 ms 512 KB Output is correct
47 Correct 4 ms 512 KB Output is correct
48 Correct 2 ms 384 KB Output is correct
49 Correct 4 ms 384 KB Output is correct
50 Correct 2 ms 384 KB Output is correct
51 Correct 5 ms 640 KB Output is correct
52 Correct 5 ms 640 KB Output is correct
53 Correct 5 ms 640 KB Output is correct
54 Correct 5 ms 640 KB Output is correct
55 Correct 2 ms 512 KB Output is correct
56 Correct 2 ms 512 KB Output is correct
57 Correct 4 ms 512 KB Output is correct
58 Correct 7 ms 640 KB Output is correct
59 Correct 8 ms 640 KB Output is correct
60 Correct 7 ms 640 KB Output is correct
61 Correct 12 ms 1152 KB Output is correct
62 Correct 15 ms 1024 KB Output is correct
63 Correct 122 ms 6724 KB Output is correct
64 Correct 126 ms 6648 KB Output is correct
65 Correct 137 ms 4088 KB Output is correct
66 Correct 138 ms 4088 KB Output is correct
67 Correct 0 ms 384 KB Output is correct
68 Correct 1 ms 384 KB Output is correct
69 Correct 165 ms 8696 KB Output is correct
70 Correct 156 ms 7032 KB Output is correct
71 Correct 152 ms 6904 KB Output is correct
72 Correct 124 ms 6264 KB Output is correct
73 Correct 145 ms 6776 KB Output is correct