Submission #379265

#TimeUsernameProblemLanguageResultExecution timeMemory
379265qwerty234Xylophone (JOI18_xylophone)C++14
100 / 100
83 ms524 KiB
#include <bits/stdc++.h> #include "xylophone.h" #define ll long long #define fi first #define se second #define pb push_back using namespace std; const int MAXN = 5e5 + 10, inf = 2e9; void solve(int n) { vector <int> b; b.assign(n, 0); vector <bool> vis(n + 1, false); int l = 0, r = n - 1, posn = n - 1; while (l <= r) { int m = (l + r) / 2; int tmp = query(1, m + 1); if (tmp < n - 1) { l = m + 1; } else { posn = min(posn, m); r = m - 1; } } b[posn] = n; vis[n] = true; if (posn != n - 1) { int tmp = query(posn + 1, posn + 2); b[posn + 1] = n - tmp; } if (posn != 0) { int tmp = query(posn, posn + 1); b[posn - 1] = n - tmp; } for (int i = posn + 2; i < n; i++) { int x, y, tmp = query(i, i + 1); x = b[i - 1] + tmp; y = b[i - 1] - tmp; if (x > n || vis[x]) { b[i] = y; } else if (y < 1 || vis[y]) { b[i] = x; } else { int tmp = query(i - 1, i + 1); if (b[i - 2] < b[i - 1]) { if (tmp == x - b[i - 2]) { b[i] = x; } else { b[i] = y; } } else { if (tmp == b[i - 2] - y) { b[i] = y; } else { b[i] = x; } } } vis[b[i]] = true; } for (int i = posn - 2; i >= 0; i--) { int x, y, tmp = query(i + 1, i + 2); x = b[i + 1] + tmp; y = b[i + 1] - tmp; if (x > n || vis[x]) { b[i] = y; } else if (y < 1 || vis[y]) { b[i] = x; } else { int tmp = query(i + 1, i + 3); if (b[i + 2] < b[i + 1]) { if (tmp == x - b[i + 2]) { b[i] = x; } else { b[i] = y; } } else { if (tmp == b[i + 2] - y) { b[i] = y; } else { b[i] = x; } } } vis[b[i]] = true; } for (int i = 0; i < n; i++) { answer(i + 1, b[i]); // cout << b[i] << " "; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...