結果
| 問題 |
No.1000 Point Add and Array Add
|
| コンテスト | |
| ユーザー |
noshi91
|
| 提出日時 | 2020-02-28 21:40:38 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 306 ms / 2,000 ms |
| コード長 | 4,895 bytes |
| コンパイル時間 | 1,073 ms |
| コンパイル使用メモリ | 79,220 KB |
| 最終ジャッジ日時 | 2025-01-09 02:39:13 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 22 |
ソースコード
// 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;
}
noshi91