Submission #1051684

#TimeUsernameProblemLanguageResultExecution timeMemory
1051684fryingducXylophone (JOI18_xylophone)C++17
100 / 100
35 ms600 KiB
#include "bits/stdc++.h" using namespace std; #ifndef duc_debug #include "xylophone.h" #endif void solve(int n) { int res = -1; int l = 1, r = n; while(l <= r) { int mid = (l + r) / 2; if(query(1, mid) == n - 1) { res = mid; r = mid - 1; } else l = mid + 1; } vector<int> a(n + 1); vector<bool> used(n + 1); used[n] = 1; a[res] = n; if(res < n) a[res + 1] = n - query(res, res + 1), used[a[res + 1]] = 1; if(res > 1) a[res - 1] = n - query(res - 1, res), used[a[res - 1]] = 1; for(int i = res - 2; i; --i) { int x = query(i, i + 1); int ft = a[i + 1] - x, se = a[i + 1] + x; if(ft < 1 || used[ft]) { a[i] = se; used[se] = 1; } else if(se > n || used[se]) { a[i] = ft; used[ft] = 1; } else { int y = query(i, i + 2); if(y == abs(a[i + 1] - a[i + 2])) { if(a[i + 1] > a[i + 2]) { a[i] = ft, used[ft] = 1; } else { a[i] = se, used[se] = 1; } } else { if(y == x) { if(a[i + 1] > a[i + 2]) { a[i] = ft, used[ft] = 1; } else { a[i] = se, used[se] = 1; } } else { if(a[i + 1] < a[i + 2]) { a[i] = a[i + 2] - y, used[a[i]] = 1; } else { a[i] = a[i + 2] + y, used[a[i]] = 1; } } } } } for(int i = res + 2; i <= n; ++i) { int x = query(i - 1, i); int ft = a[i - 1] - x, se = a[i - 1] + x; if(ft < 1 || used[ft]) { a[i] = se; used[se] = 1; } else if(se > n || used[se]) { a[i] = ft; used[ft] = 1; } else { int y = query(i - 2, i); if(y == abs(a[i - 1] - a[i - 2])) { if(a[i - 1] > a[i - 2]) { a[i] = ft, used[ft] = 1; } else { a[i] = se, used[se] = 1; } } else { if(y == x) { if(a[i - 1] > a[i - 2]) { a[i] = ft, used[ft] = 1; } else { a[i] = se, used[se] = 1; } } else { if(a[i - 1] < a[i - 2]) { a[i] = a[i - 2] - y, used[a[i]] = 1; } else { a[i] = a[i - 2] + y, used[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...