// 1 "temp0.cpp" //#define NDEBUG #include #include #include #include #include #include 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 auto md_vec(const usize n, const T& value) { return std::vector(n, value); } template auto md_vec(const usize n, Args... args) { return std::vector(n, md_vec(args...)); } template constexpr T difference(const T& a, const T& b) noexcept { return a < b ? b - a : a - b; } template void chmin(T& a, const T& b) noexcept { if (b < a) a = b; } template void chmax(T& a, const T& b) noexcept { if (a < b) a = b; } template class rec_lambda { F f; public: rec_lambda(F&& f) : f(std::move(f)) {} template auto operator()(Args&&... args) const { return f(*this, std::forward(args)...); } }; template auto make_rec(F&& f) { return rec_lambda(std::move(f)); } template 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 #include #include template class fenwick_tree { using size_t = std::size_t; public: using T = typename M::value_type; private: std::vector 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 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(); const usize q = scan(); struct q_type { char c; usize x; usize y; }; fenwick_tree> ft(n + 1); std::vector a(n); for (auto& e : a) std::cin >> e; std::vector qs(q); for (auto& e : qs) { std::cin >> e.c >> e.x >> e.y; } std::reverse(qs.begin(), qs.end()); std::vector 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(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; }