Submission #795233

# Submission time Handle Problem Language Result Execution time Memory
795233 2023-07-27T07:42:02 Z arush_agu Xylophone (JOI18_xylophone) C++17
0 / 100
1 ms 208 KB
#include "xylophone.h"
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#ifdef DEBUG
#include <time.h>
#endif

#define all(a) (a).begin(), (a).end()
#define rev(a) (a).rbegin(), (a).rend()
#define F first
#define S second
int recur_depth = 0;
#ifdef DEBUG
#define dbg(x)                                                                 \
  {                                                                            \
    ++recur_depth;                                                             \
    auto x_ = x;                                                               \
    --recur_depth;                                                             \
    cerr << string(recur_depth, '\t') << "\e[91m" << __func__ << ":"           \
         << __LINE__ << "\t" << #x << " = " << x_ << "\e[39m" << endl;         \
  }
#else
#define dbg(x)
#endif

using namespace std;
using namespace __gnu_pbds;

typedef pair<int, int> ii;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> llll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pair<int, int>> vii;
typedef vector<vii> vvii;

typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pair<ll, ll>> vll;
typedef vector<vll> vvll;

typedef vector<bool> vb;

template <class type1>
using ordered_set = tree<type1, null_type, less<type1>, rb_tree_tag,
                         tree_order_statistics_node_update>;

template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p) {
  return os << '(' << p.first << ", " << p.second << ')';
}
template <typename T_container, typename T = typename enable_if<
                                    !is_same<T_container, string>::value,
                                    typename T_container::value_type>::type>
ostream &operator<<(ostream &os, const T_container &v) {
  os << '{';
  string sep;
  for (const T &x : v)
    os << sep << x, sep = ", ";
  return os << '}';
}

const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll INF = 1e9;
const ld EPS = 1e-9;

static int A[5000];

void solve(int N) {
  vvi q(N + 1, vi(N + 1, -1));
  int cnt = 0;
  auto ask = [&](int s, int t) {
    if (q[s][t] != -1)
      return q[s][t];
    cnt++;
    return q[s][t] = query(s, t);
  };

  vi ans(N + 1, -1);
  vi at(N + 1, -1);

  int tot = ask(1, N);
  int l = 2, r = N - 1, pos_n = N;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (ask(1, mid) != tot)
      l = mid + 1;
    else {
      pos_n = mid;
      r = mid - 1;
    }
  }

  l = 2, r = pos_n - 1;
  int pos_1 = 1;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (ask(mid, pos_n) != tot)
      r = mid - 1;
    else {
      pos_1 = mid;
      l = mid + 1;
    }
  }

  auto in_rng = [&](int x) { return 1 <= x && x <= N; };
  auto fill_place = [&](int pos, int v) {
    ans[v] = pos;
    at[pos] = v;
  };

  fill_place(pos_1, 1), fill_place(pos_n, N);
  at[pos_1] = 1, at[pos_n] = N;
  if (pos_1 + 1 < pos_n) {
    fill_place(pos_1 + 1, 1 + ask(pos_1, pos_1 + 1));

    for (int i = pos_1 + 2; i < pos_n; i++) {
      int ab = ask(i - 2, i - 1), bc = ask(i - 1, i);
      if (!in_rng(at[i - 1] + bc)) {
        fill_place(i, at[i - 1] - bc);
        continue;
      }
      if (!in_rng(at[i - 1] - bc)) {
        fill_place(i, at[i - 1] + bc);
        continue;
      }
      int ac = ask(i - 2, i);
      if (ac == ab || ac == bc) {
        if (at[i - 2] < at[i - 1])
          fill_place(i, at[i - 1] - bc);
        else
          fill_place(i, at[i - 1] + bc);
      } else {
        if (at[i - 2] < at[i - 1])
          fill_place(i, at[i - 1] + bc);
        else
          fill_place(i, at[i - 1] - bc);
      }
    }
  }

  if (pos_n < N) {
    fill_place(pos_n + 1, N - ask(pos_n, pos_n + 1));
    for (int i = pos_n + 2; i <= N; i++) {
      int ab = ask(i - 2, i - 1), bc = ask(i - 1, i);
      if (!in_rng(at[i - 1] + bc)) {
        fill_place(i, at[i - 1] - bc);
        continue;
      }
      if (!in_rng(at[i - 1] - bc)) {
        fill_place(i, at[i - 1] + bc);
        continue;
      }
      int ac = ask(i - 2, i);
      if (ac == ab || ac == bc) {
        if (at[i - 2] < at[i - 1])
          fill_place(i, at[i - 1] - bc);
        else
          fill_place(i, at[i - 1] + bc);
      } else {
        if (at[i - 2] < at[i - 1])
          fill_place(i, at[i - 1] + bc);
        else
          fill_place(i, at[i - 1] - bc);
      }
    }
  }

  if (pos_1 > 1) {
    fill_place(pos_1 - 1, 1 + ask(pos_1 - 1, pos_1));
    for (int i = pos_1 - 2; i >= 1; i--) {
      int ab = ask(i, i + 1), bc = ask(i + 1, i + 2);
      if (!in_rng(at[i + 1] + bc)) {
        fill_place(i, at[i + 1] - bc);
        continue;
      }
      if (!in_rng(at[i + 1] - bc)) {
        fill_place(i, at[i + 1] + bc);
        continue;
      }
      int ac = ask(i, i + 2);
      if (ac == bc || ac == ab) {
        if (at[i + 1] < at[i + 2])
          fill_place(i, at[i + 1] + ab);
        else
          fill_place(i, at[i + 1] - ab);
      } else {
        if (at[i + 1] < at[i + 2])
          fill_place(i, at[i + 1] - ab);
        else
          fill_place(i, at[i + 1] + ab);
      }
    }
  }

  for (int i = 1; i <= N; i++)
    answer(i, at[i]);
}

Compilation message

xylophone.cpp:93:12: warning: 'A' defined but not used [-Wunused-variable]
   93 | static int A[5000];
      |            ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Incorrect 1 ms 208 KB Wrong Answer [7]
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Incorrect 1 ms 208 KB Wrong Answer [7]
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Incorrect 1 ms 208 KB Wrong Answer [7]
4 Halted 0 ms 0 KB -