QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#851844#9776. Best Friend, Worst Enemynhuang685TL 0ms3628kbC++234.2kb2025-01-11 07:20:562025-01-11 07:20:56

Judging History

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

  • [2025-01-11 07:20:56]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3628kb
  • [2025-01-11 07:20:56]
  • 提交

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

  int n;
  std::cin >> n;

  std::vector<int> x(n), y(n), cv(n), mx_m(n), mi_c(n, INF<int>);
  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) {
    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;
      }
      bool g = true;
      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]];
          inds.erase(inds.begin() + k);
          g = false;
          break;
        }
      }
      for (int k : inds) {
        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 (g) {
        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;            
          }
        }
      }
    }
  };

  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;
    }
    bool g = true;
    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;
        inds.erase(inds.begin() + j);
        g = false;
        break;
      }
    }
    for (int j = 0; j < i; ++j) {
      mi_c[i] = std::min(mi_c[i], che(j, i));
    }
    for (int j : inds) {
      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 (g) {
        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';
  }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
1 5
1 10

output:

0
2

result:

ok 2 number(s): "0 2"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3628kb

input:

4
2 5
5 3
5 7
8 5

output:

0
2
4
4

result:

ok 4 number(s): "0 2 4 4"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3556kb

input:

9
3 4
3 6
4 3
4 7
5 5
6 3
6 7
7 4
7 6

output:

0
2
1
0
4
5
6
7
8

result:

ok 9 numbers

Test #4:

score: 0
Accepted
time: 0ms
memory: 3504kb

input:

13
3 5
4 4
4 5
4 6
5 3
5 4
5 5
5 6
5 7
6 4
6 5
6 6
7 5

output:

0
2
4
7
2
2
5
2
2
3
3
4
4

result:

ok 13 numbers

Test #5:

score: -100
Time Limit Exceeded

input:

384010
200000 1000000
200000 1000001
199999 1000000
200001 1000000
200000 999999
200000 1000002
200002 1000000
200000 999998
199998 1000000
199997 1000000
200003 1000000
200000 999997
200000 1000003
199996 1000000
200004 1000000
200000 1000004
200000 999996
199995 1000000
200000 1000005
200000 99999...

output:

0
2
4
7
12
2
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0...

result: