結果
問題 | No.1014 competitive fighting |
ユーザー | jupiro |
提出日時 | 2020-03-23 19:50:10 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 145 ms / 2,000 ms |
コード長 | 3,358 bytes |
コンパイル時間 | 1,450 ms |
コンパイル使用メモリ | 133,372 KB |
実行使用メモリ | 46,976 KB |
最終ジャッジ日時 | 2024-07-07 12:59:46 |
合計ジャッジ時間 | 7,120 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 122 ms
28,416 KB |
testcase_06 | AC | 125 ms
28,416 KB |
testcase_07 | AC | 126 ms
28,416 KB |
testcase_08 | AC | 125 ms
28,416 KB |
testcase_09 | AC | 127 ms
28,416 KB |
testcase_10 | AC | 145 ms
46,976 KB |
testcase_11 | AC | 75 ms
20,612 KB |
testcase_12 | AC | 123 ms
28,452 KB |
testcase_13 | AC | 58 ms
15,496 KB |
testcase_14 | AC | 53 ms
15,128 KB |
testcase_15 | AC | 61 ms
16,032 KB |
testcase_16 | AC | 3 ms
5,376 KB |
testcase_17 | AC | 23 ms
8,704 KB |
testcase_18 | AC | 101 ms
26,180 KB |
testcase_19 | AC | 124 ms
28,072 KB |
testcase_20 | AC | 44 ms
13,944 KB |
testcase_21 | AC | 96 ms
25,292 KB |
testcase_22 | AC | 69 ms
16,952 KB |
testcase_23 | AC | 27 ms
9,600 KB |
testcase_24 | AC | 29 ms
9,560 KB |
testcase_25 | AC | 8 ms
5,376 KB |
testcase_26 | AC | 92 ms
25,128 KB |
testcase_27 | AC | 23 ms
8,704 KB |
testcase_28 | AC | 25 ms
8,960 KB |
testcase_29 | AC | 2 ms
5,376 KB |
testcase_30 | AC | 118 ms
27,924 KB |
testcase_31 | AC | 99 ms
25,596 KB |
testcase_32 | AC | 2 ms
5,376 KB |
testcase_33 | AC | 6 ms
5,376 KB |
testcase_34 | AC | 63 ms
19,496 KB |
testcase_35 | AC | 79 ms
20,412 KB |
testcase_36 | AC | 61 ms
19,284 KB |
testcase_37 | AC | 4 ms
5,376 KB |
testcase_38 | AC | 46 ms
12,448 KB |
testcase_39 | AC | 24 ms
7,956 KB |
testcase_40 | AC | 45 ms
12,416 KB |
testcase_41 | AC | 35 ms
11,744 KB |
testcase_42 | AC | 76 ms
20,260 KB |
testcase_43 | AC | 5 ms
5,376 KB |
testcase_44 | AC | 71 ms
19,984 KB |
testcase_45 | AC | 40 ms
12,016 KB |
testcase_46 | AC | 9 ms
5,376 KB |
testcase_47 | AC | 23 ms
7,744 KB |
testcase_48 | AC | 62 ms
19,516 KB |
testcase_49 | AC | 4 ms
5,376 KB |
testcase_50 | AC | 72 ms
20,132 KB |
testcase_51 | AC | 42 ms
12,060 KB |
testcase_52 | AC | 4 ms
5,376 KB |
testcase_53 | AC | 124 ms
28,292 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; }