結果

問題 No.855 ヘビの日光浴
ユーザー pekempeypekempey
提出日時 2019-07-27 01:37:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,796 bytes
コンパイル時間 2,313 ms
コンパイル使用メモリ 195,156 KB
実行使用メモリ 14,600 KB
最終ジャッジ日時 2024-10-01 20:51:58
合計ジャッジ時間 10,836 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,820 KB
testcase_01 AC 2 ms
6,820 KB
testcase_02 AC 2 ms
6,816 KB
testcase_03 WA -
testcase_04 AC 2 ms
6,820 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 2 ms
6,816 KB
testcase_14 AC 2 ms
6,816 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 2 ms
6,820 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 2 ms
6,820 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 AC 2 ms
6,820 KB
testcase_56 WA -
testcase_57 AC 2 ms
6,816 KB
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 AC 2 ms
6,816 KB
testcase_62 WA -
testcase_63 AC 2 ms
6,816 KB
testcase_64 WA -
testcase_65 WA -
testcase_66 WA -
testcase_67 WA -
testcase_68 WA -
testcase_69 WA -
testcase_70 WA -
testcase_71 WA -
testcase_72 WA -
testcase_73 WA -
testcase_74 WA -
testcase_75 WA -
testcase_76 WA -
testcase_77 WA -
testcase_78 WA -
testcase_79 WA -
testcase_80 WA -
testcase_81 WA -
testcase_82 WA -
testcase_83 AC 404 ms
14,464 KB
testcase_84 AC 410 ms
14,464 KB
testcase_85 AC 409 ms
14,472 KB
testcase_86 AC 411 ms
14,600 KB
testcase_87 AC 411 ms
14,472 KB
testcase_88 AC 400 ms
14,472 KB
testcase_89 AC 401 ms
14,472 KB
testcase_90 AC 403 ms
14,464 KB
testcase_91 AC 408 ms
14,456 KB
testcase_92 AC 399 ms
14,468 KB
testcase_93 AC 2 ms
6,816 KB
testcase_94 AC 212 ms
14,596 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)

using namespace std;
using ll = long long;

const int INF = 1.01e9;

struct Kitune {
  int N;
  vector<int> dat;

  Kitune(int n) {
    N = 1;
    while (N < n) N *= 2;
    dat.resize(N * 2, -INF);
  }

  void update(int k, int v) {
    k += N;
    dat[k] = v;
    while (k > 1) {
      k >>= 1;
      dat[k] = max(dat[k * 2], dat[k * 2 + 1]);
    }
  }

  int query(int l, int r) {
    l += N;
    r += N;
    int res = -INF;
    while (l <= r) {
      if ((l & 1) == 1) res = max(res, dat[l++]);
      if ((r & 1) == 0) res = max(res, dat[r--]);
      l >>= 1;
      r >>= 1;
    }
    return res;
  }
};

vector<int> uniq(vector<int> a) {
  sort(a.begin(), a.end());
  a.erase(unique(a.begin(), a.end()), a.end());
  return a;
}

int doko(const vector<int> &a, int x) {
  return lower_bound(a.begin(), a.end(), x) - a.begin();
}

template<class T1, class T2, class T3>
ostream &operator<<(ostream &o, tuple<T1, T2, T3> t) {
  return o << '(' << get<0>(t) << ',' << get<1>(t) << ','<< get<2>(t) << ')';
}

int main() {
  int H, W, Q;
  cin >> H >> W >> Q;
  vector<int> X(Q), Y(Q), Z(Q);
  vector<vector<int>> zisyo{{0, H + 1}, {0, W + 1}};
  rep(i, Q) {
    cin >> X[i] >> Y[i] >> Z[i];
    zisyo[0].push_back(Y[i]);
    zisyo[0].push_back(H + 1 - Y[i]);
    zisyo[1].push_back(X[i]);
    zisyo[1].push_back(W + 1 - X[i]);
  }
  zisyo[0] = uniq(zisyo[0]);
  zisyo[1] = uniq(zisyo[1]);
  zisyo.emplace_back();
  zisyo.emplace_back();
  for (int x : zisyo[0]) zisyo[2].push_back(H + 1 - x);
  for (int x : zisyo[1]) zisyo[3].push_back(W + 1 - x);
  reverse(zisyo[2].begin(), zisyo[2].end());
  reverse(zisyo[3].begin(), zisyo[3].end());
  vector<Kitune> ktn;
  vector<vector<ll>> nagasa;
  rep(i, 4) ktn.emplace_back(zisyo[i % 2].size());
  rep(i, 4) nagasa.emplace_back(zisyo[i % 2].size());
  rep(i, Q) {
    int k, z;
    if (X[i] == 0) { k = 0; z = Y[i]; }
    else if (Y[i] == 0) { k = 1; z = W + 1 - X[i]; }
    else if (X[i] == W + 1) { k = 2; z = H + 1 - Y[i]; } 
    else if (Y[i] == H + 1) { k = 3; z = X[i]; }
    else abort();
    auto hidarite = [&]() -> tuple<int, int, int> {
      int butukaru = 0;
      int butukaranai = zisyo[(k + 1) % 4].size() - 1;
      while (butukaranai - butukaru > 1) {
        int aida = (butukaru + butukaranai) / 2;
        if (ktn[(k + 1) % 4].query(aida, zisyo[(k + 1) % 4].size() - 1) >= z) {
          butukaru = aida;
        } else {
          butukaranai = aida;
        }
      }
      return {zisyo[k % 4].back() - zisyo[(k + 1) % 4][butukaru], 1, butukaru};
    };
    auto migite = [&]() -> tuple<int, int, int> {
      int butukaru = zisyo[(k + 1) % 4].size() - 1;
      int butukaranai = 0;
      while (butukaru - butukaranai > 1) {
        int aida = (butukaru + butukaranai) / 2;
        if (ktn[(k + 3) % 4].query(0, aida) >= zisyo[k].back() - z) {
          butukaru = aida;
        } else {
          butukaranai = aida;
        }
      }
      return {zisyo[(k + 1) % 4][butukaru], 3, butukaru};
    };
    auto mukai = [&]() -> tuple<int, int, int> {
      int s = doko(zisyo[(k + 2) % 4], zisyo[k].back() - z);
      return {zisyo[k].back() - nagasa[(k + 2) % 2][s], 2, s};
    };
    auto hazime_ni_butukaru = min({hidarite(), migite(), mukai()});
    int zi = doko(zisyo[k % 2], z);
    auto kakikae = [&](int k, int z, int v) {
      k %= 4;
      nagasa[k][z] = v;
      ktn[k].update(z, v);
    };
    kakikae(k, zi, nagasa[k][zi] + Z[i]);
    if (nagasa[k][zi] >= get<0>(hazime_ni_butukaru)) {
      kakikae(k, zi, 0);
      kakikae(k + get<1>(hazime_ni_butukaru), get<2>(hazime_ni_butukaru), 0);
    }
  }
  ll ans = 0;
  rep(i, 4) for (int x : nagasa[i]) ans += x;
  cout << ans << endl;
}
0