import java.io.*;
import java.util.*;
public class Mixture {
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
String str;
String[] params;
str = br.readLine();
params = str.split(" ");
long S = Integer.parseInt(params[0]);
long P = Integer.parseInt(params[1]);
long G = Integer.parseInt(params[2]);
str = br.readLine();
int N = Integer.parseInt(str);
ArrayList<Vector> data = new ArrayList<>(N);
TreeSet<Vector> set = new TreeSet<>();
long amountOfDots = 0;
long amountOfLines = 0;
long amountOfEmptyPies = 1;
for (int i = 0; i < N; i++) {
str = br.readLine();
params = str.split(" ");
if (params[0].equals("A")) {
long s = Integer.parseInt(params[1]);
long p = Integer.parseInt(params[2]);
long g = Integer.parseInt(params[3]);
long x = s * (S + P + G) - S * (s + p + g);
long y = p * (S + P + G) - P * (s + p + g);
if ((x == 0) && (y == 0)) {
data.add(new Vector(0, 0));
amountOfDots++;
} else {
long mult = s + p + g;
Vector cur = new Vector(mult * x, mult * y);
data.add(cur);
Vector existing = set.ceiling(cur);
if ((existing != null) && (existing.compareTo(cur) == 0)) {
existing.setCount(existing.getCount() + 1);
} else {
Vector same = set.ceiling(cur);
Vector opposite = set.ceiling(cur.negate());
if (((same == null) || (same.compareTo(cur) != 0))
&& ((opposite != null) && (opposite.compareTo(cur.negate()) == 0))) {
amountOfLines++;
}
if (set.size() >= 2) {
Vector prev = Optional.ofNullable(set.lower(cur)).orElse(set.last());
Vector next = Optional.ofNullable(set.higher(cur)).orElse(set.first());
if ((crossProductResult(prev, next) > 0)
&& (crossProductResult(prev, cur) <= 0)
&& (crossProductResult(cur, next) <= 0)) {
amountOfEmptyPies = 0;
}
} else {
amountOfEmptyPies = 1;
}
set.add(cur);
}
}
} else {
int ind = Integer.parseInt(params[1]);
Vector cur = data.get(ind - 1);
if ((cur.getPart() == -1)) {
amountOfDots--;
} else {
Vector existing = set.ceiling(cur);
if (existing.getCount() > 1) {
existing.setCount(existing.getCount() - 1);
} else {
set.remove(cur);
Vector same = set.ceiling(cur);
Vector opposite = set.ceiling(cur.negate());
if (((same == null) || (same.compareTo(cur) != 0))
&& ((opposite != null) && (opposite.compareTo(cur.negate()) == 0))) {
amountOfLines--;
}
if (set.size() >= 2) {
Vector prev = Optional.ofNullable(set.lower(cur)).orElse(set.last());
Vector next = Optional.ofNullable(set.higher(cur)).orElse(set.first());
if (crossProductResult(prev, next) > 0) {
amountOfEmptyPies = 1;
}
} else {
amountOfEmptyPies = 1;
}
}
}
}
if (amountOfDots > 0) {
bw.write("1\n");
} else if (amountOfLines > 0) {
bw.write("2\n");
} else if (amountOfEmptyPies == 0) {
bw.write("3\n");
} else {
bw.write("0\n");
}
}
bw.close();
}
private static class Vector implements Comparable<Vector> {
private final long x, y;
// -1 = 0-vector
// 0 = [0; pi)
// 1 = [pi; 2pi)
private final int part;
private int count = 1;
public Vector(long x, long y) {
this.x = x;
this.y = y;
if (x == 0) {
if (y > 0) {
this.part = 0;
} else if (y < 0) {
this.part = 1;
} else {
this.part = -1;
}
} else if (x > 0) {
this.part = 0;
} else {
this.part = 1;
}
}
public long getX() {
return x;
}
public long getY() {
return y;
}
public Integer getPart() {
return part;
}
public Vector negate() {
return new Vector(-x, -y);
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
@Override
public int compareTo(Vector o) {
int result = this.getPart().compareTo(o.getPart());
if (result == 0) {
result = crossProductResult(this, o);
}
return result;
}
}
private static int crossProductResult(Vector a, Vector b) {
/*
return BigInteger.valueOf(a.getX()).multiply(BigInteger.valueOf(b.getY()))
.compareTo(BigInteger.valueOf(a.getY()).multiply(BigInteger.valueOf(b.getX())));
*/
long MOD = 1L << 31;
long p0 = (b.y % MOD) * (a.x % MOD);
long p1 = (b.y % MOD) * (a.x / MOD) + (a.x % MOD) * (b.y / MOD);
long p2 = (a.x / MOD) * (b.y / MOD);
long p3 = 0;
p1 += p0 / MOD;
p0 %= MOD;
p2 += p1 / MOD;
p1 %= MOD;
p3 += p2 / MOD;
p2 %= MOD;
long q0 = (b.x % MOD) * (a.y % MOD);
long q1 = (b.x % MOD) * (a.y / MOD) + (a.y % MOD) * (b.x / MOD);
long q2 = (a.y / MOD) * (b.x / MOD);
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;
}
}
}
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
10352 KB |
Output is correct |
2 |
Correct |
75 ms |
10472 KB |
Output is correct |
3 |
Correct |
89 ms |
10488 KB |
Output is correct |
4 |
Correct |
79 ms |
10464 KB |
Output is correct |
5 |
Correct |
74 ms |
10228 KB |
Output is correct |
6 |
Correct |
83 ms |
10132 KB |
Output is correct |
7 |
Correct |
80 ms |
10484 KB |
Output is correct |
8 |
Correct |
80 ms |
10356 KB |
Output is correct |
9 |
Correct |
77 ms |
10364 KB |
Output is correct |
10 |
Correct |
79 ms |
10360 KB |
Output is correct |
11 |
Correct |
76 ms |
10360 KB |
Output is correct |
12 |
Correct |
76 ms |
10464 KB |
Output is correct |
13 |
Correct |
81 ms |
10360 KB |
Output is correct |
14 |
Correct |
79 ms |
10360 KB |
Output is correct |
15 |
Correct |
74 ms |
10480 KB |
Output is correct |
16 |
Correct |
75 ms |
10468 KB |
Output is correct |
17 |
Correct |
92 ms |
10380 KB |
Output is correct |
18 |
Correct |
79 ms |
10480 KB |
Output is correct |
19 |
Correct |
98 ms |
10528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
10352 KB |
Output is correct |
2 |
Correct |
75 ms |
10472 KB |
Output is correct |
3 |
Correct |
89 ms |
10488 KB |
Output is correct |
4 |
Correct |
79 ms |
10464 KB |
Output is correct |
5 |
Correct |
74 ms |
10228 KB |
Output is correct |
6 |
Correct |
83 ms |
10132 KB |
Output is correct |
7 |
Correct |
80 ms |
10484 KB |
Output is correct |
8 |
Correct |
80 ms |
10356 KB |
Output is correct |
9 |
Correct |
77 ms |
10364 KB |
Output is correct |
10 |
Correct |
79 ms |
10360 KB |
Output is correct |
11 |
Correct |
76 ms |
10360 KB |
Output is correct |
12 |
Correct |
76 ms |
10464 KB |
Output is correct |
13 |
Correct |
81 ms |
10360 KB |
Output is correct |
14 |
Correct |
79 ms |
10360 KB |
Output is correct |
15 |
Correct |
74 ms |
10480 KB |
Output is correct |
16 |
Correct |
75 ms |
10468 KB |
Output is correct |
17 |
Correct |
92 ms |
10380 KB |
Output is correct |
18 |
Correct |
79 ms |
10480 KB |
Output is correct |
19 |
Correct |
98 ms |
10528 KB |
Output is correct |
20 |
Correct |
89 ms |
10728 KB |
Output is correct |
21 |
Correct |
93 ms |
10620 KB |
Output is correct |
22 |
Correct |
95 ms |
10992 KB |
Output is correct |
23 |
Correct |
121 ms |
12904 KB |
Output is correct |
24 |
Correct |
89 ms |
10852 KB |
Output is correct |
25 |
Correct |
98 ms |
10996 KB |
Output is correct |
26 |
Correct |
94 ms |
10876 KB |
Output is correct |
27 |
Correct |
101 ms |
11240 KB |
Output is correct |
28 |
Correct |
96 ms |
10872 KB |
Output is correct |
29 |
Correct |
98 ms |
11148 KB |
Output is correct |
30 |
Correct |
102 ms |
11568 KB |
Output is correct |
31 |
Correct |
87 ms |
11112 KB |
Output is correct |
32 |
Correct |
117 ms |
12524 KB |
Output is correct |
33 |
Correct |
92 ms |
10984 KB |
Output is correct |
34 |
Correct |
115 ms |
11856 KB |
Output is correct |
35 |
Correct |
110 ms |
11892 KB |
Output is correct |
36 |
Correct |
104 ms |
11624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
10352 KB |
Output is correct |
2 |
Correct |
75 ms |
10472 KB |
Output is correct |
3 |
Correct |
89 ms |
10488 KB |
Output is correct |
4 |
Correct |
79 ms |
10464 KB |
Output is correct |
5 |
Correct |
74 ms |
10228 KB |
Output is correct |
6 |
Correct |
83 ms |
10132 KB |
Output is correct |
7 |
Correct |
80 ms |
10484 KB |
Output is correct |
8 |
Correct |
80 ms |
10356 KB |
Output is correct |
9 |
Correct |
77 ms |
10364 KB |
Output is correct |
10 |
Correct |
79 ms |
10360 KB |
Output is correct |
11 |
Correct |
76 ms |
10360 KB |
Output is correct |
12 |
Correct |
76 ms |
10464 KB |
Output is correct |
13 |
Correct |
81 ms |
10360 KB |
Output is correct |
14 |
Correct |
79 ms |
10360 KB |
Output is correct |
15 |
Correct |
74 ms |
10480 KB |
Output is correct |
16 |
Correct |
75 ms |
10468 KB |
Output is correct |
17 |
Correct |
92 ms |
10380 KB |
Output is correct |
18 |
Correct |
79 ms |
10480 KB |
Output is correct |
19 |
Correct |
98 ms |
10528 KB |
Output is correct |
20 |
Correct |
89 ms |
10728 KB |
Output is correct |
21 |
Correct |
93 ms |
10620 KB |
Output is correct |
22 |
Correct |
95 ms |
10992 KB |
Output is correct |
23 |
Correct |
121 ms |
12904 KB |
Output is correct |
24 |
Correct |
89 ms |
10852 KB |
Output is correct |
25 |
Correct |
98 ms |
10996 KB |
Output is correct |
26 |
Correct |
94 ms |
10876 KB |
Output is correct |
27 |
Correct |
101 ms |
11240 KB |
Output is correct |
28 |
Correct |
96 ms |
10872 KB |
Output is correct |
29 |
Correct |
98 ms |
11148 KB |
Output is correct |
30 |
Correct |
102 ms |
11568 KB |
Output is correct |
31 |
Correct |
87 ms |
11112 KB |
Output is correct |
32 |
Correct |
117 ms |
12524 KB |
Output is correct |
33 |
Correct |
92 ms |
10984 KB |
Output is correct |
34 |
Correct |
115 ms |
11856 KB |
Output is correct |
35 |
Correct |
110 ms |
11892 KB |
Output is correct |
36 |
Correct |
104 ms |
11624 KB |
Output is correct |
37 |
Correct |
135 ms |
12432 KB |
Output is correct |
38 |
Correct |
132 ms |
12516 KB |
Output is correct |
39 |
Correct |
143 ms |
12448 KB |
Output is correct |
40 |
Correct |
141 ms |
12392 KB |
Output is correct |
41 |
Correct |
145 ms |
12152 KB |
Output is correct |
42 |
Correct |
140 ms |
12776 KB |
Output is correct |
43 |
Correct |
168 ms |
12968 KB |
Output is correct |
44 |
Correct |
155 ms |
12912 KB |
Output is correct |
45 |
Correct |
168 ms |
12752 KB |
Output is correct |
46 |
Correct |
273 ms |
16972 KB |
Output is correct |
47 |
Correct |
246 ms |
15904 KB |
Output is correct |
48 |
Correct |
203 ms |
15184 KB |
Output is correct |
49 |
Correct |
209 ms |
14608 KB |
Output is correct |
50 |
Correct |
211 ms |
15500 KB |
Output is correct |
51 |
Correct |
245 ms |
16504 KB |
Output is correct |
52 |
Correct |
230 ms |
17436 KB |
Output is correct |
53 |
Correct |
317 ms |
17852 KB |
Output is correct |
54 |
Correct |
268 ms |
18708 KB |
Output is correct |
55 |
Correct |
193 ms |
15724 KB |
Output is correct |
56 |
Correct |
186 ms |
15404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
10352 KB |
Output is correct |
2 |
Correct |
75 ms |
10472 KB |
Output is correct |
3 |
Correct |
89 ms |
10488 KB |
Output is correct |
4 |
Correct |
79 ms |
10464 KB |
Output is correct |
5 |
Correct |
74 ms |
10228 KB |
Output is correct |
6 |
Correct |
83 ms |
10132 KB |
Output is correct |
7 |
Correct |
80 ms |
10484 KB |
Output is correct |
8 |
Correct |
80 ms |
10356 KB |
Output is correct |
9 |
Correct |
77 ms |
10364 KB |
Output is correct |
10 |
Correct |
79 ms |
10360 KB |
Output is correct |
11 |
Correct |
76 ms |
10360 KB |
Output is correct |
12 |
Correct |
76 ms |
10464 KB |
Output is correct |
13 |
Correct |
81 ms |
10360 KB |
Output is correct |
14 |
Correct |
79 ms |
10360 KB |
Output is correct |
15 |
Correct |
74 ms |
10480 KB |
Output is correct |
16 |
Correct |
75 ms |
10468 KB |
Output is correct |
17 |
Correct |
92 ms |
10380 KB |
Output is correct |
18 |
Correct |
79 ms |
10480 KB |
Output is correct |
19 |
Correct |
98 ms |
10528 KB |
Output is correct |
20 |
Correct |
89 ms |
10728 KB |
Output is correct |
21 |
Correct |
93 ms |
10620 KB |
Output is correct |
22 |
Correct |
95 ms |
10992 KB |
Output is correct |
23 |
Correct |
121 ms |
12904 KB |
Output is correct |
24 |
Correct |
89 ms |
10852 KB |
Output is correct |
25 |
Correct |
98 ms |
10996 KB |
Output is correct |
26 |
Correct |
94 ms |
10876 KB |
Output is correct |
27 |
Correct |
101 ms |
11240 KB |
Output is correct |
28 |
Correct |
96 ms |
10872 KB |
Output is correct |
29 |
Correct |
98 ms |
11148 KB |
Output is correct |
30 |
Correct |
102 ms |
11568 KB |
Output is correct |
31 |
Correct |
87 ms |
11112 KB |
Output is correct |
32 |
Correct |
117 ms |
12524 KB |
Output is correct |
33 |
Correct |
92 ms |
10984 KB |
Output is correct |
34 |
Correct |
115 ms |
11856 KB |
Output is correct |
35 |
Correct |
110 ms |
11892 KB |
Output is correct |
36 |
Correct |
104 ms |
11624 KB |
Output is correct |
37 |
Correct |
135 ms |
12432 KB |
Output is correct |
38 |
Correct |
132 ms |
12516 KB |
Output is correct |
39 |
Correct |
143 ms |
12448 KB |
Output is correct |
40 |
Correct |
141 ms |
12392 KB |
Output is correct |
41 |
Correct |
145 ms |
12152 KB |
Output is correct |
42 |
Correct |
140 ms |
12776 KB |
Output is correct |
43 |
Correct |
168 ms |
12968 KB |
Output is correct |
44 |
Correct |
155 ms |
12912 KB |
Output is correct |
45 |
Correct |
168 ms |
12752 KB |
Output is correct |
46 |
Correct |
273 ms |
16972 KB |
Output is correct |
47 |
Correct |
246 ms |
15904 KB |
Output is correct |
48 |
Correct |
203 ms |
15184 KB |
Output is correct |
49 |
Correct |
209 ms |
14608 KB |
Output is correct |
50 |
Correct |
211 ms |
15500 KB |
Output is correct |
51 |
Correct |
245 ms |
16504 KB |
Output is correct |
52 |
Correct |
230 ms |
17436 KB |
Output is correct |
53 |
Correct |
317 ms |
17852 KB |
Output is correct |
54 |
Correct |
268 ms |
18708 KB |
Output is correct |
55 |
Correct |
193 ms |
15724 KB |
Output is correct |
56 |
Correct |
186 ms |
15404 KB |
Output is correct |
57 |
Correct |
257 ms |
17572 KB |
Output is correct |
58 |
Correct |
406 ms |
20196 KB |
Output is correct |
59 |
Correct |
408 ms |
19840 KB |
Output is correct |
60 |
Correct |
357 ms |
19616 KB |
Output is correct |
61 |
Correct |
465 ms |
27280 KB |
Output is correct |
62 |
Correct |
333 ms |
26008 KB |
Output is correct |
63 |
Correct |
1320 ms |
55324 KB |
Output is correct |
64 |
Correct |
1238 ms |
54792 KB |
Output is correct |
65 |
Correct |
1397 ms |
54244 KB |
Output is correct |
66 |
Correct |
1386 ms |
55412 KB |
Output is correct |
67 |
Correct |
82 ms |
10392 KB |
Output is correct |
68 |
Correct |
83 ms |
10248 KB |
Output is correct |
69 |
Correct |
1448 ms |
55436 KB |
Output is correct |
70 |
Correct |
1370 ms |
55436 KB |
Output is correct |
71 |
Correct |
1387 ms |
55168 KB |
Output is correct |
72 |
Correct |
1122 ms |
54776 KB |
Output is correct |
73 |
Correct |
1166 ms |
54640 KB |
Output is correct |