| Task: | Järjestys |
| Sender: | Metabolix |
| Submission time: | 2025-09-07 10:16:30 +0300 |
| Language: | C++ (C++17) |
| Status: | READY |
| Result: | 30 |
| group | verdict | score |
|---|---|---|
| #1 | ACCEPTED | 10 |
| #2 | ACCEPTED | 10 |
| #3 | ACCEPTED | 10 |
| #4 | TIME LIMIT EXCEEDED | 0 |
| #5 | TIME LIMIT EXCEEDED | 0 |
| test | verdict | time | group | |
|---|---|---|---|---|
| #1 | ACCEPTED | 0.00 s | 1, 4, 5 | details |
| #2 | ACCEPTED | 0.00 s | 1, 4, 5 | details |
| #3 | ACCEPTED | 0.00 s | 1, 4, 5 | details |
| #4 | ACCEPTED | 0.00 s | 1, 4, 5 | details |
| #5 | ACCEPTED | 0.01 s | 1, 4, 5 | details |
| #6 | ACCEPTED | 0.01 s | 1, 2, 4, 5 | details |
| #7 | ACCEPTED | 0.00 s | 1, 3, 4, 5 | details |
| #8 | ACCEPTED | 0.00 s | 1, 4, 5 | details |
| #9 | ACCEPTED | 0.03 s | 2, 4, 5 | details |
| #10 | ACCEPTED | 0.03 s | 3, 4, 5 | details |
| #11 | TIME LIMIT EXCEEDED | -- | 4, 5 | details |
| #12 | TIME LIMIT EXCEEDED | -- | 4, 5 | details |
| #13 | TIME LIMIT EXCEEDED | -- | 4, 5 | details |
| #14 | TIME LIMIT EXCEEDED | -- | 4, 5 | details |
| #15 | ACCEPTED | 0.16 s | 2, 5 | details |
| #16 | ACCEPTED | 0.15 s | 3, 5 | details |
| #17 | TIME LIMIT EXCEEDED | -- | 5 | details |
| #18 | TIME LIMIT EXCEEDED | -- | 5 | details |
| #19 | TIME LIMIT EXCEEDED | -- | 5 | details |
| #20 | TIME LIMIT EXCEEDED | -- | 5 | details |
| #21 | TIME LIMIT EXCEEDED | -- | 5 | details |
| #22 | ACCEPTED | 0.16 s | 5 | details |
Compiler report
input/code.cpp: In lambda function:
input/code.cpp:127:42: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
127 | return count_downs(pos) == 0 && count_starts(0, pos - 1) > 0
| ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
input/code.cpp: In function 'int main()':
input/code.cpp:114:14: warning: variable 'count_ups' set but not used [-Wunused-but-set-variable]
114 | auto count_ups = [&](int pos) {
| ^~~~~~~~~Code
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
using namespace std;
class IntervalTree {
public:
IntervalTree(int size) : size(size) {
tree.resize(4 * size, 0);
}
void update(int idx, int value) {
update(1, 1, size, idx, value);
}
int query(int left, int right) {
return query(1, 1, size, left, right);
}
private:
int size;
vector<int> tree;
void update(int node, int start, int end, int idx, int value) {
if (start == end) {
tree[node] += value;
} else {
int mid = (start + end) / 2;
if (idx <= mid) {
update(2 * node, start, mid, idx, value);
} else {
update(2 * node + 1, mid + 1, end, idx, value);
}
tree[node] = tree[2 * node] + tree[2 * node + 1];
}
}
int query(int node, int start, int end, int left, int right) {
if (right < start || end < left) {
return 0;
}
if (left <= start && end <= right) {
return tree[node];
}
int mid = (start + end) / 2;
int p1 = query(2 * node, start, mid, left, right);
int p2 = query(2 * node + 1, mid + 1, end, left, right);
return p1 + p2;
}
};
struct Edge {
int x, y, x0, y0;
int low, high, depth = 0;
bool up, used = false;
};
int main() {
int t = 0;
cin >> t;
while (t--) {
int n = 0;
cin >> n;
vector<Edge> arr(n);
map<int, int> coord_map, reverse_map;
int lowest_coord = 1000000000;
for (int i = 0; i < n; i++) {
cin >> arr[i].x0 >> arr[i].y0;
lowest_coord = min({lowest_coord, arr[i].x0, arr[i].y0});
coord_map.insert({arr[i].y0, 0});
}
coord_map.insert({lowest_coord, 0});
int m = 0;
for (auto& coord : coord_map) {
coord.second = m++;
reverse_map[coord.second] = coord.first;
}
int lowest_x = m;
for (int i = 0; i < n; i++) {
auto iter = coord_map.upper_bound(arr[i].x0); // (iter->first > x0)
iter--; // (iter->first <= x0)
arr[i].x = iter->second;
arr[i].y = coord_map[arr[i].y0];
lowest_x = min(lowest_x, arr[i].x);
}
for (int i = 0; i < n; i++) {
if (arr[i].y < lowest_x) {
arr[i].y = lowest_x;
}
arr[i].low = min(arr[i].x, arr[i].y);
arr[i].high = max(arr[i].x, arr[i].y);
arr[i].up = (arr[i].y >= arr[i].x);
}
sort(arr.begin(), arr.end(), [](const Edge &a, const Edge &b) {
return a.x != b.x ? a.x < b.x : a.y < b.y;
});
IntervalTree up_lows(m+1), up_highs(m+1), down_lows(m+1), down_highs(m+1);
auto update_trees = [&](Edge &e, int value) {
if (e.up) {
up_lows.update(e.low, value);
up_highs.update(e.high, value);
} else {
down_lows.update(e.low, value);
down_highs.update(e.high, value);
}
};
for (int i = 0; i < n; i++) {
update_trees(arr[i], 1);
}
auto count_ups = [&](int pos) {
return up_lows.query(0, pos) - up_highs.query(0, pos);
};
auto count_downs = [&](int pos) {
return down_highs.query(pos, m - 1) - down_lows.query(pos, m - 1);
};
auto count_starts = [&](int low, int high) {
return up_lows.query(low, high) + down_highs.query(low, high);
};
auto count_ends = [&](int low, int high) {
return up_highs.query(low, high) + down_lows.query(low, high);
};
auto is_broken_at = [&](int pos) {
return count_downs(pos) == 0 && count_starts(0, pos - 1) > 0
|| count_starts(0, pos - 1) > count_ends(0, pos - 1);
};
auto find_next = [&](int prev_y) {
return lower_bound(arr.begin(), arr.end(), prev_y, [](const Edge &a, int value) {
return a.x < value;
}) - arr.begin();
};
function<bool(int,int)> dfs = [&](int prev, int depth) -> bool {
int y = arr[prev].y;
arr[prev].depth = depth;
update_trees(arr[prev], -1);
if (count_starts(0, m) == 0) {
return true;
}
if (!is_broken_at(y)) {
for (int i = find_next(y); i < n; i++) {
if (!arr[i].depth && dfs(i, depth + 1)) {
return true;
}
}
}
update_trees(arr[prev], 1);
arr[prev].depth = 0;
return false;
};
bool possible = false;
for (int i = 0; i < n; i++) {
if (dfs(i, 1)) {
possible = true;
break;
}
}
if (!possible) {
cout << "NO\n";
} else {
cout << "YES\n";
sort(arr.begin(), arr.end(), [](const Edge &a, const Edge &b) {
return a.depth < b.depth;
});
if (arr[n-1].depth != n) {
cout << "FAILED\n";
}
for (const auto &e : arr) {
cout << e.x0 << ' ' << e.y0 << '\n';
}
}
}
return 0;
}Test details
Test 1
Group: 1, 4, 5
Verdict: ACCEPTED
| input |
|---|
| 100 1 74 75 1 100 43 ... |
| correct output |
|---|
| YES 74 75 YES 100 43 YES ... |
| user output |
|---|
| YES 74 75 YES 100 43 YES ... Truncated |
Test 2
Group: 1, 4, 5
Verdict: ACCEPTED
| input |
|---|
| 100 2 80 54 51 61 2 ... |
| correct output |
|---|
| YES 51 61 80 54 YES 2 64 ... |
| user output |
|---|
| YES 51 61 80 54 YES 2 64 ... Truncated |
Test 3
Group: 1, 4, 5
Verdict: ACCEPTED
| input |
|---|
| 100 3 3 74 91 45 100 24 ... |
| correct output |
|---|
| YES 3 74 100 24 91 45 YES ... |
| user output |
|---|
| YES 3 74 100 24 91 45 YES ... Truncated |
Test 4
Group: 1, 4, 5
Verdict: ACCEPTED
| input |
|---|
| 100 4 88 50 62 41 12 86 ... |
| correct output |
|---|
| YES 12 86 88 50 62 41 66 93 ... |
| user output |
|---|
| YES 12 86 88 50 62 41 66 93 ... Truncated |
Test 5
Group: 1, 4, 5
Verdict: ACCEPTED
| input |
|---|
| 100 5 82 80 80 92 5 22 ... |
| correct output |
|---|
| YES 5 22 94 13 82 80 80 92 ... |
| user output |
|---|
| YES 5 22 82 80 80 92 94 13 ... Truncated |
Test 6
Group: 1, 2, 4, 5
Verdict: ACCEPTED
| input |
|---|
| 100 5 34 38 26 30 1 6 ... |
| correct output |
|---|
| YES 1 6 12 22 26 30 34 38 ... |
| user output |
|---|
| YES 1 6 12 22 26 30 34 38 ... Truncated |
Test 7
Group: 1, 3, 4, 5
Verdict: ACCEPTED
| input |
|---|
| 100 5 50 40 28 25 51 7 ... |
| correct output |
|---|
| YES 51 7 50 40 47 1 17 11 ... |
| user output |
|---|
| YES 17 11 28 25 51 7 47 1 ... Truncated |
Test 8
Group: 1, 4, 5
Verdict: ACCEPTED
| input |
|---|
| 100 5 2 2 2 1 1 1 ... |
| correct output |
|---|
| YES 1 2 2 1 2 1 1 1 ... |
| user output |
|---|
| YES 1 1 1 2 2 1 2 1 ... Truncated |
Test 9
Group: 2, 4, 5
Verdict: ACCEPTED
| input |
|---|
| 100 100 175870020 296379324 248160539 883842002 21934885 781732852 ... |
| correct output |
|---|
| NO YES 4976156 6890135 10553287 11923223 14617057 17728163 ... |
| user output |
|---|
| NO YES 4976156 6890135 10553287 11923223 14617057 17728163 ... Truncated |
Test 10
Group: 3, 4, 5
Verdict: ACCEPTED
| input |
|---|
| 100 100 447597377 314433951 700232436 691277009 937268439 708165426 ... |
| correct output |
|---|
| YES 998963839 391778929 995772196 257222033 995754704 553123757 994629465 247775824 ... |
| user output |
|---|
| YES 80804061 58329306 78989197 22224979 86698875 65763632 131739372 728604 ... Truncated |
Test 11
Group: 4, 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100 100 1 1 1 2 2 1 ... |
| correct output |
|---|
| YES 1 2 2 1 1 2 2 2 ... |
| user output |
|---|
| (empty) |
Test 12
Group: 4, 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100 100 7 1 6 3 10 9 ... |
| correct output |
|---|
| YES 6 7 7 8 9 10 10 10 ... |
| user output |
|---|
| (empty) |
Test 13
Group: 4, 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100 100 51 5 85 77 91 84 ... |
| correct output |
|---|
| YES 100 24 100 25 100 3 100 6 ... |
| user output |
|---|
| (empty) |
Test 14
Group: 4, 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100 100 823828194 863717310 593641073 340054211 420481158 965069109 ... |
| correct output |
|---|
| YES 999289319 634855378 996775156 433726648 983657502 55234695 981890636 112877413 ... |
| user output |
|---|
| (empty) |
Test 15
Group: 2, 5
Verdict: ACCEPTED
| input |
|---|
| 100 500 88724450 89315226 266915464 267648621 189301651 189661541 ... |
| correct output |
|---|
| YES 764920 1459946 1936195 2832987 3691481 4085931 4991808 5840928 ... |
| user output |
|---|
| YES 764920 1459946 1936195 2832987 3691481 4085931 4991808 5840928 ... Truncated |
Test 16
Group: 3, 5
Verdict: ACCEPTED
| input |
|---|
| 100 500 763682761 317584504 756010800 260162861 435911339 78070399 ... |
| correct output |
|---|
| YES 998768285 3307355 998714926 628486754 997115613 820932481 993320616 554600893 ... |
| user output |
|---|
| YES 67893124 41695427 71119534 44765650 91053246 37319028 93904415 12130613 ... Truncated |
Test 17
Group: 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100 500 2 2 2 1 1 2 ... |
| correct output |
|---|
| YES 1 2 2 2 2 1 1 2 ... |
| user output |
|---|
| (empty) |
Test 18
Group: 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100 500 10 6 10 10 9 10 ... |
| correct output |
|---|
| YES 2 3 3 4 4 5 5 6 ... |
| user output |
|---|
| (empty) |
Test 19
Group: 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100 500 85 87 89 70 70 92 ... |
| correct output |
|---|
| YES 96 97 100 67 100 10 100 97 ... |
| user output |
|---|
| (empty) |
Test 20
Group: 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100 500 861154169 119512584 569086662 606567153 288230434 322196278 ... |
| correct output |
|---|
| YES 999945324 969534372 999738857 240617694 999244114 722161553 999207839 557351400 ... |
| user output |
|---|
| (empty) |
Test 21
Group: 5
Verdict: TIME LIMIT EXCEEDED
| input |
|---|
| 100 500 116439250 401518028 280329609 193466222 674040956 209050570 ... |
| correct output |
|---|
| NO YES 773701149 773852119 987509190 315670966 977413249 510418200 ... |
| user output |
|---|
| (empty) |
Test 22
Group: 5
Verdict: ACCEPTED
| input |
|---|
| 100 500 934181189 942499518 684836806 395802802 957884803 570946201 ... |
| correct output |
|---|
| YES 999772640 505132174 999111650 140844643 999028633 888134186 999020109 291046771 ... |
| user output |
|---|
| YES 24314565 937625373 939285236 40930769 43558370 565096722 569646067 191247997 ... Truncated |
