답안 #918993

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
918993 2024-01-31T02:31:28 Z viwlesxq Xylophone (JOI18_xylophone) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
//#include "grader.cpp"

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;
    map<int, bool> used;
    used[1] = true;
    for (int i = min - 1; i > 0; --i) {
        int add = d[i];
        if (used[a[i + 1] + add] || a[i + 1] - add > n) {
            if (increasing) increasing = false, sum = 0;
        } else if (used[a[i + 1] - add] || a[i + 1] + add <= 0) {
            if (!increasing) increasing = true, sum = 0;
        } else {
            int diff = (i + 1 < last ? query(i, last) : d[i]);
            if (sum + add != diff) {
                last = i + 1, sum = 0;
                increasing ^= true;
            }
        }
        a[i] = a[i + 1] + (increasing ? add : -add);
        used[a[i]] = true;
        sum += add;
    }
    last = min, sum = 0;
    increasing = true;
    for (int i = min + 1; i <= n; ++i) {
        int add = d[i - 1];
        if (used[a[i - 1] + add] || a[i - 1] - add > n) {
            if (increasing) increasing = false, sum = 0;
        } else if (used[a[i - 1] - add] || a[i - 1] + add <= 0) {
            if (!increasing) increasing = true, sum = 0;
        } else {
            int diff = (last + 1 < i ? query(last, i) : d[last]);
            if (sum + add != diff) {
                last = i - 1, sum = 0;
                increasing ^= true;
            }
        }
        a[i] = a[i - 1] + (increasing ? add : -add);
        used[a[i]] = true;
        sum += add;
    }
    for (int i = 1; i <= n; ++i) {
        cout << a[i] << ' ';
        answer(i, a[i]);
    }
}

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:8:16: error: 'query' was not declared in this scope
    8 |         d[i] = query(i, i + 1);
      |                ^~~~~
xylophone.cpp:13:28: error: 'query' was not declared in this scope
   13 |         if ((mid + 1 < n ? query(mid, n) : d[mid]) == n - 1) min = mid;
      |                            ^~~~~
xylophone.cpp:28:40: error: 'query' was not declared in this scope
   28 |             int diff = (i + 1 < last ? query(i, last) : d[i]);
      |                                        ^~~~~
xylophone.cpp:47:40: error: 'query' was not declared in this scope
   47 |             int diff = (last + 1 < i ? query(last, i) : d[last]);
      |                                        ^~~~~
xylophone.cpp:59:9: error: 'answer' was not declared in this scope
   59 |         answer(i, a[i]);
      |         ^~~~~~