#include <iostream>
#include <bits/stdc++.h>
#define lli long long int
#define RBit _Rb_tree_iterator<pair<const pair<lli, lli>, int>>
using namespace std;
long long int a, b, c;
lli ab(lli n) {
return n < 0 ? -n : n;
}
lli ggt(lli x, lli y) {
return x == 0 ? y : ggt(y % x, x);
}
pair<lli, lli> toPoint(lli tX, lli tY, lli tZ) {
//cout << tX << " " << tY << " " << tZ << "\n";
lli x, y;
if (a != 0) {
x = tY * a - tX * b; y = tZ * a - tX * c;
} else if (b != 0) {
x = tX * b - tY * a; y = tZ * b - tY * c;
} else {
x = tX * c - tZ * a; y = tY * c - tZ * b;
}
lli d = ab(ggt(x, y));
//cout << x << " " << y << "\n";
if (d == 0) return {0, 0};
x /= d;
y /= d;
return {x, y};
}
pair<lli, lli> inverse(pair<lli, lli> p) {
return {- p.first, - p.second};
}
struct cmp {
bool operator()(const pair<lli, lli>& pA, const pair<lli, lli>& pB) const {
if (pA.first >= 0 && pB.first < 0) return true;
if (pB.first >= 0 && pA.first < 0) return false;
if (pA.first == 0 && pB.first == 0) return pA.second > pB.second;
return pA.second * pB.first > pB.second * pA.first;
}
};
/*
ostream& operator << (ostream& io, const pair<lli, lli>& p) {
io << p.first << " " << p.second;
return io;
}
ostream& operator << (ostream& io, const pair<pair<lli, lli>, int>& p) {
io << p.first << " x " << p.second << "\n";
return io;
}
*/
bool okay(map<pair<lli, lli>, int, cmp> circle) {
if (circle.empty()) return false;
RBit it = circle.begin();
RBit inv = circle.upper_bound(inverse((*it).first));
if (circle.end() == inv) inv = circle.begin();
RBit invinv = circle.upper_bound(inverse((*inv).first));
if (circle.end() == invinv) invinv = circle.begin();
return it != inv && inv != invinv;
}
int main() {
//long long int t = chrono::system_clock::now().time_since_epoch().count();
cin >> a >> b >> c;
int n = 0, d = 0;
pair<lli, lli> p;
vector<pair<lli, lli>> regal;
map<pair<lli, lli>, int, cmp> circle;
int q;
cin >> q;
string inst;
int pos;
long long int x, y, z;
lli ele, inv;
for (int i = 0; i < q; ++i) {
//cout << i << "\n";
cin >> inst;
if (inst == "A") {
cin >> x >> y >> z;
p = toPoint(x, y, z);
/*
cout << "\n";
cout << x << " " << y << " " << z << "\n";
cout << p;
cout << "\n\n";
*/
/*
cout << "adding\n";
cout << p;
cout << "\n";
*/
ele = (circle[p]);
inv = (circle[inverse(p)]);
if (ele > 0 && inv > 0) d--;
regal.push_back(p);
if (p.first == 0 && p.second == 0) n++; else {
ele++;
}
/*
cout << "dtest\n";
cout << *circle.end();
cout << circle[p] << "\n";
cout << *circle.find(p);
cout << p << "\n";
cout << *circle.find(inv);
cout << inv << "\n";
*/
if (ele > 0 && inv > 0) d++;
circle[p] = ele;
}
if (inst == "R") {
cin >> pos;
p = regal[pos - 1];
ele = (circle[p]);
inv = (circle[inverse(p)]);
if (ele > 0 && inv > 0) d--;
if (p.first == 0 && p.second == 0) n--; else {
ele--;
}
if (ele > 0 && inv > 0) d++;
circle[p] = ele;
}
if (circle[p] == 0) circle.erase(p);
if (circle[inverse(p)] == 0) circle.erase(inverse(p));
/*
cout << "0 0 x " << n << "\n";
for (pair<pair<lli, lli>, int> j: circle) cout << j;
cout << "\n";
*/
if (n > 0) {
cout << 1;
} else {
if (d > 0) {
cout << 2;
} else {
if (okay(circle)) {
cout << 3;
} else {
cout << 0;
}
}
}
cout << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
296 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
292 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
288 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
292 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
292 KB |
Output is correct |
15 |
Correct |
1 ms |
288 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
296 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
292 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
288 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
292 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
292 KB |
Output is correct |
15 |
Correct |
1 ms |
288 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
2 ms |
300 KB |
Output is correct |
23 |
Correct |
2 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
26 |
Correct |
2 ms |
332 KB |
Output is correct |
27 |
Correct |
3 ms |
296 KB |
Output is correct |
28 |
Correct |
2 ms |
204 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
1 ms |
204 KB |
Output is correct |
31 |
Correct |
1 ms |
204 KB |
Output is correct |
32 |
Correct |
2 ms |
332 KB |
Output is correct |
33 |
Correct |
2 ms |
300 KB |
Output is correct |
34 |
Correct |
5 ms |
332 KB |
Output is correct |
35 |
Correct |
2 ms |
204 KB |
Output is correct |
36 |
Correct |
2 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
296 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
292 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
288 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
292 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
292 KB |
Output is correct |
15 |
Correct |
1 ms |
288 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
2 ms |
300 KB |
Output is correct |
23 |
Correct |
2 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
26 |
Correct |
2 ms |
332 KB |
Output is correct |
27 |
Correct |
3 ms |
296 KB |
Output is correct |
28 |
Correct |
2 ms |
204 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
1 ms |
204 KB |
Output is correct |
31 |
Correct |
1 ms |
204 KB |
Output is correct |
32 |
Correct |
2 ms |
332 KB |
Output is correct |
33 |
Correct |
2 ms |
300 KB |
Output is correct |
34 |
Correct |
5 ms |
332 KB |
Output is correct |
35 |
Correct |
2 ms |
204 KB |
Output is correct |
36 |
Correct |
2 ms |
204 KB |
Output is correct |
37 |
Correct |
3 ms |
296 KB |
Output is correct |
38 |
Correct |
3 ms |
216 KB |
Output is correct |
39 |
Correct |
3 ms |
276 KB |
Output is correct |
40 |
Correct |
11 ms |
332 KB |
Output is correct |
41 |
Correct |
10 ms |
348 KB |
Output is correct |
42 |
Correct |
10 ms |
332 KB |
Output is correct |
43 |
Correct |
8 ms |
332 KB |
Output is correct |
44 |
Correct |
8 ms |
332 KB |
Output is correct |
45 |
Correct |
7 ms |
332 KB |
Output is correct |
46 |
Correct |
11 ms |
436 KB |
Output is correct |
47 |
Correct |
56 ms |
480 KB |
Output is correct |
48 |
Correct |
7 ms |
332 KB |
Output is correct |
49 |
Correct |
12 ms |
392 KB |
Output is correct |
50 |
Correct |
11 ms |
304 KB |
Output is correct |
51 |
Correct |
174 ms |
548 KB |
Output is correct |
52 |
Correct |
16 ms |
532 KB |
Output is correct |
53 |
Correct |
242 ms |
636 KB |
Output is correct |
54 |
Correct |
238 ms |
644 KB |
Output is correct |
55 |
Correct |
10 ms |
460 KB |
Output is correct |
56 |
Correct |
11 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
296 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
292 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
288 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
292 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
292 KB |
Output is correct |
15 |
Correct |
1 ms |
288 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
2 ms |
300 KB |
Output is correct |
23 |
Correct |
2 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
26 |
Correct |
2 ms |
332 KB |
Output is correct |
27 |
Correct |
3 ms |
296 KB |
Output is correct |
28 |
Correct |
2 ms |
204 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
1 ms |
204 KB |
Output is correct |
31 |
Correct |
1 ms |
204 KB |
Output is correct |
32 |
Correct |
2 ms |
332 KB |
Output is correct |
33 |
Correct |
2 ms |
300 KB |
Output is correct |
34 |
Correct |
5 ms |
332 KB |
Output is correct |
35 |
Correct |
2 ms |
204 KB |
Output is correct |
36 |
Correct |
2 ms |
204 KB |
Output is correct |
37 |
Correct |
3 ms |
296 KB |
Output is correct |
38 |
Correct |
3 ms |
216 KB |
Output is correct |
39 |
Correct |
3 ms |
276 KB |
Output is correct |
40 |
Correct |
11 ms |
332 KB |
Output is correct |
41 |
Correct |
10 ms |
348 KB |
Output is correct |
42 |
Correct |
10 ms |
332 KB |
Output is correct |
43 |
Correct |
8 ms |
332 KB |
Output is correct |
44 |
Correct |
8 ms |
332 KB |
Output is correct |
45 |
Correct |
7 ms |
332 KB |
Output is correct |
46 |
Correct |
11 ms |
436 KB |
Output is correct |
47 |
Correct |
56 ms |
480 KB |
Output is correct |
48 |
Correct |
7 ms |
332 KB |
Output is correct |
49 |
Correct |
12 ms |
392 KB |
Output is correct |
50 |
Correct |
11 ms |
304 KB |
Output is correct |
51 |
Correct |
174 ms |
548 KB |
Output is correct |
52 |
Correct |
16 ms |
532 KB |
Output is correct |
53 |
Correct |
242 ms |
636 KB |
Output is correct |
54 |
Correct |
238 ms |
644 KB |
Output is correct |
55 |
Correct |
10 ms |
460 KB |
Output is correct |
56 |
Correct |
11 ms |
460 KB |
Output is correct |
57 |
Correct |
18 ms |
580 KB |
Output is correct |
58 |
Correct |
194 ms |
632 KB |
Output is correct |
59 |
Correct |
247 ms |
756 KB |
Output is correct |
60 |
Correct |
18 ms |
544 KB |
Output is correct |
61 |
Correct |
52 ms |
1320 KB |
Output is correct |
62 |
Correct |
61 ms |
1360 KB |
Output is correct |
63 |
Execution timed out |
2082 ms |
1836 KB |
Time limit exceeded |
64 |
Halted |
0 ms |
0 KB |
- |