1. template<class Info, class Merge = plus<Info>>
    2. struct SegTree{
    3. int n;
    4. Merge merge;
    5. vector<Info> info;
    6. SegTree(int n): n(n), merge(Merge()), info(4 * n) {}
    7. SegTree(int n, vector<Info> &init): SegTree(n) {
    8. function<void(int,int,int)> build = [&](int p, int l, int r) {
    9. if(l == r) {
    10. info[p] = init[l];
    11. return;
    12. }
    13. int m = (l + r) / 2;
    14. build(2 * p, l, m);
    15. build(2 * p + 1, m + 1, r);
    16. pull(p);
    17. };
    18. build(1, 0, n - 1);
    19. }
    20. void pull(int p) {
    21. info[p] = move(merge(info[2 * p], info[2 * p + 1]));
    22. }
    23. void modify(int p, int l, int r, int x, const Info &v) {
    24. if(l == r) {
    25. info[p] = v;
    26. return;
    27. }
    28. int m = (l + r) / 2;
    29. if(x <= m) modify(p * 2, l, m, x, v);
    30. else modify(2 * p + 1, m + 1, r, x, v);
    31. pull(p);
    32. }
    33. void modify(int p, const Info &v) {
    34. modify(1, 0, n - 1, p, v);
    35. }
    36. Info rangeQuery(int p, int l, int r, int x, int y) {
    37. if(l > y || r < x) {
    38. return Info();
    39. }
    40. if(l >= x && r <= y) return info[p];
    41. int m = (l + r) / 2;
    42. return merge(rangeQuery(p * 2, l, m, x, y), rangeQuery(p * 2 + 1, m + 1, r, x, y));
    43. }
    44. Info rangeQuery(int l, int r) {
    45. return rangeQuery(1, 0, n - 1, l, r);
    46. }
    47. };
    48. struct Info {
    49. int L, R;
    50. Info() { L = 0, R = 0; }
    51. Info(int L, int R): L(L), R(R){}
    52. };
    53. struct Merge {
    54. Info operator () (const Info &l, const Info &r) const {
    55. Info t;
    56. t.L = l.L + r.L - min(l.L, r.R);
    57. t.R = l.R + r.R - min(l.L, r.R);
    58. return t;
    59. }
    60. };
    1. template<class Info, class LazyTag,
    2. class Merge, class Mapping, class Composition>
    3. struct LazySegTree{
    4. int n;
    5. Merge merge;
    6. Mapping mapping;
    7. Composition composition;
    8. vector<Info> info;
    9. vector<LazyTag> lazyTag;
    10. LazySegTree(int n): n(n), merge(Merge()), mapping(Mapping()),
    11. composition(Composition()), info(4 * n), lazyTag(4 * n) {}
    12. LazySegTree(int n, vector<Info> &init): LazySegTree(n) {
    13. function<void(int,int,int)> build = [&](int p, int l, int r) {
    14. if(l == r) {
    15. info[p] = init[l];
    16. return;
    17. }
    18. int m = (l + r) / 2;
    19. build(2 * p, l, m);
    20. build(2 * p + 1, m + 1, r);
    21. pull(p);
    22. };
    23. build(1, 0, n - 1);
    24. }
    25. void pull(int p) {
    26. info[p] = move(merge(info[2 * p], info[2 * p + 1]));
    27. }
    28. void push(int p, const LazyTag& tag) {
    29. mapping(tag, info[p]);
    30. composition(tag, lazyTag[p]);
    31. }
    32. void pushdown(int p) {
    33. push(2 * p, lazyTag[p]);
    34. push(2 * p + 1, lazyTag[p]);
    35. lazyTag[p] = LazyTag();
    36. }
    37. // 这里是 LazyTag
    38. void modify(int p, int l, int r, int L, int R, const LazyTag &v) {
    39. if(l >= L && r <= R) {
    40. push(p, v);
    41. return;
    42. }
    43. pushdown(p);
    44. int m = (l + r) / 2;
    45. if(L <= m) modify(p * 2, l, m, L, R, v);
    46. if(R > m) modify(2 * p + 1, m + 1, r, L, R, v);
    47. pull(p);
    48. }
    49. void modify(int l, int r, const LazyTag &v) {
    50. modify(1, 0, n - 1, l, r, v);
    51. }
    52. Info rangeQuery(int p, int l, int r, int x, int y) {
    53. if(l > y || r < x) {
    54. return Info();
    55. }
    56. if(l >= x && r <= y) return info[p];
    57. int m = (l + r) / 2;
    58. pushdown(p);
    59. return merge(rangeQuery(p * 2, l, m, x, y), rangeQuery(p * 2 + 1, m + 1, r, x, y));
    60. }
    61. Info rangeQuery(int l, int r) {
    62. return rangeQuery(1, 0, n - 1, l, r);
    63. }
    64. };
    65. struct Info {
    66. ll sum;
    67. Info(ll sum = 0):sum(sum) {}
    68. };
    69. struct LazyTag {
    70. ll val;
    71. LazyTag(ll val = -1):val(val){}
    72. };
    73. struct Merge {
    74. Info operator () (const Info &l, const Info &r) const {
    75. Info t;
    76. t.sum = (l.sum + r.sum);
    77. return t;
    78. }
    79. };
    80. struct Mapping {
    81. void operator () (const LazyTag& tag, Info& info) const {
    82. if(tag.val != -1) {
    83. info.sum = tag.val;
    84. }
    85. }
    86. };
    87. struct Composition {
    88. void operator ()(const LazyTag& x, LazyTag& y) const {
    89. if(x.val != -1) {
    90. y.val = x.val;
    91. }
    92. }
    93. };
    94. void solve() {
    95. int n, m;
    96. cin >> n >> m;
    97. vector<Info> init(n);
    98. LazySegTree<Info, LazyTag, Merge, Mapping, Composition> seg(n, init);
    99. while(m --){
    100. int op;
    101. cin >> op;
    102. if(op == 1) {
    103. int l, r, v;
    104. cin >> l >> r >> v;
    105. seg.modify(l, r - 1, LazyTag(v));
    106. } else {
    107. int l, r;
    108. cin >> l;
    109. cout << seg.rangeQuery(l, l).sum << endl;
    110. }
    111. }
    112. }