Submission #590476

# Submission time Handle Problem Language Result Execution time Memory
590476 2022-07-06T02:54:33 Z Huy Xylophone (JOI18_xylophone) C++17
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
//#define int long long
#define pii pair<int,ll>
#define fi first
#define se second
/*#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")*/
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ldb = long double;
const ll N = (int)1e9 + 1;
const int maxN = (int)3e5 + 1;
const int mod = 1e9 + 7;
//const int mod = 998244353;
const ll infty = 1e18 + 7;
const int base = (int)4e5;

void InputFile()
{
    //freopen("scrivener.inp","r",stdin);
    //freopen("scrivener.out","w",stdout);
    //freopen("test.out","r",stdin);
}

void FastInput()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}

int a[5005];
int apr[5005];

void solve(int n)
{
    int low = 1;
    int high = n;
    while(low <= high)
    {
        int mid = (low + high) / 2;
        int x = query(mid,n);
        if(x == n - 1)
            low = low = mid + 1;
        else
            high = mid - 1;
    }
    answer(high,1);
    int pt = high;
    a[high] = 1;
    for(int i = pt - 1; i >= 1; i--)
    {
        int diff = query(i,i+1);
        if(a[i+1] - diff < 0)
        {
            a[i] = a[i+1] + diff;
            answer(i,a[i]);
        }
        else if(a[i+ 1] + diff > n)
        {
            a[i] = a[i+1] - diff;
            answer(i,a[i]);
        }
        else
        {
            if(apr[a[i+1]-diff])
            {
                a[i] = a[i+1] + diff;
                answer(i,a[i]);
            }
            else if(apr[a[i+1]+diff])
            {
                a[i] = a[i+1] - diff;
                answer(i,a[i]);
            }
            else
            {
                int c = a[i+1] - diff;
                int maxi,mini;
                maxi = max(max(c,a[i+1]),a[i+2]);
                mini = min(min(c,a[i+1]),a[i+2]);
                if(query(i,i+1) == maxi - mini)
                {
                    a[i] = c;
                    answer(i,c);
                }
                else answer(i,a[i+1] + diff);
            }
        }

        apr[a[i]]++;
    }

    for(int i = pt + 1; i <= n; i++)
    {
        int diff = query(i-1,i);
        if(a[i-1] - diff < 0)
        {
            a[i] = a[i-1] + diff;
            answer(i,a[i]);
        }
        else if(a[i-1] + diff > n)
        {
            a[i] = a[i-1] - diff;
            answer(i,a[i]);
        }
        else
        {
            if(apr[a[i-1]-diff])
            {
                a[i] = a[i-1] + diff;
                answer(i,a[i]);
            }
            else if(apr[a[i-1]+diff])
            {
                a[i] = a[i-1] - diff;
                answer(i,a[i]);
            }
            else
            {
                int c = a[i-1] - diff;
                int maxi,mini;
                maxi = max(max(c,a[i-1]),a[i-2]);
                mini = min(min(c,a[i-1]),a[i-2]);
                if(query(i-1,i) == maxi - mini)
                {
                    a[i] = c;
                    answer(i,c);
                }
                else answer(i,a[i-1] + diff);
            }
        }

        apr[a[i]]++;
    }
}

void Debug()
{

}


/*int32_t main()
{
    FastInput();
    //InputFile();
    //int sub_type;
    //cin >> sub_type;
    //Sieve();
    //Prepare();
    int test;
    cin >> test;
    //test = 1;
    while(test--)
        //for(int prc = 1; prc <= test; prc++)
    {
        Read();
        Solve();
        //Debug();
    }
}*/

/*
2 5
B 0 A 4
B 1 B 3
A 5 B 7
B 2 A 6
B 1 A 7
*/

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:45:17: error: 'query' was not declared in this scope
   45 |         int x = query(mid,n);
      |                 ^~~~~
xylophone.cpp:47:17: warning: operation on 'low' may be undefined [-Wsequence-point]
   47 |             low = low = mid + 1;
      |             ~~~~^~~~~~~~~~~~~~~
xylophone.cpp:51:5: error: 'answer' was not declared in this scope
   51 |     answer(high,1);
      |     ^~~~~~
xylophone.cpp:56:20: error: 'query' was not declared in this scope
   56 |         int diff = query(i,i+1);
      |                    ^~~~~
xylophone.cpp:99:20: error: 'query' was not declared in this scope
   99 |         int diff = query(i-1,i);
      |                    ^~~~~