chore: updated problem constraints and improved tests coverage.
This commit is contained in:
@@ -13,6 +13,8 @@ long long countDominantPairs(int l, int r) {
|
||||
|
||||
int mid = (l + r)/2;
|
||||
long long count = countDominantPairs(l, mid) + countDominantPairs(mid + 1, r);
|
||||
|
||||
if (points[mid].first == points[mid + 1].first) {}
|
||||
|
||||
vector<pair<long long, long long>> temp(r - l + 1);
|
||||
int i = l, j = mid + 1, k = 0;
|
||||
@@ -20,10 +22,10 @@ long long countDominantPairs(int l, int r) {
|
||||
auto [x_a, y_a] = points[i];
|
||||
auto [x_b, y_b] = points[j];
|
||||
|
||||
if (y_a < y_b) {
|
||||
if (y_a <= y_b) {
|
||||
temp[k++] = points[i++];
|
||||
} else { // y_a > y_b -> point B is dominated by all placed points from left side
|
||||
count += (i - l);
|
||||
if (points[j].first > points[i].first) count += (i - l);
|
||||
temp[k++] = points[j++];
|
||||
}
|
||||
}
|
||||
@@ -33,7 +35,9 @@ long long countDominantPairs(int l, int r) {
|
||||
}
|
||||
|
||||
while (j <= r) {
|
||||
count += (mid + 1 - l); // this point is dominated by all placed points from left side
|
||||
if (points[j].first > points[mid].first && points[j].second > points[mid].second) { // this point is dominated by all placed points from left side
|
||||
count += (mid + 1 - l);
|
||||
}
|
||||
temp[k++] = points[j++];
|
||||
}
|
||||
|
||||
|
||||
@@ -34,22 +34,17 @@ vector<string> generate_manual_tests() {
|
||||
tests.push_back(output_tc({{-1, 3}, {1, 1}, {2, 4}, {3, 2}, {4, 5}})); // expected answer is 7
|
||||
tests.push_back(output_tc({{3, -6}, {4, 9}, {9, -9}, {1, -7}, {-3, 2}})); // expected answer is 4
|
||||
tests.push_back(output_tc({{-1, -3}, {-2, -2}, {-3, -1}, {1, 3}, {2, 2}, {3, 1}})); // expected answer is 9
|
||||
tests.push_back(output_tc({{1, 1}, {1, 2}, {1, 3}, {1, 4}, {1, 5}, {1, 6}}));
|
||||
tests.push_back(output_tc({{1, 1}, {2, 1}, {3, 1}, {4, 1}, {5, 1}, {6, 1}}));
|
||||
return tests;
|
||||
}
|
||||
|
||||
vector<pair<int, int>> generate_random_points_array(int size) {
|
||||
set<int> usedX, usedY;
|
||||
vector<pair<int, int>> coords;
|
||||
|
||||
while (coords.size() < size) {
|
||||
vector<pair<int, int>> coords(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
int x = rnd.next(MIN_COORD, MAX_COORD);
|
||||
int y = rnd.next(MIN_COORD, MAX_COORD);
|
||||
|
||||
if (usedX.find(x) == usedX.end() && usedY.find(y) == usedY.end()) {
|
||||
usedX.insert(x);
|
||||
usedY.insert(y);
|
||||
coords.push_back({x, y});
|
||||
}
|
||||
coords[i] = {x, y};
|
||||
}
|
||||
return coords;
|
||||
}
|
||||
@@ -81,9 +76,36 @@ string extreme_test_1(){
|
||||
return(output_tc(generate_random_points_array(MAX_N)));
|
||||
}
|
||||
|
||||
string extreme_test_2(){
|
||||
vector<pair<int, int>> coords(MAX_N);
|
||||
for (int i = 0; i < MAX_N; i++) {
|
||||
coords[i] = {i, i};
|
||||
}
|
||||
return(output_tc(coords));
|
||||
}
|
||||
|
||||
string extreme_test_3(){
|
||||
vector<pair<int, int>> coords(MAX_N);
|
||||
for (int i = 0; i < MAX_N; i++) {
|
||||
coords[i] = {i, 0};
|
||||
}
|
||||
return(output_tc(coords));
|
||||
}
|
||||
|
||||
string extreme_test_4(){
|
||||
vector<pair<int, int>> coords(MAX_N);
|
||||
for (int i = 0; i < MAX_N; i++) {
|
||||
coords[i] = {0, i};
|
||||
}
|
||||
return(output_tc(coords));
|
||||
}
|
||||
|
||||
vector<string> generate_extreme_tests(){
|
||||
vector<string> tests;
|
||||
vector<string> tests;
|
||||
tests.push_back(extreme_test_1());
|
||||
tests.push_back(extreme_test_2());
|
||||
tests.push_back(extreme_test_3());
|
||||
tests.push_back(extreme_test_4());
|
||||
return tests;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,16 +12,11 @@ int main(int argc, char* argv[]) {
|
||||
registerValidation(argc, argv);
|
||||
int n = inf.readInt(MIN_N, MAX_N, "n");
|
||||
inf.readEoln();
|
||||
unordered_set<int> seenX, seenY;
|
||||
for (int i = 0; i < n; i++) {
|
||||
int x = inf.readInt(MIN_COORD, MAX_COORD, "xi");
|
||||
inf.readSpace();
|
||||
int y = inf.readInt(MIN_COORD, MAX_COORD, "yi");
|
||||
inf.readEoln();
|
||||
ensuref(seenX.count(x) == 0, "Repeated point X coordinate is not allowed");
|
||||
ensuref(seenY.count(y) == 0, "Repeated point Y coordinate is not allowed");
|
||||
seenX.insert(x);
|
||||
seenY.insert(y);
|
||||
}
|
||||
inf.readEof();
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user