Submission #260707

#TimeUsernameProblemLanguageResultExecution timeMemory
260707arborXylophone (JOI18_xylophone)C++14
100 / 100
140 ms532 KiB
#include <bits/stdc++.h>
#include "xylophone.h"

#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MN = 1e5 + 5;

void solve(int n) {
    vector<int> d(n + 1), up(n + 1), a(n + 1);
    for (int i = 1; i <= n - 1; i++) {
        d[i] = query(i, i + 1);
    }
    a[1] = 0, a[2] = d[1];
    up[1] = 1;
    for (int i = 1; i <= n - 2; i++) {
        int j = i + 1;
        int q = query(i, i + 2);
        if (d[i] + d[i + 1] == q) up[j] = up[i];
        else up[j] = !up[i];
    }
    for (int i = 2; i <= n - 1; i++) {
        if (up[i]) a[i + 1] = a[i] + d[i];
        else a[i + 1] = a[i] - d[i];
    }
    int mn = min_element(a.begin() + 1, a.end()) - a.begin();
    int mx = max_element(a.begin() + 1, a.end()) - a.begin();
    if (mn > mx) for (int i = 1; i <= n; i++) a[i] = -a[i];
    int m = *min_element(a.begin() + 1, a.end());
    for (int i = 1; i <= n; i++) {
        a[i] = a[i] - m + 1;
        answer(i, a[i]);
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...