1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
| #include <iostream> #define maxn 1000010 #define ll long long using namespace std;
int n, m; ll add[maxn];
#define lc i << 1 #define rc i << 1 | 1 struct Seg { int col; ll v; } T[maxn * 4]; inline void maintain(int i) { T[i].col = T[lc].col == T[rc].col ? T[lc].col : 0; }
void build(int i, int l, int r) { if (l == r) return T[i] = { 1, 0 }, void(); int m = l + r >> 1; build(lc, l, m); build(rc, m + 1, r); maintain(i); }
inline void Update(int i, ll v, int col) { T[i].v += v; if (col) T[i].col = col; }
inline void pushdown(int i) { ll &v = T[i].v; int &col = T[i].col; Update(lc, v, col); Update(rc, v, col); v = col = 0; }
void update(int i, int l, int r, int L, int R, int col) { if (l > R || r < L) return ; if (L <= l && r <= R && T[i].col) return Update(i, add[T[i].col] - add[col], col); int m = l + r >> 1; pushdown(i); update(lc, l, m, L, R, col); update(rc, m + 1, r, L, R, col); maintain(i); }
ll query(int i, int l, int r, int k) { if (l == r) return T[i].v + add[T[i].col]; int m = l + r >> 1; pushdown(i); if (k <= m) return query(lc, l, m, k); else return query(rc, m + 1, r, k); }
inline void solve_1() { int x, y, z; cin >> x >> y >> z; update(1, 1, n, x, y, z); }
inline void solve_2() { int x, y; cin >> x >> y; add[x] += y; }
inline void solve_3() { int x; cin >> x; cout << query(1, 1, n, x) << "\n"; }
int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
cin >> n >> m; build(1, 1, n); for (int i = 1; i <= m; ++i) { char s[20]; cin >> s + 1; switch (s[1]) { case 'C': solve_1(); break; case 'A': solve_2(); break; case 'Q': solve_3(); break; } } return 0; }
|