제출 #505196

#제출 시각아이디문제언어결과실행 시간메모리
505196colossal_pepeXylophone (JOI18_xylophone)C++17
0 / 100
1 ms328 KiB
#include <xylophone.h> #include <iostream> #include <vector> using namespace std; int n; vector<int> a, pos; int find1Pos() { int l = 1, r = n; while (r - l > 1) { int mid = (r + l) / 2; if (query(mid, n) == n - 1) l = mid; else r = mid - 1; } if (query(r, n) == n - 1) return r; return l; } int getVal(int cur, int p, int pp) { int d = query(min(cur, p), max(cur, p)); if (a[p] + d > n or pos[a[p] + d] != -1) { return a[p] - d; } else if (a[p] - d < 1 or pos[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, -1), pos.resize(n + 1, -1); pos[1] = find1Pos(); a[pos[1]] = 1; int l = pos[1] - 1; while (l >= 1) { a[l] = getVal(l, l + 1, l + 2); pos[a[l]] = l; l--; } int r = pos[1] + 1; while (r <= n) { a[r] = getVal(r, r - 1, r - 2); pos[a[r]] = r; r++; } 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...