static void Main() { var h = Read(); int n = h[0], q = h[1]; var rs = new int[n].Select(_ => Read()).ToArray(); var ps = new int[q].Select(_ => Read()).ToArray(); var dy = rs.SelectMany(v => new[] { v[1], v[1] + v[2] }) .Concat(ps.Select(v => v[1])) .Distinct() .OrderBy(y => y) .Select((y, i) => (y, i)) .ToDictionary(v => v.y, v => v.i); var c = new long[q]; var st = new ST_RangeAdd(dy.Count); var qs = rs .Select(v => (x: v[0], X: v[0] + v[2], y: dy[v[1]], Y: dy[v[1] + v[2]], c: v[3])) .SelectMany(v => new[] { (q: -1, v.x, v.y, v.Y, v.c), (q: 1, x: v.X, v.y, v.Y, c: -v.c) })
static void Main() { var r = new List <long>(); var h = Read(); var n = h[0]; var st = new ST_RangeAdd(n + 1); for (int i = 0; i < h[1]; i++) { var q = Read(); if (q[0] == 0) { st.Add(q[1], q[2] + 1, q[3]); } else { r.Add(st[q[1]]); } } Console.WriteLine(string.Join("\n", r)); }