Submission #776064

#TimeUsernameProblemLanguageResultExecution timeMemory
776064anha3k25cvpXylophone (JOI18_xylophone)C++14
100 / 100
66 ms444 KiB
#include <bits/stdc++.h> #include "xylophone.h" using namespace std; void solve(int n) { int lo = 1, hi = n; vector <int> a(n + 1, 0), vis(n + 1, 0); while (lo < hi) { int mid = (lo + hi + 1) / 2, val = query(mid, n); if (val == n - 1) lo = mid; else hi = mid - 1; } a[lo] = 1; vis[1] = 1; if (lo > 1) { int val = query(lo - 1, lo); a[lo - 1] = val + 1; vis[val + 1] = 1; for (int i = lo - 2; i > 0; i --) { val = query(i, i + 1); vector <int> g; if (a[i + 1] - val > 0 && !vis[a[i + 1] - val]) g.push_back(a[i + 1] - val); if (a[i + 1] + val <= n && !vis[a[i + 1] + val]) g.push_back(a[i + 1] + val); if (g.size() == 1) { a[i] = g[0]; vis[a[i]] = 1; } else { int val_ = max({g[0], a[i + 1], a[i + 2]}) - min({g[0], a[i + 1], a[i + 2]}); if (val_ == query(i, i + 2)) { a[i] = g[0]; vis[a[i]] = 1; } else { a[i] = g[1]; vis[a[i]] = 1; } } } } int val = query(lo, lo + 1); a[lo + 1] = val + 1; vis[val + 1] = 1; for (int i = lo + 2; i <= n; i ++) { val = query(i - 1, i); vector <int> g; if (a[i - 1] - val > 0 && !vis[a[i - 1] - val]) g.push_back(a[i - 1] - val); if (a[i - 1] + val <= n && !vis[a[i - 1] + val]) g.push_back(a[i - 1] + val); if (g.size() == 1) { a[i] = g[0]; vis[a[i]] = 1; } else { int val_ = max({g[0], a[i - 1], a[i - 2]}) - min({g[0], a[i - 1], a[i - 2]}); if (val_ == query(i - 2, i)) { a[i] = g[0]; vis[a[i]] = 1; } else { a[i] = g[1]; vis[a[i]] = 1; } } } for (int i = 1; i <= n; i ++) answer(i, a[i]); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...