Submission #1368890

#TimeUsernameProblemLanguageResultExecution timeMemory
1368890altern23Xylophone (JOI18_xylophone)C++20
47 / 100
17 ms448 KiB
#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;

#define ll long long

void solve(int N) {
      ll lf = 1, rg = N, ptr = -1;
      while (lf<=rg) {
            ll mid = (lf+rg)/2;
            if (query(1, mid) == N-1) {
                  ptr = mid;
                  rg = mid-1;
            }
            else lf = mid+1;
      }

      vector <ll> A(N+5);
      A[ptr] = N;

      // tentuin yang kanan
      ll lst = -1;
      bool arah = 0;

      if (ptr+1 <= N) {
            lst = query(ptr, ptr+1);
            A[ptr+1] = N-lst;
      }

      for (int i=ptr+2; i<=N; i++) {
            ll z = query(i-1, i);
            ll y = query(i-2, i);
            if (z+lst != y) arah ^= 1;
            if (!arah) A[i] = A[i-1]-z;
            else A[i] = A[i-1]+z;
            lst = z;
      }

      // tentuin yg kiri
      arah = 0;
      if (ptr-1 >= 1) {
            lst = query(ptr-1, ptr);
            A[ptr-1] = N-lst;
      }

      for (int i=ptr-2; i>=1; --i) {
            ll z = query(i, i+1);
            ll y = query(i, i+2);
            if (z+lst != y) arah ^= 1;
            if (!arah) A[i] = A[i+1]-z;
            else A[i] = A[i+1]+z;
            lst = z;
      }
      
      for (int i=1; i<=N; i++) answer(i, A[i]);
}
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...