結果
問題 | No.855 ヘビの日光浴 |
ユーザー | pekempey |
提出日時 | 2019-07-26 23:35:16 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 5,895 bytes |
コンパイル時間 | 2,213 ms |
コンパイル使用メモリ | 191,572 KB |
実行使用メモリ | 9,076 KB |
最終ジャッジ日時 | 2024-10-01 20:52:47 |
合計ジャッジ時間 | 9,382 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | WA | - |
testcase_04 | AC | 2 ms
5,248 KB |
testcase_05 | AC | 2 ms
5,248 KB |
testcase_06 | AC | 2 ms
5,248 KB |
testcase_07 | WA | - |
testcase_08 | AC | 2 ms
5,248 KB |
testcase_09 | AC | 2 ms
5,248 KB |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | AC | 2 ms
5,248 KB |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | AC | 2 ms
5,248 KB |
testcase_17 | AC | 2 ms
5,248 KB |
testcase_18 | WA | - |
testcase_19 | AC | 2 ms
5,248 KB |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | AC | 2 ms
5,248 KB |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | AC | 2 ms
5,248 KB |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | AC | 2 ms
5,248 KB |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | AC | 2 ms
5,248 KB |
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 | WA | - |
testcase_56 | WA | - |
testcase_57 | AC | 2 ms
5,248 KB |
testcase_58 | AC | 2 ms
5,248 KB |
testcase_59 | WA | - |
testcase_60 | WA | - |
testcase_61 | WA | - |
testcase_62 | WA | - |
testcase_63 | AC | 2 ms
5,248 KB |
testcase_64 | AC | 2 ms
5,248 KB |
testcase_65 | WA | - |
testcase_66 | WA | - |
testcase_67 | AC | 2 ms
5,248 KB |
testcase_68 | AC | 2 ms
5,248 KB |
testcase_69 | WA | - |
testcase_70 | AC | 2 ms
5,248 KB |
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 | WA | - |
testcase_84 | WA | - |
testcase_85 | WA | - |
testcase_86 | WA | - |
testcase_87 | WA | - |
testcase_88 | WA | - |
testcase_89 | WA | - |
testcase_90 | WA | - |
testcase_91 | WA | - |
testcase_92 | WA | - |
testcase_93 | AC | 2 ms
5,248 KB |
testcase_94 | AC | 151 ms
8,816 KB |
ソースコード
#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.1e9; struct MAX { int N; vector<int> dat; MAX(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(); } int main() { int H, W, Q; cin >> H >> W >> Q; vector<int> X(Q), Y(Q), Z(Q); vector<int> DX{0, W + 1}, DY{0, H + 1}; rep(i, Q) { cin >> X[i] >> Y[i] >> Z[i]; DX.push_back(X[i]); DY.push_back(Y[i]); } DX = uniq(DX); DY = uniq(DY); MAX U(DX.size()); MAX D(DX.size()); MAX L(DY.size()); MAX R(DY.size()); vector<ll> nagasaU(DX.size(), 0); vector<ll> nagasaD(DX.size(), 0); vector<ll> nagasaL(DY.size(), 0); vector<ll> nagasaR(DY.size(), 0); // ha? rep(i, Q) { int x = doko(DX, X[i]); int y = doko(DY, Y[i]); tuple<int, int, int> ans(INF, INF, INF); if (X[i] == 0) { // hidari auto sawaruU = [&]() -> tuple<int, int, int> { int l = -1; int r = DX.size() - 1; while (r - l > 1) { int m = (l + r) / 2; (U.query(1, m) >= Y[i] ? r : l) = m; } return {DX[r], DX[r], 0}; }; auto sawaruD = [&]() -> tuple<int, int, int> { int l = -1; int r = DX.size() - 1; while (r - l > 1) { int m = (l + r) / 2; (H + 1 - D.query(1, m) <= Y[i] ? r : l) = m; } return {DX[r], DX[r], H + 1}; }; auto sawaruR = [&]() -> tuple<int, int, int> { return {W + 1 - nagasaR[y], W + 1, Y[i]}; }; ans = min({sawaruU(), sawaruD(), sawaruR()}); } else if (X[i] == W + 1) { // migi auto sawaruU = [&]() -> tuple<int, int, int> { int l = 0; int r = DX.size(); while (r - l > 1) { int m = (l + r) / 2; (U.query(m, DX.size() - 1) >= Y[i] ? l : r) = m; } return {W + 1 - DX[l], DX[l], 0}; }; auto sawaruD = [&]() -> tuple<int, int, int> { int l = 0; int r = DX.size(); while (r - l > 1) { int m = (l + r) / 2; (H + 1 - D.query(m, DX.size() - 1) <= Y[i] ? l : r) = m; } return {W + 1 - DX[l], DX[l], H + 1}; }; auto sawaruL = [&]() -> tuple<int, int, int> { return {W + 1 - nagasaL[y], 0, Y[i]}; }; ans = min({sawaruU(), sawaruD(), sawaruL()}); } else if (Y[i] == 0) { // ue auto sawaruL = [&]() -> tuple<int, int, int> { int l = -1; int r = DY.size() - 1; while (r - l > 1) { int m = (l + r) / 2; (L.query(1, m) >= X[i] ? r : l) = m; } return {DY[r], 0, DY[r]}; }; auto sawaruR = [&]() -> tuple<int, int, int> { int l = -1; int r = DY.size() - 1; while (r - l > 1) { int m = (l + r) / 2; (H + 1 - R.query(1, m) <= Y[i] ? r : l) = m; } return {DY[r], W + 1, DY[r]}; }; auto sawaruD = [&]() -> tuple<int, int, int> { return {H + 1 - nagasaD[x], X[i], H + 1}; }; ans = min({sawaruL(), sawaruR(), sawaruD()}); } else if (Y[i] == H + 1) { // sita auto sawaruL = [&]() -> tuple<int, int, int> { int l = 0; int r = DY.size(); while (r - l > 1) { int m = (l + r) / 2; (L.query(m, DY.size() - 1) >= X[i] ? l : r) = m; } return {H + 1 - DY[l], 0, DY[l]}; }; auto sawaruR = [&]() -> tuple<int, int, int> { int l = 0; int r = DY.size(); while (r - l > 1) { int m = (l + r) / 2; (W + 1 - R.query(m, DY.size() - 1) <= X[i] ? l : r) = m; } return {H + 1 - DY[l], W + 1, DY[l]}; }; auto sawaruU = [&]() -> tuple<int, int, int> { return {H + 1 - nagasaU[x], X[i], 0}; }; ans = min({sawaruL(), sawaruR(), sawaruU()}); } else abort(); auto modosu = [&](int x, int y) { int ix = doko(DX, x); int iy = doko(DY, y); if (y == 0) { nagasaU[ix] = 0; U.update(ix, 0); } else if (y == H + 1) { nagasaD[ix] = 0; D.update(ix, 0); } else if (x == 0) { nagasaL[iy] = 0; L.update(iy, 0); } else if (x == W + 1) { nagasaR[iy] = 0; R.update(iy, 0); } else abort(); }; auto nobasu = [&]() { if (Y[i] == 0) { nagasaU[x] += Z[i]; if (nagasaU[x] >= get<0>(ans)) return false; U.update(x, nagasaU[x]); } else if (Y[i] == H + 1) { nagasaD[x] += Z[i]; if (nagasaD[x] >= get<0>(ans)) return false; D.update(x, nagasaD[x]); } else if (X[i] == 0) { nagasaL[y] += Z[i]; if (nagasaL[y] >= get<0>(ans)) return false; L.update(y, nagasaL[y]); } else if (X[i] == W + 1) { nagasaR[y] += Z[i]; if (nagasaR[y] >= get<0>(ans)) return false; R.update(y, nagasaR[y]); } return true; }; if (!nobasu()) { modosu(get<1>(ans), get<2>(ans)); modosu(X[i], Y[i]); } } ll ans = 0; rep(i, DY.size()) ans += nagasaL[i] + nagasaR[i]; rep(i, DX.size()) ans += nagasaU[i] + nagasaD[i]; cout << ans << endl; }