제출 #469159

#제출 시각아이디문제언어결과실행 시간메모리
469159Killer2501Xylophone (JOI18_xylophone)C++14
100 / 100
133 ms452 KiB
#include <bits/stdc++.h>
#include "xylophone.h"

#define ll long long
#define pb push_back
using namespace std;
const int N = 1e5 + 5;
int n, m, a[N], b[N], x[N];

void solve(int n)
{
    //cout << "ok" << '\n';
    for (int i = 2; i <= n; i++)
    {
        a[i] = query(i - 1, i);
    }

    b[2] = 1;

    for (int i = 3; i <= n; i++)
    {
        if (a[i] + a[i - 1] == query(i - 2, i))
            b[i] = b[i - 1];
        else
            b[i] = -b[i - 1];
    }

    int mx = 0, mn = 0, idn = 1, idx = 1;
    for (int i = 2; i <= n; i++)
    {
        a[i] = a[i] * b[i] + a[i - 1];
        if (a[i] > mx)
        {
            idx = i;
            mx = a[i];
        }
        if (a[i] < mn)
        {
            idn = i;
            mn = a[i];
        }
        //cout << a[i] << " ";
    }
    //cout << '\n';
    //cout << idn << " " << idx << '\n';
    if (idn < idx)
    {
        for (int i = 1; i <= n; i++)
            a[i] += 1 - mn;
    }
    else
        for (int i = 1; i <= n; i++)
            a[i] = -a[i] + mn + n;
    for (int i = 1; i <= n; i++)
        answer(i, a[i]);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...