Submission #1324294

#TimeUsernameProblemLanguageResultExecution timeMemory
1324294adscodingXylophone (JOI18_xylophone)C++20
Compilation error
0 ms0 KiB
#include "xylophone.h" #include <bits/stdc++.h> #define fi first #define se second #define FOR(i, a, b) for (int i = a, _b = b; i <= _b; ++i) #define FORD(i, a, b) for (int i = a, _b = b; i >= _b; --i) #define FORLL(i, a, b) for (ll i = a, _b = b; i <= _b; ++i) #define FORDLL(i, a, b) for (ll i = a, _b = b; i >= _b; --i) #define all(x) x.begin(), x.end() #define uni(x) sort(all(x)), x.erase(unique(all(x)), x.end()) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; bool valid(int x) { return x >= 1 && x <= n && !mark[x]; } int get_ans(int root, int so, int delta) { if (root < so) return root + delta; return root - delta; } void solve(int n) { vector<int> a(n + 3, 0), RES(n + 3, 0); vector<bool> mark(n + 3, false); int l = 1, r = n; while (l <= r) { int mid = l + r >> 1; if (query(mid, n) == n - 1) l = mid + 1; else r = mid - 1; } int pos1 = r; a[pos1] = 1; mark[1] = true; pii cur = {0, 0}; if (pos1 < n) { RES[pos1] = query(pos1, pos1 + 1); a[pos1 + 1] = RES[pos1] + 1; FOR(i, pos1 + 2, n) { mark[a[i - 1]] = true; RES[i - 1] = query(i - 1, i); if (!valid(a[i - 1] + RES[i - 1])) { a[i] = a[i - 1] - RES[i - 1]; continue; } else if (!valid(a[i - 1] - RES[i - 1])) { a[i] = a[i - 1] + RES[i - 1]; continue; } int cur = query(i - 2, i); // dbg(i, RES[i - 1], RES[i - 2], cur); if (cur == RES[i - 1]) a[i] = get_ans(a[i - 1], a[i - 2], cur); else if (cur == RES[i - 2]) a[i] = get_ans(a[i - 1], a[i - 2], RES[i - 1]); else a[i] = get_ans(a[i - 2], a[i - 1], cur); } } if (pos1 > 1) { RES[pos1 - 1] = query(pos1 - 1, pos1); a[pos1 - 1] = RES[pos1 - 1] + 1; FORD(i, pos1 - 2, 1) { mark[a[i + 1]] = true; RES[i] = query(i, i + 1); if (!valid(a[i + 1] + RES[i])) { a[i] = a[i + 1] - RES[i]; continue; } else if (!valid(a[i + 1] - RES[i])) { a[i] = a[i + 1] + RES[i]; continue; } if (RES[i + 1] == 0) RES[i + 1] = query(i + 1, i + 2); int cur = query(i, i + 2); if (cur == RES[i]) a[i] = get_ans(a[i + 1], a[i + 2], cur); else if (cur == RES[i + 1]) a[i] = get_ans(a[i + 1], a[i + 2], RES[i]); else a[i] = get_ans(a[i + 2], a[i + 1], cur); } } FOR(i, 1, n) answer(i, a[i]); }

Compilation message (stderr)

xylophone.cpp: In function 'bool valid(int)':
xylophone.cpp:19:31: error: 'n' was not declared in this scope
   19 |         return x >= 1 && x <= n && !mark[x];
      |                               ^
xylophone.cpp:19:37: error: 'mark' was not declared in this scope
   19 |         return x >= 1 && x <= n && !mark[x];
      |                                     ^~~~