玩原神玩的
#include <bits/stdc++.h>
template <typename P, typename Q> constexpr std::istream& operator>>(std::istream& is, std::pair<P, Q>& v) { std::cin >> v.first >> v.second; return is; }
template <typename P, typename Q> constexpr std::ostream& operator<<(std::ostream& os, std::pair<P, Q>& v) { std::cout << v.first << ' ' << v.second; return os; }
template <typename T, std::size_t N> constexpr std::istream& operator>>(std::istream& is, std::array<T, N>& v) { for (auto& i : v) is >> i; return is; }
template <typename T, std::size_t N> constexpr std::ostream& operator<<(std::ostream& os, std::array<T, N>& v) { for (auto& i : v) os << i << ' '; return os; }
template <typename T> constexpr std::istream& operator>>(std::istream& is, std::vector<T>& v) { for (auto& i : v) is >> i; return is; }
template <typename T> constexpr std::ostream& operator<<(std::ostream& os, std::vector<T>& v) { for (auto& i : v) os << i << ' '; return os; }
template <typename...Args> constexpr void print(Args...args) { ((std::cout << args << ' '), ...); }
template <typename...Args> constexpr void debug(Args...args) { ((std::cerr << args << ' '), ...); std::cerr << '\n'; }
template <typename...Args> constexpr void println(Args...args) { ((std::cout << args << ' '), ...); std::cout << '\n'; }
template <typename P, typename Q> constexpr bool chmax(P& a, Q b) { a = (b > a ? b : a); return a == b; }
template <typename P, typename Q> constexpr bool chmin(P& a, Q b) { a = (b < a ? b : a); return a == b; }
template <typename T> static constexpr T inf = std::numeric_limits<T>::max() / 2;
using i64 = int64_t;
template <class Info, class Tag>
struct LazySegmentTree {
#define m (l + r) / 2
int n;
std::vector<Info> tr;
std::vector<Tag> tag;
LazySegmentTree() : n(0) {}
LazySegmentTree(int n_, Info v_ = Info()) {
init(n_, v_);
}
template<class T>
LazySegmentTree(std::vector<T> init_) {
init(init_);
}
void init(int n_, Info v_ = Info()) {
init(std::vector(n_, v_));
}
template<class T>
void init(std::vector<T> init_) {
n = init_.size();
tr.assign(4 << std::__lg(n), Info());
tag.assign(4 << std::__lg(n), Tag());
std::function<void(int, int, int)> build = [&](int p, int l, int r) {
if (r - l == 1) {
tr[p] = { init_[l] };
return;
}
build(2 * p, l, m);
build(2 * p + 1, m, r);
pull(p);
};
build(1, 0, n);
}
void pull(int p) {
tr[p] = tr[2 * p] + tr[2 * p + 1];
}
void apply(int p, const Tag& t) {
tr[p].apply(t);
tag[p].apply(t);
}
void push(int p) {
apply(2 * p, tag[p]);
apply(2 * p + 1, tag[p]);
tag[p] = Tag();
}
void modify(int p, int l, int r, int x, const Info& v) {
if (r - l == 1) {
tr[p] = v;
return;
}
push(p);
if (x < m) {
modify(2 * p, l, m, x, v);
}
else {
modify(2 * p + 1, m, r, x, v);
}
pull(p);
}
void modify(int x, const Info& v) {
modify(1, 0, n, x, v);
}
Info rangeQuery(int p, int l, int r, int x, int y) {
if (l >= y || r <= x) {
return Info();
}
if (l >= x && r <= y) {
return tr[p];
}
push(p);
return rangeQuery(2 * p, l, m, x, y) + rangeQuery(2 * p + 1, m, r, x, y);
}
Info rangeQuery(int l, int r) {
return rangeQuery(1, 0, n, l, r);
}
void rangeApply(int p, int l, int r, int x, int y, const Tag& t) {
if (l >= y || r <= x) {
return;
}
if (l >= x && r <= y) {
return apply(p, t);
}
push(p);
rangeApply(2 * p, l, m, x, y, t);
rangeApply(2 * p + 1, m, r, x, y, t);
pull(p);
}
void rangeApply(int l, int r, const Tag& t) {
return rangeApply(1, 0, n, l, r, t);
}
int findFirst(int p, int l, int r, int x, int y, auto check) {
if (l >= y || r <= x || !check(tr[p])) {
return -1;
}
if (r - l == 1) {
return l;
}
push(p);
int res = findFirst(2 * p, l, m, x, y, check);
if (res == -1) {
res = findFirst(2 * p + 1, m, r, x, y, check);
}
return res;
}
int findFirst(int x, int y, auto check) {
return findFirst(1, 0, n, x, y, check);
}
int findLast(int p, int l, int r, int x, int y, auto check) {
if (l >= y || r <= x || !check(tr[p])) {
return -1;
}
if (r - l == 1) {
return l;
}
push(p);
int res = findLast(2 * p + 1, m, r, x, y, check);
if (res == -1) {
res = findLast(2 * p, l, m, x, y, check);
}
return res;
}
int findLast(int x, int y, auto check) {
return findLast(1, 0, n, x, y, check);
}
struct Proxy {
LazySegmentTree& seg{};
int i = 0, j = 1;
Info val{};
Proxy(LazySegmentTree& seg, int i, int j) :seg(seg), i(i), j(j), val(seg.rangeQuery(i, j)) {}
constexpr Info* operator->() {
return &val;
}
constexpr Proxy& operator=(const Info& info) {
seg.modify(i, info);
return *this;
}
constexpr Proxy& operator+=(const Tag& tag) {
seg.rangeApply(i, j, tag);
return *this;
}
};
constexpr Proxy operator[](int i) {
return Proxy(*this, i, i + 1);
}
constexpr Proxy operator()(int i) {
return Proxy(*this, i, i + 1);
}
constexpr Proxy operator()(int i, int j) {
return Proxy(*this, i, j);
}
#undef m
};
struct Tag {
i64 x = 0;
void apply(const Tag& t) {
x += t.x;
}
};
struct Info {
i64 x = 0;
int siz = 1;
void apply(const Tag& t) {
x += t.x * siz;
}
};
Info operator+(const Info& a, const Info& b) {
return { a.x + b.x, a.siz + b.siz };
}
int main() {
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
int n, m;
std::cin >> n >> m;
std::vector<Info> a(n);
for (auto& info : a) {
std::cin >> info.x;
}
LazySegmentTree<Info, Tag> seg(a);
while (m--) {
char o;
int l, r, d;
std::cin >> o >> l >> r;
if (o == 'C') {
std::cin >> d;
seg(l - 1, r) += {d};
}
else {
std::cout << seg(l - 1, r)->x << "\n";
}
}
return 0;
}