Submission #1051682

# Submission time Handle Problem Language Result Execution time Memory
1051682 2024-08-10T09:00:11 Z fryingduc Xylophone (JOI18_xylophone) C++17
Compilation error
0 ms 0 KB
#include "bits/stdc++.h"
using namespace std;

#ifndef duc_debug
#incldue "xylophone.h"
#endif

int query(int l, int r) {
    cout << "? " << l << " " << r << endl;
    
    int x; cin >> x;
    return x;
}
void answer(int i, int a) {
    cout << i << " " << a << '\n';
}
void solve(int n) {
    int res = -1;
    int l = 1, r = n;
    while(l <= r) {
        int mid = (l + r) / 2;
        if(query(1, mid) == n - 1) {
            res = mid;
            r = mid - 1;
        }
        else l = mid + 1;
    }
    vector<int> a(n + 1);
    vector<bool> used(n + 1);
    used[n] = 1;
    a[res] = n;
    if(res < n) a[res + 1] = n - query(res, res + 1), used[a[res + 1]] = 1;
    if(res > 1) a[res - 1] = n - query(res - 1, res), used[a[res - 1]] = 1;
    
    for(int i = res - 2; i; --i) {
        int x = query(i, i + 1);
        int ft = a[i + 1] - x, se = a[i + 1] + x;
        if(ft < 1 || used[ft]) {
            a[i] = se;
            used[se] = 1;
        }
        else if(se > n || used[se]) { 
            a[i] = ft;
            used[ft] = 1;
        }
        else {
            int y = query(i, i + 2);
            if(y == abs(a[i + 1] - a[i + 2])) {
                if(a[i + 1] > a[i + 2]) {
                    a[i] = ft, used[ft] = 1;
                }
                else {
                    a[i] = se, used[se] = 1;
                }
            }
            else {
                if(y == x) {
                    if(a[i + 1] > a[i + 2]) {
                        a[i] = ft, used[ft] = 1;
                    }
                    else {
                        a[i] = se, used[se] = 1;
                    }
                }
                else {
                    if(a[i + 1] < a[i + 2]) {
                        a[i] = a[i + 2] - y, used[a[i]] = 1;
                    }
                    else {
                        a[i] = a[i + 2] + y, used[a[i]] = 1;
                    }
                }
            }
        }
    }
    for(int i = res + 2; i <= n; ++i) {
        int x = query(i - 1, i);
        int ft = a[i - 1] - x, se = a[i - 1] + x;
        if(ft < 1 || used[ft]) {
            a[i] = se;
            used[se] = 1;
        }
        else if(se > n || used[se]) { 
            a[i] = ft;
            used[ft] = 1;
        }
        else {
            int y = query(i - 2, i);
            if(y == abs(a[i - 1] - a[i - 2])) {
                if(a[i - 1] > a[i - 2]) {
                    a[i] = ft, used[ft] = 1;
                }
                else {
                    a[i] = se, used[se] = 1;
                }
            }
            else {
                if(y == x) {
                    if(a[i - 1] > a[i - 2]) {
                        a[i] = ft, used[ft] = 1;
                    }
                    else {
                        a[i] = se, used[se] = 1;
                    }
                }
                else {
                    if(a[i - 1] < a[i - 2]) {
                        a[i] = a[i - 2] - y, used[a[i]] = 1;
                    }
                    else {
                        a[i] = a[i - 2] + y, used[a[i]] = 1;
                    }
                }
            }
        }
    }
    
    for(int i = 1; i <= n; ++i) {
        answer(i, a[i]);
    }
}
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n; cin >> n;
    solve(n);
    return 0;
}

Compilation message

xylophone.cpp:5:2: error: invalid preprocessing directive #incldue; did you mean #include?
    5 | #incldue "xylophone.h"
      |  ^~~~~~~
      |  include