static void Main() { Console.SetOut(new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); var h = Read(); int n = h[0], qc = h[1]; var a = Array.ConvertAll(Read(), x => new[] { x }); var qs = Array.ConvertAll(new bool[qc], _ => Read()); var st = new ST1 <int[]>(n, (a1, a2) => { var r = new int[a1.Length + a2.Length]; Array.Copy(a1, r, a1.Length); Array.Copy(a2, 0, r, a1.Length, a2.Length); Array.Sort(r); return(r); }, new int[0], a); foreach (var q in qs) { var r = Last(-1, 1 << 30, x => q[2] >= st.Aggregate(q[0], q[1], 0, (p, n, l) => p + First(0, st[n].Length, i => st[n][i] >= x))); Console.WriteLine(r); } Console.Out.Flush(); }
public int GetLca(int u, int v) { if (u == v) { return(u); } if (ordersMap[u][0] > ordersMap[v][0]) { var t = u; u = v; v = t; } if (ordersMap[u].Last() > ordersMap[v][0]) { return(u); } var minDepth = depthST.Get(ordersMap[u].Last(), ordersMap[v][0]); var lcaOrder = depthST.Aggregate(ordersMap[u].Last(), ordersMap[v][0], -1, (p, n, l) => { if (p != -1 || depthST[n] != minDepth) { return(p); } while (l > 1) { n = depthST[n.Child0] == minDepth ? n.Child0 : n.Child1; l >>= 1; } return(depthST.Original(n)); }); return(tour[lcaOrder]); }
static void Main() { Console.SetOut(new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }); var h = Read(); var n = h[0]; var a = Read(); var st = new ST1 <int>(n, Math.Max, 0, a); for (int k = 0; k < h[1]; k++) { var q = Read(); if (q[0] == 1) { st.Set(q[1] - 1, q[2]); } else if (q[0] == 2) { Console.WriteLine(st.Get(q[1] - 1, q[2])); } else { Console.WriteLine(1 + st.Aggregate(q[1] - 1, n, n, (p, node, l) => { if (p < n || st[node] < q[2]) { return(p); } while (node.i < st.n2 >> 1) { node = q[2] <= st[node.Child0] ? node.Child0 : node.Child1; } return(st.Original(node)); })); } } Console.Out.Flush(); }