Submission #894544

#TimeUsernameProblemLanguageResultExecution timeMemory
894544lunaTuXylophone (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); 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; if (l != N) { a[l + 1] = 1 + query(l, l + 1); answer(l + 1, a[l + 1]); } for (int i = l + 2; i <= N; i++) { int x = query(i - 2, i); if (x == abs(a[i - 1] - a[i - 2])) { int y = query(i - 1, i); if (a[i - 1] < a[i - 2]) a[i] = a[i - 1] + y; else a[i] = a[i - 1] - y; } else if (a[i - 1] < a[i - 2]) a[i] = a[i - 1] + x; else a[i] = a[i - 2] + x; answer(i, a[i]); } 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); if (x == abs(a[i + 1] - a[i + 2])) { int y = query(i, i + 1); if (a[i + 1] < a[i + 2]) a[i] = a[i + 1] + y; else a[i] = a[i + 1] - y; } else if (a[i + 1] < a[i + 2]) a[i] = a[i + 1] + x; else a[i] = a[i + 2] + x; answer(i, a[i]); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...