Submission #1350480

#TimeUsernameProblemLanguageResultExecution timeMemory
1350480Ghulam_JunaidXylophone (JOI18_xylophone)C++20
0 / 100
0 ms332 KiB
#include <bits/stdc++.h>
#include "xylophone.h"
// #include "grader.cpp"
using namespace std;

typedef long long ll;

void solve(int N) {
    int a[N + 2] = {};
    int lo = 1, hi = N, mid;
    while (hi - lo > 1) {
        mid = (lo + hi) / 2;
        if (query(mid, N) == N - 1) lo = mid; 
        else hi = mid;
    }
    a[lo] = 1;

    bool done[N + 2] = {};
    done[1] = 1;
    for (int i, d, x, y = lo + 1; i <= N; i ++){
        d = query(i - 1, i);
        x = a[i - 1] + d, y = a[i - 1] - d;
        if (x > N or done[x]) a[i] = y;
        else if (y <= 0 or done[y]) a[i] = x;
        else{
            d = query(i - 2, i);
            if (a[i - 2] < a[i - 1]){
                if (d == x - a[i - 2])
                    a[i] = x;
                else
                    a[i] = y;
            }
            else{
                if (d == a[i - 2] - y)
                    a[i] = y;
                else
                    a[i] = x;
            }
        }
        done[a[i]] = 1;
    }
    for (int i, d, x, y = lo - 1; i > 0; i --){
        d = query(i, i + 1);
        x = a[i + 1] + d, y = a[i + 1] - d;
        if (x > N or done[x]) a[i] = y;
        else if (y <= 0 or done[y]) a[i] = x;
        else{
            d = query(i, i + 2);
            if (a[i + 2] < a[i + 1]){
                if (d == x - a[i + 2])
                    a[i] = x;
                else
                    a[i] = y;
            }
            else{
                if (d == a[i + 2] - y)
                    a[i] = y;
                else
                    a[i] = x;
            }
        }
        done[a[i]] = 1;
    }

    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...