Submission #363299

#TimeUsernameProblemLanguageResultExecution timeMemory
363299teewarXylophone (JOI18_xylophone)C++14
Compilation error
0 ms0 KiB
#include "xylophone.h"
#include <cmath>
#include <cassert>

using namespace std;

void solve(int n) {
    int a[n + 1];
    int l = 1, r = n;
    while(r - l > 1) {
        int m = (l + r) / 2;
        if(query(1, m) >= n - 1) {
            r = m;
        }
        else {
            l = m;
        }
    }
    int mxid = r;
    a[mxid] = n;
    unordered_set<int> free;
    for(int i = 1; i < n; ++i) {
        free.insert(i);
    }
    if(mxid > 1) {
        a[mxid - 1] = a[mxid] - query(mxid - 1, mxid);
        free.erase(a[mxid - 1]);
    }
    if(mxid + 1 <= n) {
        a[mxid + 1] = a[mxid] - query(mxid, mxid + 1);
        free.erase(a[mxid + 1]);
    }
    for(int i = mxid + 2; i <= n; ++i) {
        int p = query(i - 1, i);
        int val1 = a[i - 1] - p;
        int val2 = a[i - 1] + p;
        if(!free.count(val1)) {
            a[i] = val2;
            continue;
        }
        if(!free.count(val2)) {
            a[i] = val1;
            continue;
        }
        int t = query(i - 2, i);
        if(abs(a[i - 1] - a[i - 2]) + p == t) {
            if(a[i - 2] < a[i - 1]) {
                a[i] = val2;
            }
            else {
                a[i] = val1;
            }
        }
        else {
            if(a[i - 2] < a[i - 1]) {
                a[i] = val1;
            }
            else {
                a[i] = val2;
            }
        }
    }
    for(int i = mxid - 2; i >= 1; --i) {
        int p = query(i, i + 1);
        int val1 = a[i + 1] - p;
        int val2 = a[i + 1] + p;
        if(!free.count(val1)) {
            a[i] = val2;
            continue;
        }
        if(!free.count(val2)) { 
            a[i] = val1;
            continue;
        }
        int t = query(i, i + 2);
        if(abs(a[i + 1] - a[i + 2]) + p == t) {
            if(a[i + 1] < a[i + 2]) {
                a[i] = val1;
            }
            else {
                a[i] = val2;
            }
        }
        else {
            if(a[i + 1] < a[i + 2]) {
                a[i] = val2;
            }
            else {
                a[i] = val1;
            }
        }
    }
    for(int i = 1; i <= n; ++i) {
        answer(i, a[i]);
    }
}

Compilation message (stderr)

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:21:5: error: 'unordered_set' was not declared in this scope
   21 |     unordered_set<int> free;
      |     ^~~~~~~~~~~~~
xylophone.cpp:4:1: note: 'std::unordered_set' is defined in header '<unordered_set>'; did you forget to '#include <unordered_set>'?
    3 | #include <cassert>
  +++ |+#include <unordered_set>
    4 | 
xylophone.cpp:21:19: error: expected primary-expression before 'int'
   21 |     unordered_set<int> free;
      |                   ^~~
xylophone.cpp:23:14: error: request for member 'insert' in 'free', which is of non-class type 'void(void*) throw ()' {aka 'void(void*)'}
   23 |         free.insert(i);
      |              ^~~~~~
xylophone.cpp:27:14: error: request for member 'erase' in 'free', which is of non-class type 'void(void*) throw ()' {aka 'void(void*)'}
   27 |         free.erase(a[mxid - 1]);
      |              ^~~~~
xylophone.cpp:31:14: error: request for member 'erase' in 'free', which is of non-class type 'void(void*) throw ()' {aka 'void(void*)'}
   31 |         free.erase(a[mxid + 1]);
      |              ^~~~~
xylophone.cpp:37:18: error: request for member 'count' in 'free', which is of non-class type 'void(void*) throw ()' {aka 'void(void*)'}
   37 |         if(!free.count(val1)) {
      |                  ^~~~~
xylophone.cpp:41:18: error: request for member 'count' in 'free', which is of non-class type 'void(void*) throw ()' {aka 'void(void*)'}
   41 |         if(!free.count(val2)) {
      |                  ^~~~~
xylophone.cpp:67:18: error: request for member 'count' in 'free', which is of non-class type 'void(void*) throw ()' {aka 'void(void*)'}
   67 |         if(!free.count(val1)) {
      |                  ^~~~~
xylophone.cpp:71:18: error: request for member 'count' in 'free', which is of non-class type 'void(void*) throw ()' {aka 'void(void*)'}
   71 |         if(!free.count(val2)) {
      |                  ^~~~~