Submission #1107714

# Submission time Handle Problem Language Result Execution time Memory
1107714 2024-11-02T03:44:27 Z KK_1729 Xylophone (JOI18_xylophone) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

// #define int long long
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define pb push_back
#define all(a) a.begin(), a.end()
#define endl "\n"

void printVector(vector<int> a){
    for (auto x: a) cout << x << " ";
    cout << endl;
}
void solve(int n){
    vector<int> diff(n+1);
    FOR(i,1,n){
        diff[i] = query(i, i+1);
    }

    vector<int> type(n+1, -1);
    type[1] = 1;
    FOR(i,1,n-1){
        int e = query(i, i+2);
        if (e == diff[i]+diff[i+1]){
            type[i+1] = type[i];
        }else{
            type[i+1] = type[i]^1;
        }
    }
    vector<int> a(n+1);

    FOR(i,1,n){
        if (type[i] == 1){
            a[i+1] = a[i]+diff[i];
        }else{
            a[i+1] = a[i]-diff[i];
        }
        
    }
    
    int mini = 1e9; int maxi = 0;
    int minind = 0; int maxind = 0;
    FOR(i,1,n+1){
        if (a[i] < mini){
            minind = i;
        }
        if (a[i] > maxi){
            maxind = i;
        }
        mini = min(mini, a[i]);
        maxi = max(maxi, a[i]);

    }
    // printVector(a);
    if (maxi - mini == n-1 && maxind > minind){
        FOR(i,1,n+1){
            answer(i, a[i]-(mini-1));
        }
        return;
    }
    a.clear();a.resize(n+1);
    FOR(i,1,n){
        if (type[i] == 1){
            a[i+1] = a[i]-diff[i];
        }else{
            a[i+1] = a[i]+diff[i];
        }
        
    }

    mini = 1e9; maxi = 0;
    FOR(i,1,n+1){
        mini = min(mini, a[i]);maxi = max(maxi, a[i]);
    }
    FOR(i,1,n+1){
        answer(i, a[i]-(mini-1));
    }
    return;
}
int32_t main(){
    solve(7);
}

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:17:19: error: 'query' was not declared in this scope
   17 |         diff[i] = query(i, i+1);
      |                   ^~~~~
xylophone.cpp:23:17: error: 'query' was not declared in this scope
   23 |         int e = query(i, i+2);
      |                 ^~~~~
xylophone.cpp:57:13: error: 'answer' was not declared in this scope
   57 |             answer(i, a[i]-(mini-1));
      |             ^~~~~~
xylophone.cpp:76:9: error: 'answer' was not declared in this scope
   76 |         answer(i, a[i]-(mini-1));
      |         ^~~~~~