Submission #505221

#TimeUsernameProblemLanguageResultExecution timeMemory
505221colossal_pepeXylophone (JOI18_xylophone)C++17
0 / 100
1 ms200 KiB
#include <iostream> #include <vector> using namespace std; int n; vector<int> a; int query(int s, int t); void answer(int i, int x); int find1Pos() { int l = 1, r = n; while (r - l > 5) { int mid = (r + l) / 2; if (query(mid, n) == n - 1) l = mid; else r = mid - 1; } for (int i = r; i >= l; i--) { if (query(i, n) == n - 1) return i; } return 1; } int getVal(int cur, int p, int pp) { int d = query(min(cur, p), max(cur, p)); if (a[p] + d > n) { return a[p] - d; } else if (a[p] - d < 1) { return a[p] + d; } else { int e = query(min(cur, pp), max(cur, pp)), c = 1; if (a[p] > a[pp]) c = -1; return (e == abs(a[p] - a[pp]) ? a[p] + (c * d) : a[p] - (c * d)); } } void solve(int N) { n = N; a.resize(n + 1); for (int i = 1; i <= n; i++) { a[i] = -1; } int k = find1Pos(); a[k] = 1; for (int i = k - 1; i >= 1; i--) { a[i] = getVal(i, i + 1, i + 2); } for (int i = k + 1; i <= n; i++) { a[i] = getVal(i, i - 1, i - 2); } 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...