#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;
//#ifndef DLOCAL
// #define cin fin
// #define cout fout
// ifstream cin(".in");
// ofstream cout(".out");
//#endif
using ll = long long;
using ld = long double;
//#define int ll
#define sz(x) ((int)(x).size())
using pii = pair<int,int>;
using tii = tuple<int,int,int>;
using point = pair<double,double>;
#define x first
#define y second
#define ERROR (-100)
const double PI = acos(-1);
const double eps = 1e-10;
double difference_(double start, double finish) {
start -= eps;
finish += eps;
if(start < finish) return finish - start;
return finish - start + 2 * PI;
}
static inline double reeps(double X) {
return X;
}
double angle(double A, double B) {
auto U = atan2(A, B);
if(U < 0) return reeps(2. * PI + U);
return reeps(U);
}
double flip(double angle) {
if(angle == ERROR) return ERROR;
return angle < PI? angle + PI : angle - PI;
}
template<typename T>
struct MP {
map<double, T> freq;
T& operator[](double a) {
auto it = freq.lower_bound(a - eps);
if(it != freq.end() && it -> first <= a + eps) return freq[it -> first];
return freq[a];
}
};
struct AdjacentDifferences {
multiset<double> angles;
multiset<double>::iterator before(multiset<double>::iterator it) {
if(it == angles.begin()) return prev(angles.end());
return prev(it);
}
multiset<double>::iterator after(multiset<double>::iterator it) {
if(next(it) == angles.end()) return angles.begin();
return next(it);
}
double difference(multiset<double>::iterator L, multiset<double>::iterator R) {
//cerr << difference_(*L, *R) << '\n';
if(R == angles.begin() && abs(*L - *R) <= eps) return 2 * PI;
return difference_(*L, *R);
}
multiset<double> differences;
pair<double, double> jump = pair<double, double>{ERROR, ERROR};
void insert(double U) {
auto it = angles.insert(U), L = before(it), R = after(it);
if(angles.size() >= 3) {
if(difference(L, R) > PI) jump = make_pair(ERROR, ERROR);
}
if(angles.size() >= 2) {
if(difference(L, it) > PI) jump = make_pair(*L, *it);
if(difference(it, R) > PI) jump = make_pair(*it, *R);
}
}
void erase(double U) {
auto it = angles.find(U), L = before(it), R = after(it);
if(angles.size() >= 2) {
if(difference(L, it) > PI) jump = make_pair(ERROR, ERROR);
if(difference(it, R) > PI) jump = make_pair(ERROR, ERROR);
}
angles.erase(it);
if(angles.size() >= 2) {
if(difference(L, R) > PI) jump = make_pair(*L, *R);
}
}
bool count(double L, double R) {
if(L == ERROR || R == ERROR) return 0;
if(L > R) return count(L, 2 * PI) || count(0, R);
auto it = angles.lower_bound(L - eps);
if(it != angles.end() && *it <= R + eps) return 1;
return 0;
}
};
namespace DS {
int cnt_0;
MP<pii> freq;
MP<int> point_freq, vector_freq;
AdjacentDifferences point_adjdif, vector_adjdif;
int paired_with_vector = 0;
int ok_pairs = 0;
void insert(point a) {
if(a.x == 0 && a.y == 0) cnt_0++;
else {
double U = angle(a.y, a.x);
//cerr << "\t + point " << U << '\n';
point_adjdif.insert(U);
double link = (U < PI? U : U - PI);
bool ready = 0;
if(freq[link].first * freq[link].second == 0) ready = 1;
if(U < PI) freq[U].first++;
else freq[U - PI].second++;
if(freq[link].first * freq[link].second != 0 && ready) ok_pairs++;
paired_with_vector += vector_freq[flip(U)];
point_freq[U]++;
}
}
void erase(point a) {
if(a.x == 0 && a.y == 0) cnt_0--;
else {
double U = angle(a.y, a.x);
point_adjdif.erase(U);
double link = (U < PI? U : U - PI);
bool ready = 0;
if(freq[link].first * freq[link].second != 0) ready = 1;
if(U < PI) freq[U].first--;
else freq[U - PI].second--;
if(freq[link].first * freq[link].second == 0 && ready) ok_pairs--;
paired_with_vector -= vector_freq[flip(U)];
point_freq[U]--;
}
}
void insert_vector(point a) {
double U = angle(a.y, a.x);
//cerr << "\t + vector " << U << '\n';
vector_adjdif.insert(U);
paired_with_vector += point_freq[flip(U)];
vector_freq[U]++;
return;
}
void erase_vector(point a) {
double U = angle(a.y, a.x);
vector_adjdif.erase(U);
paired_with_vector -= point_freq[flip(U)];
vector_freq[U]--;
return;
}
int query() {
//cerr << '\t' << angles.size() << '\n';
if(cnt_0) return 1;
if(ok_pairs) return 2;
if(paired_with_vector) return 2;
auto [l, r] = point_adjdif.jump;
//cerr << l << ' ' << r << '\t';
//for(auto x : point_adjdif.angles) cerr << x << ' ';
//cerr << '\n';
if(point_adjdif.jump.first == ERROR && sz(point_adjdif.angles) >= 3) return 3;
if(vector_adjdif.jump.second == ERROR && sz(vector_adjdif.angles) >= 3) return 3;
//auto [l, r] = point_adjdif.jump;
//cerr << l << ' ' << r << '\n';
l = flip(l);
r = flip(r);
swap(l, r);
if(vector_adjdif.count(l, r)) return 3;
//cerr << l << ' ' << r << '\n';
tie(l, r) = vector_adjdif.jump;
l = flip(l);
r = flip(r);
swap(l, r);
if(point_adjdif.count(l, r)) return 3;
return 0;
}
}
signed main() {
cin.tie(0) -> sync_with_stdio(0);
double a, b, c;
int este_zero = 0;
cin >> a >> b >> c;
point center;
double T[3] = {a, b, c};
vector<int> idx(3);
iota(all(idx), 0);
#ifndef DLOCAL
sort(all(idx), [&](int a, int b) { return T[a] > T[b]; });
#endif
a = T[idx[0]];
b = T[idx[1]];
c = T[idx[2]];
//cerr << a << ' ' << b << ' ' << c << '\n';
center.x = b / a;
center.y = c / a;
int n;
cin >> n;
vector<tuple<double, double, double>> v;
//if(este_zero == 0) {
vector<int> pula;
for(int i = 0; i < n; i++) {
char ch;
cin >> ch;
point here;
bool ebine = 1;
if(ch == 'R') {
int t;
cin >> t;
t--;
tie(a, b, c) = v[t];
}
else {
cin >> a >> b >> c;
T[0] = a, T[1] = b, T[2] = c;
a = T[idx[0]];
b = T[idx[1]];
c = T[idx[2]];
v.emplace_back(a, b, c);
}
if(a == 0) here.x = b, here.y = c;
else {
here.x = b / a - center.x;
here.y = c / a - center.y;
}
if(ch == 'R') {
if(a != 0)
DS::erase(here);
else
DS::erase_vector(here);
}
else {
if(a != 0)
DS::insert(here);
else
DS::insert_vector(here);
}
cout << DS::query() << '\n';
}
}
/**
Istenem! Nu poate fi real.
-- Surse verificate
*/
Compilation message
Mixture.cpp: In function 'int main()':
Mixture.cpp:254:15: warning: unused variable 'ebine' [-Wunused-variable]
254 | bool ebine = 1;
| ^~~~~
Mixture.cpp:223:8: warning: unused variable 'este_zero' [-Wunused-variable]
223 | int este_zero = 0;
| ^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
600 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
600 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
600 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
600 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
600 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
2 ms |
348 KB |
Output is correct |
39 |
Correct |
2 ms |
604 KB |
Output is correct |
40 |
Correct |
2 ms |
600 KB |
Output is correct |
41 |
Correct |
2 ms |
604 KB |
Output is correct |
42 |
Correct |
2 ms |
604 KB |
Output is correct |
43 |
Correct |
2 ms |
604 KB |
Output is correct |
44 |
Correct |
2 ms |
604 KB |
Output is correct |
45 |
Correct |
2 ms |
604 KB |
Output is correct |
46 |
Correct |
7 ms |
860 KB |
Output is correct |
47 |
Correct |
8 ms |
860 KB |
Output is correct |
48 |
Correct |
3 ms |
348 KB |
Output is correct |
49 |
Correct |
3 ms |
348 KB |
Output is correct |
50 |
Correct |
3 ms |
464 KB |
Output is correct |
51 |
Correct |
10 ms |
860 KB |
Output is correct |
52 |
Correct |
6 ms |
860 KB |
Output is correct |
53 |
Correct |
10 ms |
1116 KB |
Output is correct |
54 |
Correct |
10 ms |
1096 KB |
Output is correct |
55 |
Correct |
3 ms |
604 KB |
Output is correct |
56 |
Correct |
4 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
600 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
600 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
2 ms |
348 KB |
Output is correct |
39 |
Correct |
2 ms |
604 KB |
Output is correct |
40 |
Correct |
2 ms |
600 KB |
Output is correct |
41 |
Correct |
2 ms |
604 KB |
Output is correct |
42 |
Correct |
2 ms |
604 KB |
Output is correct |
43 |
Correct |
2 ms |
604 KB |
Output is correct |
44 |
Correct |
2 ms |
604 KB |
Output is correct |
45 |
Correct |
2 ms |
604 KB |
Output is correct |
46 |
Correct |
7 ms |
860 KB |
Output is correct |
47 |
Correct |
8 ms |
860 KB |
Output is correct |
48 |
Correct |
3 ms |
348 KB |
Output is correct |
49 |
Correct |
3 ms |
348 KB |
Output is correct |
50 |
Correct |
3 ms |
464 KB |
Output is correct |
51 |
Correct |
10 ms |
860 KB |
Output is correct |
52 |
Correct |
6 ms |
860 KB |
Output is correct |
53 |
Correct |
10 ms |
1116 KB |
Output is correct |
54 |
Correct |
10 ms |
1096 KB |
Output is correct |
55 |
Correct |
3 ms |
604 KB |
Output is correct |
56 |
Correct |
4 ms |
604 KB |
Output is correct |
57 |
Correct |
5 ms |
600 KB |
Output is correct |
58 |
Correct |
14 ms |
1332 KB |
Output is correct |
59 |
Correct |
13 ms |
1368 KB |
Output is correct |
60 |
Correct |
12 ms |
1112 KB |
Output is correct |
61 |
Correct |
18 ms |
1944 KB |
Output is correct |
62 |
Correct |
19 ms |
1716 KB |
Output is correct |
63 |
Correct |
288 ms |
15872 KB |
Output is correct |
64 |
Correct |
281 ms |
15760 KB |
Output is correct |
65 |
Correct |
285 ms |
12544 KB |
Output is correct |
66 |
Correct |
249 ms |
12552 KB |
Output is correct |
67 |
Correct |
0 ms |
344 KB |
Output is correct |
68 |
Correct |
0 ms |
348 KB |
Output is correct |
69 |
Correct |
375 ms |
22644 KB |
Output is correct |
70 |
Correct |
274 ms |
19776 KB |
Output is correct |
71 |
Correct |
279 ms |
18536 KB |
Output is correct |
72 |
Correct |
241 ms |
14596 KB |
Output is correct |
73 |
Correct |
283 ms |
16200 KB |
Output is correct |