#define _USE_MATH_DEFINES #include using namespace std; template class LazySegmentTree { private: //using FunctionMonoid = function; //using FunctionAction = function; //using FunctionLazy = function; FunctionMonoid fm; FunctionAction fa; FunctionLazy fl; int n, height; vector data; vector lazy; Monoid M_UNITY; LazyMonoid L_UNITY; void build (const int siz) { n = 1; height = 0; while (n < siz) n <<= 1, ++height; data.assign(2 * n, M_UNITY); lazy.assign(2 * n, L_UNITY); } public: LazySegmentTree (const FunctionMonoid& f, const FunctionAction& g, const FunctionLazy& h, const Monoid& m_unity, const LazyMonoid& l_unity, int siz = 1) : fm(f), fa(g), fl(h), M_UNITY(m_unity), L_UNITY(l_unity) { build(siz); } inline Monoid reflect (int k) { return lazy[k] == L_UNITY ? data[k] : fa(data[k], lazy[k]); } inline void propagate (int k) { if (lazy[k] == L_UNITY) return; lazy[(k << 1) | 0] = fl(lazy[(k << 1) | 0], lazy[k]); lazy[(k << 1) | 1] = fl(lazy[(k << 1) | 1], lazy[k]); data[k] = reflect(k); lazy[k] = L_UNITY; } inline void thrust (int k) { for (int i = height; i > 0; --i) propagate(k >> i); } inline void recalc (int k) { while (k >>= 1) data[k] = fm(reflect((k << 1) | 0), reflect((k << 1) | 1)); } void modify (int left, int right, LazyMonoid val) { thrust(left += n); thrust(right += n - 1); for (int l = left, r = right + 1; l < r; l >>= 1, r >>= 1) { if (l & 1) lazy[l] = fl(lazy[l], val), l++; if (r & 1) --r, lazy[r] = fl(lazy[r], val); } recalc(left); recalc(right); } void modify (int idx, LazyMonoid val) { thrust(idx += n); data[idx] = val; lazy[idx] = L_UNITY; recalc(idx); } Monoid get (int left, int right) { thrust(left += n); thrust(right += n - 1); Monoid val_l = M_UNITY, val_r = M_UNITY; for (int l = left, r = right + 1; l < r; l >>= 1, r >>= 1) { if (l & 1) val_l = fm(val_l, reflect(l++)); if (r & 1) val_r = fm(reflect(--r), val_r); } return fm(val_l, val_r); } }; signed main() { ios::sync_with_stdio(false); cin.tie(0); //c int n, q; cin >> n >> q; vector a(n); for (int i = 0; i < n; i++) cin >> a[i]; vector> query; for (int i = 0; i < q; i++) { char ch; cin >> ch; int c = (ch == 'A'); int x, y; cin >> x >> y; if (c == 1) x--; else x--, y--; query.push_back({c, x, y}); } reverse(query.begin(), query.end()); auto f = [] (int x, int y) { return x + y; }; LazySegmentTree sgt (f, f, f, 0, 0, n + 10); for (int i = 0; i < n; i++) sgt.modify(i, 0); vector>> add(n); for (int i = 0; i < q; i++) { if (query[i][0] == 0) { int l = query[i][1]; int r = query[i][2]; sgt.modify(l, r + 1, 1); //cerr << l << " " << r << endl; } else { int idx = query[i][1]; int val = query[i][2]; add[idx].emplace_back(val, sgt.get(idx, idx + 1)); } } // for (int i = 0; i < n; i++) { // cerr << sgt.get(i, i + 1) << " "; // } // cerr << endl; vector ans(n); for (int i = 0; i < n; i++) { for (auto& p : add[i]) { ans[i] += 1LL * p.first * p.second; } } for (int i = 0; i < n; i++) { ans[i] += 1LL * a[i] * sgt.get(i, i + 1); } for (int i = 0; i < n; i++) { if (i > 0) cout << " "; cout << ans[i]; } cout << endl; return 0; }