結果
問題 | No.1014 competitive fighting |
ユーザー | polylogK |
提出日時 | 2020-03-20 22:30:31 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,588 bytes |
コンパイル時間 | 2,182 ms |
コンパイル使用メモリ | 190,308 KB |
実行使用メモリ | 17,892 KB |
最終ジャッジ日時 | 2024-05-08 22:46:41 |
合計ジャッジ時間 | 9,661 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,376 KB |
testcase_02 | WA | - |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 94 ms
16,356 KB |
testcase_06 | WA | - |
testcase_07 | AC | 98 ms
16,356 KB |
testcase_08 | AC | 92 ms
16,356 KB |
testcase_09 | AC | 92 ms
16,356 KB |
testcase_10 | AC | 68 ms
17,892 KB |
testcase_11 | AC | 61 ms
14,824 KB |
testcase_12 | AC | 96 ms
16,480 KB |
testcase_13 | AC | 43 ms
9,600 KB |
testcase_14 | AC | 41 ms
9,168 KB |
testcase_15 | AC | 48 ms
10,028 KB |
testcase_16 | AC | 4 ms
5,376 KB |
testcase_17 | AC | 17 ms
6,016 KB |
testcase_18 | AC | 77 ms
14,352 KB |
testcase_19 | AC | 92 ms
16,060 KB |
testcase_20 | AC | 32 ms
8,296 KB |
testcase_21 | AC | 70 ms
13,496 KB |
testcase_22 | AC | 58 ms
11,036 KB |
testcase_23 | AC | 22 ms
6,656 KB |
testcase_24 | WA | - |
testcase_25 | AC | 6 ms
5,376 KB |
testcase_26 | AC | 69 ms
13,344 KB |
testcase_27 | AC | 17 ms
5,888 KB |
testcase_28 | AC | 19 ms
6,144 KB |
testcase_29 | AC | 2 ms
5,376 KB |
testcase_30 | AC | 90 ms
15,936 KB |
testcase_31 | AC | 71 ms
13,900 KB |
testcase_32 | AC | 2 ms
5,376 KB |
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 | AC | 94 ms
16,360 KB |
ソースコード
#include <bits/stdc++.h> using namespace std::literals::string_literals; using i64 = std::int_fast64_t; using std::cout; using std::cerr; using std::endl; using std::cin; template<typename T> std::vector<T> make_v(size_t a){return std::vector<T>(a);} template<typename T,typename... Ts> auto make_v(size_t a,Ts... ts){ return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); } #ifndef INCLUDED_SEGMENT_TREE_HPP #define INCLUDED_SEGMENT_TREE_HPP #include <cstdint> #include <vector> #include <functional> template<class Monoid> class segment_tree { public: using T = typename Monoid::value_type; using size_type = std::uint_fast32_t; using updator = std::function<T(T)>; using checker = std::function<bool(T)>; private: const size_type size_; size_type height_; public: std::vector<T> data; private: const size_type get_height(size_type size) const { size_type height = 1; while(1 << height <= size) height++; return height; } const size_type base_size() const { return 1 << height_; } void meld(size_type index) { data[index] = Monoid::operation(data[index << 1 ^ 0], data[index << 1 ^ 1]); } public: segment_tree() = default; segment_tree(segment_tree&&) = default; segment_tree(const segment_tree&) = default; segment_tree(size_type size) : size_(size) { height_ = get_height(size); data.assign(base_size() << 1, T{}); } T fold(size_type left, size_type right) { T l_value = T{}; T r_value = T{}; for(left += base_size(), right += base_size(); left < right; left >>= 1, right >>= 1) { if(left & 1) l_value = Monoid::operation(l_value, data[left++]); if(right & 1) r_value = Monoid::operation(data[--right], r_value); } return Monoid::operation(std::move(l_value), std::move(r_value)); } void update(size_type index, const updator& update) { index += base_size(); data[index] = update(data[index]); while(index >>= 1) meld(index); } void update(size_type index, const T& value) { update(index, [&value](const T& x) { return Monoid::operation(x, value); }); } void change(size_type index, const T& value) { update(index, [&value](const T& x) { return value; }); } const size_type search(size_type left, const checker& check) { T val = T{}; size_type k = left + base_size(); while(true) { if(check(Monoid::operation(val, data[k]))) { val = Monoid::operation(val, data[k]); if(k & 1) { if((k + 1) & k) k = (k + 1) >> 1; else return size(); } else { k = k + 1; } } else { if(k < base_size()) { k = k << 1 ^ 0; } else { return k - base_size(); } } } } const T operator[](size_type index) const { return data[index + base_size()]; } const size_type size() const { return size_; } const bool empty() const { return data.empty(); } }; template<class T> struct monoid { using value_type = T; static value_type operation(const value_type& a, const value_type& b) { return a + b; }; }; // @docs docs/segment_tree.md #endif struct node { int x, id; node(int x = -(1 << 30), int id = -1): x(x), id(id) {}; node operator+(const node& r) const { if(x < r.x) return r; return (*this); } }; int main() { int n; scanf("%d", &n); std::vector<int> a(n), b(n), c(n); for(int i = 0; i < n; i++) { int x; scanf("%d%d%d", &a[i], &c[i], &x); b[i] = c[i] - x; } std::vector<std::pair<int, int>> vec; for(int i = 0; i < n; i++) vec.push_back({a[i], i}); sort(begin(vec), end(vec)); sort(begin(a), end(a)); segment_tree<monoid<node>> seg(n); for(int i = 0; i < n; i++) seg.change(i, node(b[vec[i].second], i)); std::vector<int> x(n), y(n), h(n); std::vector<std::vector<int>> g(n), G(n); for(int i = 0; i < n; i++) { int k = upper_bound(begin(a), end(a), b[vec[i].second]) - begin(a); if(i < k) { auto p = seg.fold(0, i) + seg.fold(i + 1, k); x[i] = i; y[i] = p.id; } else { auto p = seg.fold(0, k); x[i] = i; y[i] = p.id; } if(y[i] == -1) continue; g[x[i]].push_back(i); G[y[i]].push_back(i); h[i]++; } std::vector<i64> dp(n, -1); std::queue<int> qu; for(int i = 0; i < n; i++) { if(y[i] != -1) continue; qu.push(i); dp[i] = c[vec[i].second]; } while(!qu.empty()) { auto v = qu.front(); qu.pop(); for(auto id: G[v]) { int to = x[id] ^ y[id] ^ v; if(--h[to]) continue; dp[to] = std::max(dp[to], dp[v] + (i64)c[vec[to].second]); qu.push(to); } } std::vector<int> ans(n); for(int i = 0; i < n; i++) ans[vec[i].second] = dp[i]; for(auto v: ans) { if(v == -1) printf("BAN\n"); else printf("%lld\n", v); } return 0; }