답안 #254782

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
254782 2020-07-30T15:11:37 Z model_code Mixture (BOI20_mixture) C++11
100 / 100
221 ms 7288 KB
#include <bits/stdc++.h>
#define MAXN 100005

using namespace std;

struct vec {
	long long x, y;
	int part;
};

int crossProductResult(const vec &a, const vec &b) {
	
	__int128 res = (__int128)(a.x) * (__int128)(b.y) - (__int128)(a.y) * (__int128)(b.x);
	if (res < 0) {
		return -1;
	} else if (res > 0) {
		return 1;
	} else {
		return 0;
	}

	long long MOD = 1LL << 31;

	long long p0 = (b.y % MOD) * (a.x % MOD);
	long long p1 = (b.y % MOD) * (a.x / MOD) + (a.x % MOD) * (b.y / MOD);
	long long p2 = (a.x / MOD) * (b.y / MOD);
	long long p3 = 0;
	p1 += p0 / MOD;
	p0 %= MOD;
	p2 += p1 / MOD;
	p1 %= MOD;
	p3 += p2 / MOD;
	p2 %= MOD;

	long long q0 = (b.x % MOD) * (a.y % MOD);
	long long q1 = (b.x % MOD) * (a.y / MOD) + (a.y % MOD) * (b.x / MOD);
	long long q2 = (a.y / MOD) * (b.x / MOD);
	long long q3 = 0;
	q1 += q0 / MOD;
	q0 %= MOD;
	q2 += q1 / MOD;
	q1 %= MOD;
	q3 += q2 / MOD;
	q2 %= MOD;

	if (p3 < q3) {
		return -1;
	} else if (p3 > q3) {
		return 1;
	} else {
		if (p2 < q2) {
			return -1;
		} else if (p2 > q2) {
			return 1;
		} else {
			if (p1 < q1) {
				return -1;
			} else if (p1 > q1) {
				return 1;
			} else {
				if (p0 < q0) {
					return -1;
				} else if (p0 > q0) {
					return 1;
				} else {
					return 0;
				}
			}
		}
	}
}

int vecCompare(const vec &a, const vec &b) {
	if (a.part < b.part) {
		return -1;
	} else if (a.part > b.part) {
		return 1;
	} else {
		return crossProductResult(a, b);
	}
}

vec negateVec(const vec &a) {
	vec res;
	res.x = -a.x;
	res.y = -a.y;
	res.part = 1 ^ a.part;
	return res; 
}

struct vecLess {
	bool operator()(const vec &lhs, const vec &rhs) {
		return vecCompare(lhs, rhs) < 0;
	}
};

vec newVector(long long x, long long y) {
	vec res;
	res.x = x;
	res.y = y;
	if (x == 0) {
		if (y > 0) {
			res.part = 0;
		} else if (y < 0) {
			res.part = 1;
		} else {
			res.part = -1;
		}
	} else if (x > 0) {
		res.part = 0;
	} else {
		res.part = 1;
	}
	return res;
}

int main () {
	long long S, P, G;
	scanf("%lli %lli %lli",&S,&P,&G);

	int N;
	scanf("%d",&N);

	static vec data[MAXN];
	int datac = 0;
	multiset<vec, vecLess> st;

	int amountOfDots = 0;
	int amountOfLines = 0;
	int amountOfEmptyPies = 1;

	for (int i = 0; i < N; i++) {
		char c;
		scanf("\n%c",&c);
		if (c == 'A') {
			long long s, p, g;
			scanf("%lli %lli %lli",&s,&p,&g);

			long long x = s * (S + P + G) - S * (s + p + g);
			long long y = p * (S + P + G) - P * (s + p + g);

			if ((x == 0) && (y == 0)) {
				data[datac] = newVector(0, 0);
				datac++;
				amountOfDots++;
			} else {
				long long mult = s + p + g;
				vec cur = newVector(mult * x, mult * y);
				data[datac] = cur;
				datac++;

				multiset<vec>::iterator same = st.find(cur);
				multiset<vec>::iterator opposite = st.find(negateVec(cur));
				if ((same == st.end()) && (opposite != st.end())) {
					amountOfLines++;
				}

				if (st.size() >= 2) {
					multiset<vec>::iterator nextIt = st.upper_bound(cur);
					vec next;
					if (nextIt == st.end()) {
						next = *st.begin();
					} else {
						next = *nextIt;
					}
					vec prev;
					if ((nextIt == st.end()) || (nextIt == st.begin())) {
						prev = *st.rbegin();
					} else {
						prev = *(--nextIt);
					}

					if ((crossProductResult(prev, next) > 0)
							&& (crossProductResult(prev, cur) <= 0)
							&& (crossProductResult(cur, next) <= 0)) {
						amountOfEmptyPies = 0;
					}
				} else {
					amountOfEmptyPies = 1;
				}

				st.insert(cur);
			}
		} else {
			int ind;
			scanf("%d",&ind);
			vec cur = data[ind - 1];

			if ((cur.part == -1)) {
				amountOfDots--;
			} else {
				st.erase(st.find(cur));

				multiset<vec>::iterator same = st.find(cur);
				multiset<vec>::iterator opposite = st.find(negateVec(cur));
				if ((same == st.end()) && (opposite != st.end())) {
					amountOfLines--;
				}

				if (st.size() >= 2) {
					multiset<vec>::iterator nextIt = st.upper_bound(cur);
					vec next;
					if (nextIt == st.end()) {
						next = *st.begin();
					} else {
						next = *nextIt;
					}
					vec prev;
					if ((nextIt == st.end()) || (nextIt == st.begin())) {
						prev = *st.rbegin();
					} else {
						prev = *(--nextIt);
					}

					if (crossProductResult(prev, next) > 0) {
						amountOfEmptyPies = 1;
					}
				} else {
					amountOfEmptyPies = 1;
				}
			}
		}
		if (amountOfDots > 0) {
			printf("1\n");
		} else if (amountOfLines > 0) {
			printf("2\n");
		} else if (amountOfEmptyPies == 0) {
			printf("3\n");
		} else {
			printf("0\n");
		}
	}

	return 0;
}

Compilation message

Mixture.cpp: In function 'int main()':
Mixture.cpp:119:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lli %lli %lli",&S,&P,&G);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
Mixture.cpp:122:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&N);
  ~~~~~^~~~~~~~~
Mixture.cpp:134:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("\n%c",&c);
   ~~~~~^~~~~~~~~~~
Mixture.cpp:137:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%lli %lli %lli",&s,&p,&g);
    ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
Mixture.cpp:186:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d",&ind);
    ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 288 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 256 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 288 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 256 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 256 KB Output is correct
22 Correct 1 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 1 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 0 ms 256 KB Output is correct
2 Correct 1 ms 288 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 256 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 256 KB Output is correct
22 Correct 1 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 1 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 2 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 2 ms 384 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 2 ms 384 KB Output is correct
44 Correct 1 ms 384 KB Output is correct
45 Correct 2 ms 384 KB Output is correct
46 Correct 5 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 3 ms 384 KB Output is correct
50 Correct 3 ms 384 KB Output is correct
51 Correct 5 ms 512 KB Output is correct
52 Correct 6 ms 640 KB Output is correct
53 Correct 6 ms 640 KB Output is correct
54 Correct 6 ms 640 KB Output is correct
55 Correct 4 ms 512 KB Output is correct
56 Correct 3 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 288 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Correct 0 ms 256 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 0 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 256 KB Output is correct
22 Correct 1 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 1 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 2 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 2 ms 384 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 2 ms 384 KB Output is correct
44 Correct 1 ms 384 KB Output is correct
45 Correct 2 ms 384 KB Output is correct
46 Correct 5 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 3 ms 384 KB Output is correct
50 Correct 3 ms 384 KB Output is correct
51 Correct 5 ms 512 KB Output is correct
52 Correct 6 ms 640 KB Output is correct
53 Correct 6 ms 640 KB Output is correct
54 Correct 6 ms 640 KB Output is correct
55 Correct 4 ms 512 KB Output is correct
56 Correct 3 ms 512 KB Output is correct
57 Correct 8 ms 520 KB Output is correct
58 Correct 7 ms 512 KB Output is correct
59 Correct 7 ms 512 KB Output is correct
60 Correct 8 ms 512 KB Output is correct
61 Correct 34 ms 1756 KB Output is correct
62 Correct 21 ms 1792 KB Output is correct
63 Correct 138 ms 6648 KB Output is correct
64 Correct 176 ms 6592 KB Output is correct
65 Correct 143 ms 3192 KB Output is correct
66 Correct 136 ms 3192 KB Output is correct
67 Correct 0 ms 384 KB Output is correct
68 Correct 0 ms 256 KB Output is correct
69 Correct 221 ms 7288 KB Output is correct
70 Correct 135 ms 5728 KB Output is correct
71 Correct 143 ms 5752 KB Output is correct
72 Correct 139 ms 6648 KB Output is correct
73 Correct 149 ms 6520 KB Output is correct