結果
問題 | No.1014 competitive fighting |
ユーザー | 👑 jupiro |
提出日時 | 2020-03-23 19:50:10 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 150 ms / 2,000 ms |
コード長 | 3,358 bytes |
コンパイル時間 | 1,660 ms |
コンパイル使用メモリ | 132,920 KB |
実行使用メモリ | 46,904 KB |
最終ジャッジ日時 | 2023-09-21 19:25:25 |
合計ジャッジ時間 | 8,358 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,380 KB |
testcase_01 | AC | 1 ms
4,376 KB |
testcase_02 | AC | 2 ms
4,380 KB |
testcase_03 | AC | 2 ms
4,380 KB |
testcase_04 | AC | 2 ms
4,376 KB |
testcase_05 | AC | 141 ms
28,316 KB |
testcase_06 | AC | 142 ms
28,148 KB |
testcase_07 | AC | 142 ms
28,076 KB |
testcase_08 | AC | 143 ms
28,152 KB |
testcase_09 | AC | 143 ms
28,000 KB |
testcase_10 | AC | 150 ms
46,904 KB |
testcase_11 | AC | 84 ms
20,308 KB |
testcase_12 | AC | 144 ms
28,192 KB |
testcase_13 | AC | 64 ms
15,328 KB |
testcase_14 | AC | 61 ms
14,960 KB |
testcase_15 | AC | 71 ms
15,728 KB |
testcase_16 | AC | 4 ms
4,380 KB |
testcase_17 | AC | 26 ms
8,424 KB |
testcase_18 | AC | 119 ms
25,992 KB |
testcase_19 | AC | 139 ms
27,844 KB |
testcase_20 | AC | 49 ms
13,980 KB |
testcase_21 | AC | 108 ms
25,488 KB |
testcase_22 | AC | 81 ms
16,812 KB |
testcase_23 | AC | 32 ms
9,328 KB |
testcase_24 | AC | 33 ms
9,372 KB |
testcase_25 | AC | 9 ms
4,612 KB |
testcase_26 | AC | 107 ms
24,968 KB |
testcase_27 | AC | 26 ms
8,580 KB |
testcase_28 | AC | 28 ms
8,916 KB |
testcase_29 | AC | 3 ms
4,376 KB |
testcase_30 | AC | 137 ms
27,704 KB |
testcase_31 | AC | 113 ms
25,336 KB |
testcase_32 | AC | 3 ms
4,376 KB |
testcase_33 | AC | 6 ms
4,380 KB |
testcase_34 | AC | 68 ms
19,376 KB |
testcase_35 | AC | 83 ms
20,476 KB |
testcase_36 | AC | 63 ms
19,044 KB |
testcase_37 | AC | 4 ms
4,376 KB |
testcase_38 | AC | 51 ms
12,064 KB |
testcase_39 | AC | 26 ms
7,656 KB |
testcase_40 | AC | 50 ms
12,272 KB |
testcase_41 | AC | 38 ms
11,340 KB |
testcase_42 | AC | 81 ms
19,936 KB |
testcase_43 | AC | 6 ms
4,380 KB |
testcase_44 | AC | 75 ms
19,784 KB |
testcase_45 | AC | 43 ms
11,848 KB |
testcase_46 | AC | 9 ms
5,072 KB |
testcase_47 | AC | 25 ms
7,492 KB |
testcase_48 | AC | 66 ms
19,264 KB |
testcase_49 | AC | 5 ms
4,376 KB |
testcase_50 | AC | 79 ms
19,744 KB |
testcase_51 | AC | 44 ms
11,736 KB |
testcase_52 | AC | 4 ms
4,376 KB |
testcase_53 | AC | 142 ms
28,148 KB |
ソースコード
#include <cstdio> #include <iostream> #include <string> #include <sstream> #include <stack> #include <algorithm> #include <cmath> #include <queue> #include <map> #include <set> #include <cstdlib> #include <bitset> #include <tuple> #include <assert.h> #include <deque> #include <bitset> #include <iomanip> #include <limits> #include <chrono> #include <random> #include <array> #include <unordered_map> #include <functional> #include <complex> template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } constexpr long long MAX = 5100000; constexpr long long INF = 1LL << 60; constexpr int inf = 1 << 28; //constexpr long long mod = 1000000007LL; constexpr long long mod = 998244353LL; using namespace std; typedef unsigned long long ull; typedef long long ll; struct SegmentTree { public: int n; vector<ll> node; vector<vector<int>> g; SegmentTree(vector<ll> v) { int sz = v.size(); n = 1; while (sz > n) n *= 2; } void add_edge(int a, int b, int nd, int k = 0, int l = 0, int r = -1) { if (r < 0) r = n; if (r <= a || b <= l) return; if (a <= l && r <= b) { g[nd + n - 1].emplace_back(k); return; } add_edge(a, b, nd, 2 * k + 1, l, (l + r) / 2); add_edge(a, b, nd, 2 * k + 2, (l + r) / 2, r); } }; struct technique { ll a, b, c; int id; technique(ll _a, ll _b, ll _c, int _id) :a(_a), b(_b), c(_c), id(_id) {} bool operator <(technique &t) { if (a == t.a) { if (b == t.b) return c < t.c; else return b < t.b; } else return a < t.a; } }; vector<ll> dp; vector<bool> used; vector<technique> vt; vector<int> score; int n; ll dfs(int cur, SegmentTree& seg) { if (dp[cur] != -1) return dp[cur]; if (used[cur]) return dp[cur] = INF; ll res = 0; used[cur] = true; for (auto next : seg.g[cur]) { ll tmp = dfs(next, seg); if (tmp == INF) res = INF; else chmax(res, tmp); } if (res == INF) return dp[cur] = INF; return dp[cur] = res + score[cur]; } int main() { /* cin.tie(nullptr); ios::sync_with_stdio(false); */ scanf("%d", &n); vector<technique> vt; vt.reserve(n); for (int i = 0; i < n; i++) { ll a, b, c; scanf("%lld %lld %lld", &a, &b, &c); vt.emplace_back(a, b, c, i); } SegmentTree seg(vector<ll>(n,0)); n = seg.n; used = vector<bool>(n * 2, false); seg.g.resize(n * 2); dp = vector<ll>(n * 2, -1); score.resize(n * 2); for (int i = 0; i < n - 1; i++) { seg.g[i].emplace_back(i * 2 + 1); seg.g[i].emplace_back(i * 2 + 2); } sort(vt.begin(), vt.end()); for (int i = 0; i < vt.size(); i++) { score[i + n - 1] = vt[i].b; } for (int i = 0; i < vt.size(); i++) { ll d = vt[i].b - vt[i].c; int left = -1; int right = vt.size(); while (right - left > 1) { int mid = (left + right) >> 1; if (mid == vt.size()) left = mid; else if (d < vt[mid].a) right = mid; else left = mid; } //cout << i << " " << right << endl; if (right == 0) continue; if(right < i) seg.add_edge(0, right, i); else { seg.add_edge(0, i, i); if(i + 1!= right) seg.add_edge(i + 1, right, i); } } vector<ll> ans(vt.size()); for (int i = 0; i < vt.size(); i++) { ans[vt[i].id] = dfs(i + n - 1, seg); } for (int i = 0; i < ans.size(); i++) { if (ans[i] == INF) puts("BAN"); else printf("%lld\n", ans[i]); } return 0; }