Submission #894569

#TimeUsernameProblemLanguageResultExecution timeMemory
894569lunaTuXylophone (JOI18_xylophone)C++17
0 / 100
0 ms344 KiB
#include <bits/stdc++.h> #define ff first #define ss second #define all(x) x.begin(), x.end() #include "xylophone.h" typedef long long ll; using namespace std; void solve(int N) { vector<int> a(N + 1), u(N + 1); int l = 1, r = N + 1; while (r - l > 1) { int m = (l + r) / 2; int get = 0; if (m < N) get = query(m, N); if (get != N - 1) r = m; else l = m; } answer(l, 1); a[l] = 1; u[1] = 1; if (l != N) { a[l + 1] = 1 + query(l, l + 1); answer(l + 1, a[l + 1]); u[a[l + 1]] = 1; } for (int i = l + 2; i <= N; i++) { int x = query(i - 2, i); int r = abs(a[i - 1] - a[i - 2]) - x; if (a[i - 1] < a[i - 2]) { if (r == 0) { int y = query(i - 1, i); a[i] = a[i - 1] + y; } else { if (u[a[i - 2] - x]) a[i] = a[i - 1] + x; else if (u[a[i - 1] + x]) a[i] = a[i - 2] - x; else { int y = query(i - 1, i); if (y == x) a[i] = a[i - 1] + x; else a[i] = a[i - 2] - x; } } } else { if (r == 0) { int y = query(i - 1, i); a[i] = a[i - 1] - y; } else { if (u[a[i - 1] - x]) a[i] = a[i - 2] + x; else if (u[a[i - 2] + x]) a[i] = a[i - 1] - x; else { int y = query(i - 1, i); if (y == x) a[i] = a[i - 1] - x; else a[i] = a[i - 2] + x; } } } answer(i, a[i]); u[a[i]] = 1; } if (l != 1) { a[l - 1] = 1 + query(l - 1, l); answer(l - 1, a[l - 1]); } for (int i = l - 2; i >= 1; i--) { int x = query(i, i + 2); int r = abs(a[i - 1] - a[i - 2]) - x; if (a[i + 1] < a[i + 2]) { if (r == 0) { int y = query(i, i + 1); a[i] = a[i + 1] + y; } else { if (u[a[i + 2] - x]) a[i] = a[i + 1] + x; else if (u[a[i + 1] + x]) a[i] = a[i + 2] - x; else { int y = query(i, i + 1); if (y == x) a[i] = a[i + 1] + x; else a[i] = a[i + 2] - x; } } } else { if (r == 0) { int y = query(i, i + 1); a[i] = a[i + 1] - y; } else { if (u[a[i + 1] - x]) a[i] = a[i + 2] + x; else if (u[a[i + 2] + x]) a[i] = a[i + 1] - x; else { int y = query(i, i + 1); if (y == x) a[i] = a[i + 1] - x; else a[i] = a[i + 2] + x; } } } answer(i, a[i]); u[a[i]] = 1; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...