Submission #918980

#TimeUsernameProblemLanguageResultExecution timeMemory
918980viwlesxqXylophone (JOI18_xylophone)C++17
47 / 100
41 ms500 KiB
#include <bits/stdc++.h> using namespace std; #include "xylophone.h" void solve(int n) { vector<int> a(n + 1), d(n + 1); for (int i = 1; i < n; ++i) { d[i] = query(i, i + 1); } int min = 1, hi = n; while (min + 1 < hi) { int mid = (min + hi) / 2; if ((mid + 1 < n ? query(mid, n) : d[mid]) == n - 1) min = mid; else hi = mid; } a[min] = 1; int last = min, sum = 0; bool increasing = true; for (int i = min - 1; i > 0; --i) { int diff = (i + 1 < last ? query(i, last) : d[i]), add = d[i]; if (sum + add != diff) { last = i + 1, sum = 0; increasing ^= true; } a[i] = a[i + 1] + (increasing ? add : -add); sum += add; } last = min, sum = 0; increasing = true; for (int i = min + 1; i <= n; ++i) { int diff = (last + 1 < i ? query(last, i) : d[last]), add = d[i - 1]; if (sum + add != diff) { last = i - 1, sum = 0; increasing ^= true; } a[i] = a[i - 1] + (increasing ? add : -add); sum += add; } 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...