Submission #960649

#TimeUsernameProblemLanguageResultExecution timeMemory
960649NeltXylophone (JOI18_xylophone)C++17
0 / 100
1 ms428 KiB
#include "xylophone.h" #include <bits/stdc++.h> #define ll long long #define endl "\n" using namespace std; map<pair<ll, ll>, ll> mp; ll ask(ll i, ll j) { return mp.count({i, j}) ? mp[{i, j}] : mp[{i, j}] = query(i, j); } void solve(int n) { ll a[n + 1]; ll l = 1, r = n; while (l <= r) { ll mid = (l + r) >> 1; if (ask(mid, n) == n - 1) l = mid + 1; else r = mid - 1; } l--; a[l] = 1; if (l + 1 <= n) a[l + 1] = ask(l, l + 1) + 1; for (ll i = l + 2; i <= n; i++) if (a[i - 2] < a[i - 1]) { if (ask(i - 2, i) > ask(i - 2, i - 1)) a[i] = ask(i - 2, i) + a[i - 2]; else a[i] = a[i - 1] - ask(i - 1, i); } else { if (ask(i - 2, i) > ask(i - 2, i - 1)) a[i] = a[i - 2] - ask(i - 2, i); else a[i] = ask(i - 1, i) + a[i - 1]; } if (l - 1 > 0) a[l - 1] = ask(l - 1, l) + 1; for (ll i = l - 2; i >= 1; i--) if (a[i + 2] < a[i + 1]) { if (ask(i, i + 2) > ask(i + 1, i + 2)) a[i] = ask(i, i + 2) + a[i + 2]; else a[i] = a[i + 1] - ask(i, i + 1); } else { if (ask(i, i + 2) > ask(i + 1, i + 2)) a[i] = a[i + 2] - ask(i, i + 2); else a[i] = ask(i, i + 1) + a[i + 1]; } for (ll 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...