#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;
typedef long long ll;
#include "minerals.h"
void Solve(int N) {
vector <int> gs_l;
vector <int> gs_r;
int cnt = 0;
for (int i = 1; i <= 2 * N; ++i) {
int cur_cnt = Query(i);
if (cur_cnt > cnt) {
cnt = cur_cnt;
gs_l.push_back(i);
} else {
gs_r.push_back(i);
Query(i);
}
}
vector <int> f, s;
function <void(vector <int>, vector <int>, int)> rec = [&] (vector <int> l, vector <int> r, int em) {
if (l.size() == 1) {
assert(r.size() == 1);
f.push_back(l[0]);
s.push_back(r[0]);
} else {
int m = (int)l.size() / 2;
vector <int> l_l, l_r, r_l, r_r;
for (int i = 0; i < m; ++i) l_l.push_back(l[i]);
for (int i = m; i < (int)l.size(); ++i) l_r.push_back(l[i]);
int have = -1;
for (auto x : l_l) {
have = Query(x);
}
if (!em) {
for (auto x : r) {
int cur = Query(x);
if (cur > have) {
r_l.push_back(x);
} else {
r_r.push_back(x);
}
Query(x);
}
rec(l_l, r_l, 1);
rec(l_r, r_r, 0);
} else {
for (auto x : r) {
int cur = Query(x);
if (cur > have) {
r_r.push_back(x);
} else {
r_l.push_back(x);
}
Query(x);
}
rec(l_l, r_l, 0);
rec(l_r, r_r, 1);
}
}
};
rec(gs_l, gs_r, 0);
for (int i = 0; i < N; ++i) {
Answer(f[i], s[i]);
}
}
#ifdef LOCAL
constexpr int MAX_N = 43000;
constexpr int MAX_CALLS = 1000000;
namespace {
void WrongAnswer(int code) {
printf("Wrong Answer [%d]\n", code);
exit(0);
}
int N;
int _counterpart[2 * MAX_N + 1];
int num_queries;
int num_kinds;
int on[2 * MAX_N + 1];
int _count[2 * MAX_N + 1];
int num_answers;
int answer[2 * MAX_N + 1];
} // namespace
int Query(int x) {
if (!(1 <= x && x <= 2 * N)) {
WrongAnswer(1);
}
if (++num_queries > MAX_CALLS) {
WrongAnswer(2);
}
const int type = std::min(x, _counterpart[x]);
if (on[x]) {
--on[x];
--_count[type];
if (_count[type] == 0) {
--num_kinds;
}
} else {
++on[x];
++_count[type];
if (_count[type] == 1) {
++num_kinds;
}
}
return num_kinds;
}
void Answer(int a, int b) {
if (++num_answers > N) {
WrongAnswer(6);
}
if (!(1 <= a && a <= 2 * N && 1 <= b && b <= 2 * N)) {
WrongAnswer(3);
}
if (answer[a] != 0) {
WrongAnswer(4);
}
answer[a] = b;
if (answer[b] != 0) {
WrongAnswer(4);
}
answer[b] = a;
if (!(_counterpart[a] == b && _counterpart[b] == a)) {
WrongAnswer(5);
}
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif
cin >> N;
for (int i = 1; i <= N; ++i) {
int x, y;
cin >> x >> y;
_counterpart[x] = y;
_counterpart[y] = x;
}
Solve(N);
if (num_answers != N) {
WrongAnswer(6);
}
printf("Accepted: %d\n", num_queries);
return 0;
}
#endif
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
512 KB |
Output is correct |
3 |
Correct |
5 ms |
640 KB |
Output is correct |
4 |
Correct |
12 ms |
1024 KB |
Output is correct |
5 |
Correct |
20 ms |
1528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
512 KB |
Output is correct |
7 |
Correct |
5 ms |
640 KB |
Output is correct |
8 |
Correct |
12 ms |
1024 KB |
Output is correct |
9 |
Correct |
20 ms |
1528 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
14 ms |
1280 KB |
Output is correct |
12 |
Correct |
20 ms |
1528 KB |
Output is correct |
13 |
Correct |
18 ms |
1536 KB |
Output is correct |
14 |
Correct |
19 ms |
1536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
512 KB |
Output is correct |
7 |
Correct |
5 ms |
640 KB |
Output is correct |
8 |
Correct |
12 ms |
1024 KB |
Output is correct |
9 |
Correct |
20 ms |
1528 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
14 ms |
1280 KB |
Output is correct |
12 |
Correct |
20 ms |
1528 KB |
Output is correct |
13 |
Correct |
18 ms |
1536 KB |
Output is correct |
14 |
Correct |
19 ms |
1536 KB |
Output is correct |
15 |
Incorrect |
38 ms |
3316 KB |
Wrong Answer [2] |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
512 KB |
Output is correct |
7 |
Correct |
5 ms |
640 KB |
Output is correct |
8 |
Correct |
12 ms |
1024 KB |
Output is correct |
9 |
Correct |
20 ms |
1528 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
14 ms |
1280 KB |
Output is correct |
12 |
Correct |
20 ms |
1528 KB |
Output is correct |
13 |
Correct |
18 ms |
1536 KB |
Output is correct |
14 |
Correct |
19 ms |
1536 KB |
Output is correct |
15 |
Incorrect |
38 ms |
3316 KB |
Wrong Answer [2] |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
512 KB |
Output is correct |
7 |
Correct |
5 ms |
640 KB |
Output is correct |
8 |
Correct |
12 ms |
1024 KB |
Output is correct |
9 |
Correct |
20 ms |
1528 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
14 ms |
1280 KB |
Output is correct |
12 |
Correct |
20 ms |
1528 KB |
Output is correct |
13 |
Correct |
18 ms |
1536 KB |
Output is correct |
14 |
Correct |
19 ms |
1536 KB |
Output is correct |
15 |
Incorrect |
38 ms |
3316 KB |
Wrong Answer [2] |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
512 KB |
Output is correct |
7 |
Correct |
5 ms |
640 KB |
Output is correct |
8 |
Correct |
12 ms |
1024 KB |
Output is correct |
9 |
Correct |
20 ms |
1528 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
14 ms |
1280 KB |
Output is correct |
12 |
Correct |
20 ms |
1528 KB |
Output is correct |
13 |
Correct |
18 ms |
1536 KB |
Output is correct |
14 |
Correct |
19 ms |
1536 KB |
Output is correct |
15 |
Incorrect |
38 ms |
3316 KB |
Wrong Answer [2] |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
512 KB |
Output is correct |
7 |
Correct |
5 ms |
640 KB |
Output is correct |
8 |
Correct |
12 ms |
1024 KB |
Output is correct |
9 |
Correct |
20 ms |
1528 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
14 ms |
1280 KB |
Output is correct |
12 |
Correct |
20 ms |
1528 KB |
Output is correct |
13 |
Correct |
18 ms |
1536 KB |
Output is correct |
14 |
Correct |
19 ms |
1536 KB |
Output is correct |
15 |
Incorrect |
38 ms |
3316 KB |
Wrong Answer [2] |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
512 KB |
Output is correct |
7 |
Correct |
5 ms |
640 KB |
Output is correct |
8 |
Correct |
12 ms |
1024 KB |
Output is correct |
9 |
Correct |
20 ms |
1528 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
14 ms |
1280 KB |
Output is correct |
12 |
Correct |
20 ms |
1528 KB |
Output is correct |
13 |
Correct |
18 ms |
1536 KB |
Output is correct |
14 |
Correct |
19 ms |
1536 KB |
Output is correct |
15 |
Incorrect |
38 ms |
3316 KB |
Wrong Answer [2] |
16 |
Halted |
0 ms |
0 KB |
- |