Submission #433862

#TimeUsernameProblemLanguageResultExecution timeMemory
433862LouayFarahXylophone (JOI18_xylophone)C++14
Compilation error
0 ms0 KiB
void solve(int n)
{
    vector<int> arr(n+1);
    /*for(auto elt: arr)
        cout << elt << ' ';
    cout << endl;*/
    orig.resize(n+1);
    /*for(int i = 1; i<=n; i++)
        cin >> orig[i];*/

    int l = 1, r = n-1;
    int maxdif = n-1;
    while(maxdif==n-1)
    {
        maxdif = query(l, r);
        r--;
    }
    r+=2, l++;
    maxdif = n-1;
    while(maxdif==n-1)
    {
        maxdif = query(l, r);
        l++;
    }
    l-=2;

    arr[l] = 1;
    arr[r] = n;

    //cout << l << ' ' << r << endl;

    if(r-l>1)
    {
        maxdif = query(l, l+1);
        arr[l+1] = maxdif+1;
    }

    for(int i = l+2; i<r; i++)
    {
        int dif = query(l, i);
        if(dif==maxdif)
        {
            int dif2 = query(l+1, i);
            arr[i] = arr[l+1]-dif2;
        }
        else
        {
            arr[i] = dif + 1;
        }
    }

    if(l>1)
    {
        maxdif = query(l-1, l);
        arr[l-1] = maxdif+1;
    }
    for(int i = l-2; i>=1; i--)
    {
        int dif = query(i, l);
        if(dif==maxdif)
        {
            int dif2 = query(l-1, i);
            arr[i] = arr[l-1]-dif2;
        }
        else
        {
            arr[i] = dif+1;
        }
    }
    if(r<n)
    {
        maxdif = query(r, r+1);
        arr[r+1] = n-maxdif;
    }

    for(int i = r+2; r<=n; r++)
    {
        int dif = query(r, i);
        if(dif==maxdif)
        {
            int dif2 = query(r+1, i);
            //cout << i << ' ' << arr[r+1] << ' ' << dif2 << endl;
            arr[i] = arr[r+1] + dif2;
        }
        else
        {
            arr[i] = n-dif;
        }
    }

    /*for(auto elt: arr)
        cout << elt << ' ';
    cout << endl;*/
    
    for(int i = 1; i<=n; i++)
    {
        answer(i, arr[i]);
    }
}

Compilation message (stderr)

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:3:5: error: 'vector' was not declared in this scope
    3 |     vector<int> arr(n+1);
      |     ^~~~~~
xylophone.cpp:3:12: error: expected primary-expression before 'int'
    3 |     vector<int> arr(n+1);
      |            ^~~
xylophone.cpp:7:5: error: 'orig' was not declared in this scope
    7 |     orig.resize(n+1);
      |     ^~~~
xylophone.cpp:15:18: error: 'query' was not declared in this scope
   15 |         maxdif = query(l, r);
      |                  ^~~~~
xylophone.cpp:22:18: error: 'query' was not declared in this scope
   22 |         maxdif = query(l, r);
      |                  ^~~~~
xylophone.cpp:27:5: error: 'arr' was not declared in this scope
   27 |     arr[l] = 1;
      |     ^~~
xylophone.cpp:34:18: error: 'query' was not declared in this scope
   34 |         maxdif = query(l, l+1);
      |                  ^~~~~
xylophone.cpp:40:19: error: 'query' was not declared in this scope
   40 |         int dif = query(l, i);
      |                   ^~~~~
xylophone.cpp:54:18: error: 'query' was not declared in this scope
   54 |         maxdif = query(l-1, l);
      |                  ^~~~~
xylophone.cpp:59:19: error: 'query' was not declared in this scope
   59 |         int dif = query(i, l);
      |                   ^~~~~
xylophone.cpp:72:18: error: 'query' was not declared in this scope
   72 |         maxdif = query(r, r+1);
      |                  ^~~~~
xylophone.cpp:78:19: error: 'query' was not declared in this scope
   78 |         int dif = query(r, i);
      |                   ^~~~~
xylophone.cpp:97:9: error: 'answer' was not declared in this scope
   97 |         answer(i, arr[i]);
      |         ^~~~~~