QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#851846#9776. Best Friend, Worst Enemynhuang685WA 0ms3796kbC++234.5kb2025-01-11 07:42:052025-01-11 07:42:05

Judging History

你现在查看的是最新测评结果

  • [2025-01-11 07:42:05]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3796kb
  • [2025-01-11 07:42:05]
  • 提交

answer

/**
 * @author n685
 * @date 2025-01-10 15:46:13
 */
#include "bits/stdc++.h"

#ifdef LOCAL
#include "dd/debug.h"
#else
#define dbg(...) 42
#define dbg_proj(...) 420
#define dbg_rproj(...) 420420
void nline() {}
void bar() {}
void start_clock() {}
void end_clock() {}
#endif

namespace rs = std::ranges;
namespace rv = std::views;

using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

template <class T> constexpr T INF = T{};
template <std::floating_point T>
constexpr T INF<T> = std::numeric_limits<T>::infinity();
template <> constexpr int INF<int> = 0x3f3f3f3f; // 1061109567
template <>
constexpr long long INF<long long>
  = 0x3f3f3f3f3f3f3f3fLL; // 4557430888798830399

int main() {
#ifndef LOCAL
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
#endif
  start_clock();

  int n;
  std::cin >> n;

  std::vector<int> x(n), y(n), cv(n), mx_m(n), mi_c(n, INF<int>);
  std::vector<bool> good(n);
  for (int i = 0; i < n; ++i) {
    std::cin >> x[i] >> y[i];
  }
  auto mh = [&](int i, int j) {
    return std::abs(x[i] - x[j]) + std::abs(y[i] - y[j]);
  };
  auto che = [&](int i, int j) {
    return std::max(std::abs(x[i] - x[j]), std::abs(y[i] - y[j]));
  };

  int l = mh(0, 1);
  auto len = [&]() { return std::max(1, l / 4); };

  int ans = 2;
  std::vector<int> inds{0, 1};
  int pp = std::max(x[0] + y[0], x[1] + y[1]),
      pm = std::max(x[0] - y[0], x[1] - y[1]),
      mp = std::max(-x[0] + y[0], -x[1] + y[1]),
      mm = std::max(-x[0] - y[0], -x[1] - y[1]);
  mx_m[0] = l;
  mi_c[0] = che(0, 1);
  mx_m[1] = l;
  mi_c[1] = mi_c[0];
  cv[0] = 1;
  cv[1] = 1;
  auto build = [&](int i) {
    good.assign(n, true);
    dbg(l);
    start_clock();
    ans = 0;
    for (int j = 0; j <= i; ++j) {
      mx_m[j] = std::max(
        {pp - x[j] - y[j], y[j] + pm - x[j], x[j] + mp - y[j], x[j] + y[j] + mm}
      );
      cv[j] = 0;
      if (j == 0) {
        inds = {0};
        continue;
      }
      for (int k = 0; k < std::ssize(inds); ++k) {
        if (x[j] / len() == x[inds[k]] / len()
            && y[j] / len() == y[inds[k]] / len())
        {
          ans -= cv[inds[k]];
          good[j] = false;
          good[inds[k]] = false;
          break;
        }
      }
      for (int k : inds) {
        if (!good[k]) {
          continue;
        }
        if (che(k, j) < mi_c[k]) {
          mi_c[k] = che(k, j);
          ans -= cv[k];
          cv[k] = 0;
        }
        if (mh(k, j) == mx_m[k] && che(k, j) == mi_c[k]) {
          ++cv[k];
          ++ans;
        }
      }
      if (good[j]) {
        inds.push_back(j);
        for (int k = 0; k < j; ++k) {
          mi_c[j] = std::min(mi_c[j], che(k, j));
        }
        for (int k = 0; k < j; ++k) {
          if (mh(k, j) == mx_m[j] && che(k, j) == mi_c[j]) {
            ++cv[j];
            ++ans;
          }
        }
      }
    }
    end_clock();
  };

  std::cout << "0\n";
  std::cout << "2\n";
  for (int i = 2; i < n; ++i) {
    pp = std::max(pp, x[i] + y[i]);
    pm = std::max(pm, x[i] - y[i]);
    mp = std::max(mp, -x[i] + y[i]);
    mm = std::max(mm, -x[i] - y[i]);
    mx_m[i] = std::max(
      {pp - x[i] - y[i], y[i] + pm - x[i], x[i] + mp - y[i], x[i] + y[i] + mm}
    );
    if (mx_m[i] >= 2 * l) {
      l = mx_m[i];
      build(i);
      std::cout << ans << '\n';
      continue;
    }
    for (int j = 0; j < std::ssize(inds); ++j) {
      if (x[i] / len() == x[inds[j]] / len()
          && y[i] / len() == y[inds[j]] / len())
      {
        ans -= cv[inds[j]];
        cv[inds[j]] = 0;
        good[i] = false;
        good[inds[j]] = false;
        break;
      }
    }
    for (int j : inds) {
      if (!good[j]) {
        continue;
      }
      int nm = std::max(
        {pp - x[j] - y[j], y[j] + pm - x[j], x[j] + mp - y[j], x[j] + y[j] + mm}
      );
      int nc = std::min(mi_c[j], che(j, i));
      if (nm > mx_m[j] || nc < mi_c[j]) {
        ans -= cv[j];
        cv[j] = 0;
      }
      mx_m[j] = nm;
      mi_c[j] = nc;
      if (mh(j, i) == mx_m[j] && che(j, i) == mi_c[j]) {
        ++cv[j];
        ++ans;
      }
    }
    if (good[i]) {
      for (int j = 0; j < i; ++j) {
        mi_c[i] = std::min(mi_c[i], che(j, i));
      }
      for (int j = 0; j < i; ++j) {
        cv[i] += mh(j, i) == mx_m[i] && che(j, i) == mi_c[i];
      }
      ans += cv[i];
      inds.push_back(i);
    }
    std::cout << ans << '\n';
  }

  end_clock();
}


詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3796kb

input:

2
1 5
1 10

output:

0
2

result:

ok 2 number(s): "0 2"

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3568kb

input:

4
2 5
5 3
5 7
8 5

output:

0
2
2
2

result:

wrong answer 3rd numbers differ - expected: '4', found: '2'