結果
問題 | No.1000 Point Add and Array Add |
ユーザー | noshi91 |
提出日時 | 2020-02-28 21:40:38 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 228 ms / 2,000 ms |
コード長 | 4,895 bytes |
コンパイル時間 | 812 ms |
コンパイル使用メモリ | 81,500 KB |
実行使用メモリ | 12,652 KB |
最終ジャッジ日時 | 2024-10-13 17:05:06 |
合計ジャッジ時間 | 4,329 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,820 KB |
testcase_02 | AC | 1 ms
6,816 KB |
testcase_03 | AC | 2 ms
6,816 KB |
testcase_04 | AC | 1 ms
6,816 KB |
testcase_05 | AC | 2 ms
6,820 KB |
testcase_06 | AC | 1 ms
6,816 KB |
testcase_07 | AC | 2 ms
6,820 KB |
testcase_08 | AC | 2 ms
6,820 KB |
testcase_09 | AC | 1 ms
6,820 KB |
testcase_10 | AC | 2 ms
6,816 KB |
testcase_11 | AC | 2 ms
6,816 KB |
testcase_12 | AC | 3 ms
6,816 KB |
testcase_13 | AC | 3 ms
6,820 KB |
testcase_14 | AC | 4 ms
6,820 KB |
testcase_15 | AC | 4 ms
6,820 KB |
testcase_16 | AC | 157 ms
10,240 KB |
testcase_17 | AC | 134 ms
9,068 KB |
testcase_18 | AC | 216 ms
12,588 KB |
testcase_19 | AC | 218 ms
12,532 KB |
testcase_20 | AC | 210 ms
12,652 KB |
testcase_21 | AC | 225 ms
12,556 KB |
testcase_22 | AC | 214 ms
12,644 KB |
testcase_23 | AC | 228 ms
12,584 KB |
ソースコード
// 1 "temp0.cpp" //#define NDEBUG #include <algorithm> #include <cstddef> #include <cstdint> #include <iostream> #include <utility> #include <vector> namespace n91 { using i8 = std::int_fast8_t; using i32 = std::int_fast32_t; using i64 = std::int_fast64_t; using u8 = std::uint_fast8_t; using u32 = std::uint_fast32_t; using u64 = std::uint_fast64_t; using isize = std::ptrdiff_t; using usize = std::size_t; struct rep { struct itr { usize i; constexpr itr(const usize i) noexcept : i(i) {} void operator++() noexcept { ++i; } constexpr usize operator*() const noexcept { return i; } constexpr bool operator!=(const itr x) const noexcept { return i != x.i; } }; const itr f, l; constexpr rep(const usize f, const usize l) noexcept : f(std::min(f, l)), l(l) {} constexpr auto begin() const noexcept { return f; } constexpr auto end() const noexcept { return l; } }; struct revrep { struct itr { usize i; constexpr itr(const usize i) noexcept : i(i) {} void operator++() noexcept { --i; } constexpr usize operator*() const noexcept { return i; } constexpr bool operator!=(const itr x) const noexcept { return i != x.i; } }; const itr f, l; constexpr revrep(const usize f, const usize l) noexcept : f(l - 1), l(std::min(f, l) - 1) {} constexpr auto begin() const noexcept { return f; } constexpr auto end() const noexcept { return l; } }; template <class T> auto md_vec(const usize n, const T& value) { return std::vector<T>(n, value); } template <class... Args> auto md_vec(const usize n, Args... args) { return std::vector<decltype(md_vec(args...))>(n, md_vec(args...)); } template <class T> constexpr T difference(const T& a, const T& b) noexcept { return a < b ? b - a : a - b; } template <class T> void chmin(T& a, const T& b) noexcept { if (b < a) a = b; } template <class T> void chmax(T& a, const T& b) noexcept { if (a < b) a = b; } template <class F> class rec_lambda { F f; public: rec_lambda(F&& f) : f(std::move(f)) {} template <class... Args> auto operator()(Args&&... args) const { return f(*this, std::forward<Args>(args)...); } }; template <class F> auto make_rec(F&& f) { return rec_lambda<F>(std::move(f)); } template <class T> T scan() { T ret; std::cin >> ret; return ret; } } // namespace n91 // 1 "/mnt/c/Users/noshi/Desktop/base_/Library/data_structure/fenwick_tree.cpp" #include <cassert> #include <cstddef> #include <vector> template <class M> class fenwick_tree { using size_t = std::size_t; public: using T = typename M::value_type; private: std::vector<T> tree; public: fenwick_tree() = default; explicit fenwick_tree(const size_t size) : tree(size + 1, M::identity) {} bool empty() const { return size() == 0; } size_t size() const { return tree.size() - 1; } T fold_prefix(size_t last) const { assert(last <= size()); T ret = M::identity; while (last != 0) { ret = M::operation(tree[last], ret); last &= last - 1; } return ret; } void add(size_t index, const T value) { assert(index < size()); index += 1; while (index < tree.size()) { tree[index] = M::operation(tree[index], value); index += index & ~index + 1; } } }; /** * @brief Fenwick Tree * @see https://scrapbox.io/data-structures/Fenwick_Tree */ // 1 "/mnt/c/Users/noshi/Desktop/base_/Library/other/plus_group.cpp" template <class T> class plus_group { public: using value_type = T; static constexpr T operation(const T& l, const T& r) noexcept { return l + r; } static constexpr T identity = 0; static constexpr T inverse(const T& x) noexcept { return -x; } }; // 84 "temp0.cpp" namespace n91 { void main_() { /* std::ios::sync_with_stdio(false); std::cin.tie(nullptr); //*/ const usize n = scan<usize>(); const usize q = scan<usize>(); struct q_type { char c; usize x; usize y; }; fenwick_tree<plus_group<u64>> ft(n + 1); std::vector<u64> a(n); for (auto& e : a) std::cin >> e; std::vector<q_type> qs(q); for (auto& e : qs) { std::cin >> e.c >> e.x >> e.y; } std::reverse(qs.begin(), qs.end()); std::vector<u64> ans(n, 0); for (auto& e : qs) { switch (e.c) { case 'A': { e.x -= 1; ans[e.x] += e.y * ft.fold_prefix(e.x + 1); } break; case 'B': { e.x -= 1; ft.add(e.x, 1); ft.add(e.y, -static_cast<u64>(1)); } break; } } for (const usize i : rep(0, n)) { ans[i] += a[i] * ft.fold_prefix(i + 1); } for (const usize i : rep(0, n)) { std::cout << ans[i] << " \n"[i + 1 == n]; } } } // namespace n91 int main() { n91::main_(); return 0; }