Submission #1354565

#TimeUsernameProblemLanguageResultExecution timeMemory
1354565SulAXylophone (JOI18_xylophone)C++20
0 / 100
0 ms360 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define popcount __builtin_popcount
#define all(a) (a).begin(), (a).end()
using namespace std;
using namespace chrono;
using namespace __gnu_pbds;
template<typename T> using ordered_set = tree<T,null_type,less_equal<>,rb_tree_tag,tree_order_statistics_node_update>;

int query(int l, int r);
void answer(int i, int ai);

void solve(int n) {
    int dif[3][n+1];
    for (int i = 1; i <= 2; i++) {
        for (int j = 1; i+j <= n; j++) {
            dif[i][j] = query(j, j+i);
        }
    }
    int comp[n+1];
    comp[1] = 1;
    for (int i = 2; i < n; i++) {
        comp[i] = comp[i-1];
        if (dif[1][i] + dif[1][i+1] != dif[2][i])
            comp[i] *= -1;
    }
    int a[n+1];
    a[1] = 1;
    for (int i = 1; i < n; i++)
        a[i+1] = a[i] + comp[i]*dif[1][i];
    int mn = *min_element(a+1, a+n+1);
    for (int i = 1; i <= n; i++)
        a[i] += 1 - mn;
    int p1 = find(a+1, a+n+1, 1) - a;
    int pn = find(a+1, a+n+1, n) - a;
    if (p1 > pn) {
        for (int i = 1; i <= n; i++) {
            a[i] = n+1 - a[i];
        }
    }
    for (int i = 1; i <= n; i++)
        answer(i, a[i]);
}
// 2 1 5 3 4

// int query(int l, int r) { int x; cout << "? " << l << " " << r << endl; cin >> x; return x; }
// void answer(int i, int ai) { cout << i << " " << ai << endl; }

// int main() {
//     ios::sync_with_stdio(false);
//     cin.tie(nullptr);

//     int n; cin >> n;
//     solve(n);
// }
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...