結果

問題 No.1074 増殖
ユーザー 👑 emthrmemthrm
提出日時 2020-06-05 21:54:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 750 ms / 2,000 ms
コード長 4,035 bytes
コンパイル時間 2,386 ms
コンパイル使用メモリ 207,596 KB
実行使用メモリ 5,312 KB
最終ジャッジ日時 2023-08-22 15:15:00
合計ジャッジ時間 8,550 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,096 KB
testcase_01 AC 3 ms
5,312 KB
testcase_02 AC 3 ms
5,128 KB
testcase_03 AC 3 ms
5,064 KB
testcase_04 AC 3 ms
5,156 KB
testcase_05 AC 4 ms
5,076 KB
testcase_06 AC 648 ms
5,112 KB
testcase_07 AC 506 ms
5,124 KB
testcase_08 AC 576 ms
5,144 KB
testcase_09 AC 750 ms
5,092 KB
testcase_10 AC 494 ms
5,124 KB
testcase_11 AC 479 ms
5,144 KB
testcase_12 AC 480 ms
5,068 KB
testcase_13 AC 623 ms
5,140 KB
testcase_14 AC 623 ms
5,124 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;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, 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() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

template <typename Monoid>
struct RSQandRUQ {
  RSQandRUQ(int sz, const Monoid UNITY = 0) : UNITY(UNITY) {
    init(sz);
    dat.assign((n << 1) - 1, UNITY);
  }

  RSQandRUQ(const vector<Monoid> &a, const Monoid UNITY = 0) : UNITY(UNITY) {
    int a_sz = a.size();
    init(a_sz);
    dat.resize((n << 1) - 1);
    REP(i, a_sz) dat[n - 1 + i] = a[i];
    for (int i = n - 2; i >= 0; --i) dat[i] = dat[(i << 1) + 1] + dat[(i << 1) + 2];
  }

  void update(int a, int b, Monoid val) { update(a, b, val, 0, 0, n); }

  Monoid sum(int a, int b) { return sum(a, b, 0, 0, n); }

  Monoid operator[](const int idx) { return sum(idx, idx + 1); }

  int find(int a, int b, Monoid val) { return find(a, b, val, 0, 0, n); }

private:
  int n = 1;
  const Monoid UNITY;
  vector<Monoid> dat, lazy;
  vector<bool> need_to_be_eval;

  void init(int sz) {
    while (n < sz) n <<= 1;
    lazy.assign((n << 1) - 1, UNITY);
    need_to_be_eval.assign((n << 1) - 1, false);
  }

  inline void evaluate(int node, int left, int right) {
    if (need_to_be_eval[node]) {
      dat[node] = (right - left) * lazy[node];
      if (node < n - 1) {
        lazy[(node << 1) + 1] = lazy[(node << 1) + 2] = lazy[node];
        need_to_be_eval[(node << 1) + 1] = need_to_be_eval[(node << 1) + 2] = true;
      }
      lazy[node] = UNITY;
      need_to_be_eval[node] = false;
    }
  }

  void update(int a, int b, Monoid val, int node, int left, int right) {
    evaluate(node, left, right);
    if (right <= a || b <= left) return;
    if (a <= left && right <= b) {
      lazy[node] = val;
      need_to_be_eval[node] = true;
      evaluate(node, left, right);
    } else {
      update(a, b, val, (node << 1) + 1, left, (left + right) >> 1);
      update(a, b, val, (node << 1) + 2, (left + right) >> 1, right);
      dat[node] = dat[(node << 1) + 1] + dat[(node << 1) + 2];
    }
  }

  Monoid sum(int a, int b, int node, int left, int right) {
    evaluate(node, left, right);
    if (right <= a || b <= left) return UNITY;
    if (a <= left && right <= b) return dat[node];
    return sum(a, b, (node << 1) + 1, left, (left + right) >> 1) + sum(a, b, (node << 1) + 2, (left + right) >> 1, right);
  }

  int find(int a, int b, Monoid val, int node, int left, int right) {
    evaluate(node, left, right);
    if (dat[node] < val || right <= a || b <= left) return -1;
    if (right - left == 1) return node - (n - 1);
    int res_l = find(a, b, val, (node << 1) + 1, left, (left + right) >> 1);
    if (res_l != -1) return res_l;
    return find(a, b, val, (node << 1) + 2, (left + right) >> 1, right);
  }
};

int main() {
  int n; cin >> n;
  struct Solver {
    RSQandRUQ<int> rsq;
    Solver() : rsq(20001) {}
    int add(int x, int y) {
      int lb = -1, ub = 20001;
      while (ub - lb > 1) {
        int mid = (lb + ub) / 2;
        (rsq[mid] >= y ? lb : ub) = mid;
      }
      if (x <= ub) return 0;
      int sum = rsq.sum(ub, x);
      rsq.update(ub, x, y);
      return (x - ub) * y - sum;
    }
  };
  Solver a, b, c, d;
  while (n--) {
    int xa, ya, xb, yb; cin >> xa >> ya >> xb >> yb;
    cout << a.add(xb, yb) + b.add(-xa, yb) + c.add(-xa, -ya) + d.add(xb, -ya) << '\n';
  }
  return 0;
}
0