Submission #94328

# Submission time Handle Problem Language Result Execution time Memory
94328 2019-01-17T18:02:02 Z fedoseevtimofey Xylophone (JOI18_xylophone) C++14
Compilation error
0 ms 0 KB
#include "xylophone.h"

int my_query(int l, int r, vector <int> &a) {
    int mx = -1e9, mn = 1e9;
    for (int i = l; i <= r; ++i) {
        mx = max(mx, a[i]);
        mn = min(mn, a[i]);
    }
    return mx - mn;
}

void solve(int n) {
    int r = n;
    while (query(1, r) == n - 1) --r;
    ++r;
    vector <int> a(n + 1, -1);
    a[r] = n;
    if (r != n) {
        a[r + 1] = n - query(r, r + 1);
    }
    if (r != 1) {
        a[r - 1] = n - query(r - 1, r);
    }
    for (int i = r - 2; i >= 1; --i) {
        int x = query(i, i + 1);
        int y = query(i, i + 2);
        for (int z = 1; z <= n; ++z) {
            a[i] = z;
            if (my_query(i, i + 1, a) == x && my_query(i, i + 2, a) == y) {
                break;
            }
        }
        assert(a[i] != -1);
    }
    for (int i = r + 2; i <= n; ++i) {
        int x = query(i - 1, i);
        int y = query(i - 2, i);
        for (int z = 1; z <= n; ++z) {
            a[i] = z;
            if (my_query(i - 1, i, a) == x && my_query(i - 2, i, a) == y) {
                break;
            }
        }
        assert(a[i] != -1);
    }
    for (int i = 1; i <= n; ++i) {
        answer(i, a[i]);
    }
}

Compilation message

xylophone.cpp:3:28: error: 'vector' has not been declared
 int my_query(int l, int r, vector <int> &a) {
                            ^~~~~~
xylophone.cpp:3:35: error: expected ',' or '...' before '<' token
 int my_query(int l, int r, vector <int> &a) {
                                   ^
xylophone.cpp: In function 'int my_query(int, int, int)':
xylophone.cpp:6:22: error: 'a' was not declared in this scope
         mx = max(mx, a[i]);
                      ^
xylophone.cpp:6:14: error: 'max' was not declared in this scope
         mx = max(mx, a[i]);
              ^~~
xylophone.cpp:6:14: note: suggested alternative: 'mx'
         mx = max(mx, a[i]);
              ^~~
              mx
xylophone.cpp:7:14: error: 'min' was not declared in this scope
         mn = min(mn, a[i]);
              ^~~
xylophone.cpp:7:14: note: suggested alternative: 'mn'
         mn = min(mn, a[i]);
              ^~~
              mn
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:16:5: error: 'vector' was not declared in this scope
     vector <int> a(n + 1, -1);
     ^~~~~~
xylophone.cpp:16:13: error: expected primary-expression before 'int'
     vector <int> a(n + 1, -1);
             ^~~
xylophone.cpp:17:5: error: 'a' was not declared in this scope
     a[r] = n;
     ^
xylophone.cpp:33:9: error: 'assert' was not declared in this scope
         assert(a[i] != -1);
         ^~~~~~
xylophone.cpp:33:9: note: suggested alternative: 'answer'
         assert(a[i] != -1);
         ^~~~~~
         answer
xylophone.cpp:44:9: error: 'assert' was not declared in this scope
         assert(a[i] != -1);
         ^~~~~~
xylophone.cpp:44:9: note: suggested alternative: 'answer'
         assert(a[i] != -1);
         ^~~~~~
         answer