結果

問題 No.1997 X Lighting
ユーザー 👑 emthrmemthrm
提出日時 2022-07-01 22:12:44
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 88 ms / 2,000 ms
コード長 2,733 bytes
コンパイル時間 2,788 ms
コンパイル使用メモリ 213,712 KB
実行使用メモリ 10,772 KB
最終ジャッジ日時 2023-08-17 09:43:15
合計ジャッジ時間 5,903 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 17 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 28 ms
5,092 KB
testcase_14 AC 75 ms
10,264 KB
testcase_15 AC 22 ms
4,988 KB
testcase_16 AC 29 ms
5,436 KB
testcase_17 AC 66 ms
9,228 KB
testcase_18 AC 37 ms
6,724 KB
testcase_19 AC 79 ms
10,636 KB
testcase_20 AC 88 ms
10,772 KB
testcase_21 AC 88 ms
10,456 KB
testcase_22 AC 78 ms
10,164 KB
testcase_23 AC 46 ms
6,740 KB
testcase_24 AC 4 ms
4,376 KB
testcase_25 AC 85 ms
10,332 KB
testcase_26 AC 72 ms
8,400 KB
testcase_27 AC 73 ms
8,832 KB
testcase_28 AC 26 ms
5,368 KB
testcase_29 AC 24 ms
5,008 KB
testcase_30 AC 83 ms
9,932 KB
testcase_31 AC 55 ms
7,396 KB
testcase_32 AC 16 ms
4,500 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int DY4[]{1, 0, -1, 0}, DX4[]{0, -1, 0, 1};
constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1};
constexpr int DX8[]{0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U>
inline bool chmax(T& a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U>
inline bool chmin(T& a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  ll n; int m; cin >> n >> m;
  // vector on(n, vector(n, 0));
  vector<ll> diag1, diag2;
  while (m--) {
    ll y, x; cin >> y >> x; --y; --x;
    diag1.emplace_back(y + x);
    diag2.emplace_back(n - 1 - y + x);
    // for (int k : vector<int>{1, 3, 5, 7}) {
    //   for (int r = y, c = x; 0 <= r && r < n && 0 <= c && c < n; r += DY8[k], c += DX8[k]) {
    //     on[r][c] = true;
    //   }
    // }
  }
  // REP(i, n) {
  //   REP(j, n) cout << on[i][j];
  //   cout << '\n';
  // }
  sort(ALL(diag1));
  diag1.erase(unique(ALL(diag1)), diag1.end());
  sort(ALL(diag2));
  diag2.erase(unique(ALL(diag2)), diag2.end());
  ll ans = 0;
  vector<pair<ll, ll>> seg;
  vector<ll> v[2]{{0, n * 2 - 2}, {}};
  for (ll e : diag1) {
    ll l = n * 2 - 2, r = 0;
    if (e < n) {
      l = n - 1 - e;
      r = n * 2 - 2 - (n - 1 - e);
    } else {
      l = e - (n - 1);
      r = n * 2 - 2 - (e - (n - 1));
    }
    ans += (r - l + 1 + 1) / 2;
    seg.emplace_back(l, r);
    v[l & 1].emplace_back(l);
    v[r & 1].emplace_back(r);
  }
  for (ll e : diag2) v[e & 1].emplace_back(e);
  int l[2];
  REP(p, 2) {
    sort(ALL(v[p]));
    v[p].erase(unique(ALL(v[p])), v[p].end());
    l[p] = v[p].size();
  }
  vector<int> imos[2]{vector<int>(l[0], 0), vector<int>(l[1], 0)};
  for (const auto [l, r] : seg) {
    const int le = lower_bound(ALL(v[l & 1]), l) - v[l & 1].begin();
    const int ri = lower_bound(ALL(v[r & 1]), r) - v[r & 1].begin();
    ++imos[l & 1][le];
    if (ri + 1 < v[l & 1].size()) --imos[l & 1][ri + 1];
  }
  REP(p, 2) FOR(i, 1, l[p]) imos[p][i] += imos[p][i - 1];
  for (ll e : diag2) {
    if (e < n) {
      ans += n - (n - 1 - e);
    } else {
      ans += n - (e - (n - 1));
    }
    ans -= imos[e & 1][lower_bound(ALL(v[e & 1]), e) - v[e & 1].begin()];
  }
  cout << ans << '\n';
  return 0;
}
0