結果

問題 No.2574 Defect-free Rectangles
ユーザー KumaTachiRenKumaTachiRen
提出日時 2023-12-02 16:54:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,191 ms / 2,000 ms
コード長 1,951 bytes
コンパイル時間 5,257 ms
コンパイル使用メモリ 266,496 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2023-12-02 16:54:31
合計ジャッジ時間 10,221 ms
ジャッジサーバーID
(参考情報)
judge10 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 3 ms
6,548 KB
testcase_04 AC 5 ms
6,548 KB
testcase_05 AC 4 ms
6,548 KB
testcase_06 AC 185 ms
6,548 KB
testcase_07 AC 68 ms
6,548 KB
testcase_08 AC 60 ms
6,548 KB
testcase_09 AC 1,144 ms
6,548 KB
testcase_10 AC 366 ms
6,548 KB
testcase_11 AC 1,188 ms
6,548 KB
testcase_12 AC 1,191 ms
6,548 KB
testcase_13 AC 22 ms
6,548 KB
testcase_14 AC 349 ms
6,548 KB
testcase_15 AC 197 ms
6,548 KB
testcase_16 AC 67 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using namespace atcoder;

struct Fast {
  Fast() {
    std::cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(10);
  }
} fast;

#define all(a) (a).begin(), (a).end()
#define contains(a, x) ((a).find(x) != (a).end())
#define rep(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (a); i--)
#define YN(b) cout << ((b) ? "YES" : "NO") << "\n";
#define Yn(b) cout << ((b) ? "Yes" : "No") << "\n";
#define yn(b) cout << ((b) ? "yes" : "no") << "\n";

template <typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  }
  return os;
}

using ll = long long;
using vb = vector<bool>;
using vvb = vector<vb>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

using mint = modint998244353;
using vm = vector<mint>;
using vvm = vector<vm>;
inline ostream& operator<<(ostream& os, const mint P) { return os << P.val(); };

int op(int x, int y) { return x + y; }
int e() { return 0; }
bool g(int x) { return x == 0; }

void solve() {
  int h, w, n;
  cin >> h >> w >> n;
  vvi b(h, vi());
  rep(i, 0, n) {
    int u, v;
    cin >> u >> v;
    b[u - 1].push_back(v - 1);
  }

  ll ans = 0;
  rep(r, 0, h) {
    segtree<int, op, e> seg(w);
    ll sum = (ll)w * (w + 1) / 2;
    vector<bool> f(w, false);
    rep(x, r, h) {
      for (auto y : b[x]) {
        if (f[y]) continue;
        f[y] = true;
        int l = seg.min_left<g>(y);
        int r = seg.max_right<g>(y);
        ll d = r - l;
        sum -= d * (d + 1) / 2;
        ll d1 = y - l, d2 = r - (y + 1);
        sum += d1 * (d1 + 1) / 2 + d2 * (d2 + 1) / 2;
        seg.set(y, 1);
      }
      ans += sum;
    }
  }
  cout << ans << "\n";
}

int main() {
  int t = 1;
  // cin >> t;
  while (t--) solve();
}
0