Example #1
0
        public void FromObject2()
        {
            string s1;

            ST1 st1 = new ST1();
            s1 = Microsoft.VisualBasic.CompilerServices.StringType.FromObject(st1);
        }
Example #2
0
        public void FromObject2()
        {
            string s1;

            ST1 st1 = new ST1();

            s1 = Microsoft.VisualBasic.CompilerServices.StringType.FromObject(st1);
        }
Example #3
0
 public Lca(int n, int root, List <int>[] _map)
 {
     map       = _map;
     tour      = new List <int>();
     ordersMap = Array.ConvertAll(new int[n], _ => new List <int>());
     depths    = new List <int>();
     EulerTourDfs(root, 0);
     depthST = new ST1 <int>(2 * n, Math.Min, int.MaxValue, depths.ToArray());
 }
Example #4
0
    static void Main()
    {
        var(n, qc) = Read2();
        var a  = Read();
        var qs = Array.ConvertAll(new bool[qc], _ => Read3());

        // a の値となりうるインデックスのセット
        var map = new Dictionary <int, SortedSet <int> >();

        void AddPair(int i, int v)
        {
            if (!map.ContainsKey(v))
            {
                map[v] = new SortedSet <int>();
            }
            map[v].Add(i);
        }

        for (int i = 0; i < n; i++)
        {
            AddPair(i, a[i]);
        }
        foreach (var(t, x, y) in qs)
        {
            if (t == 1)
            {
                AddPair(x - 1, y);
            }
        }

        var st = new ST1 <int>(n, Math.Min, int.MaxValue, a);

        Console.SetOut(new System.IO.StreamWriter(Console.OpenStandardOutput())
        {
            AutoFlush = false
        });
        foreach (var q in qs)
        {
            var(t, x, y) = q;
            x--;

            if (t == 1)
            {
                a[x] = y;
                st.Set(x, y);
            }
            else
            {
                var p = st.Get(x, y);

                var r = map[p].GetViewBetween(x, y - 1).Where(i => a[i] == p).Select(i => i + 1).ToArray();
                Console.WriteLine($"{r.Length} " + string.Join(" ", r));
            }
        }
        Console.Out.Flush();
    }
Example #5
0
    static void Main()
    {
        var n  = int.Parse(Console.ReadLine());
        var xs = Read();
        var qc = int.Parse(Console.ReadLine());
        var qs = Enumerable.Range(0, qc).Select(Read3).ToArray();

        var mins = Array.ConvertAll(new bool[qc], _ => int.MaxValue);
        var st1  = new ST1 <int>(n, Math.Max, int.MinValue);
        var st2  = new ST1 <int>(n, Math.Min, int.MaxValue);

        var xqs = xs.Select((x, i) => (x, l: int.MinValue, r: 0, i)).Concat(qs).ToArray();
        // x - x_i >= 0
        var q1 = xqs.OrderBy(v => v);
        // x_i - x >= 0
        var q2 = xqs.OrderBy(v => - v.x).ThenBy(v => v.l);

        foreach (var(x, l, r, i) in q1)
        {
            if (r == 0)
            {
                st1.Set(i, x);
            }
            else
            {
                var max = st1.Get(l - 1, r);
                if (max == st1.v0)
                {
                    continue;
                }
                mins[i] = Math.Min(mins[i], x - max);
            }
        }

        foreach (var(x, l, r, i) in q2)
        {
            if (r == 0)
            {
                st2.Set(i, x);
            }
            else
            {
                var min = st2.Get(l - 1, r);
                if (min == st2.v0)
                {
                    continue;
                }
                mins[i] = Math.Min(mins[i], min - x);
            }
        }

        Console.WriteLine(string.Join("\n", mins));
    }
Example #6
0
    static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split().Select(int.Parse).Select((x, i) => new { x, i }).OrderBy(_ => _.x).ToArray();

        var st = new ST1 <long>(n, (x, y) => x + y, 0);
        var r  = 0L;

        for (int i = 0; i < n; i++)
        {
            r += st.Get(a[i].i, n);
            st.Set(a[i].i, 1);
        }
        Console.WriteLine(r);
    }
Example #7
0
    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();
    }
Example #8
0
    static string Solve()
    {
        var n = int.Parse(Console.ReadLine());
        var a = Read();

        var max1 = a.CumMax();
        var max2 = a.Reverse().ToArray().CumMax();

        Array.Reverse(max2);

        var st = new ST1 <int>(n, Math.Min, int.MaxValue, a);

        for (int x = 1; x <= n - 2; x++)
        {
            var m  = max1[x];
            var zi = First(x + 1, n, j => max2[j] <= m);
            if (max2[zi] != m)
            {
                continue;
            }

            var min = st.Get(x, zi);
            if (min == m)
            {
                return($"YES\n{x} {zi - x} {n - zi}");
            }

            if (max2[zi] == max2[zi + 1])
            {
                zi++;
            }
            min = st.Get(x, zi);
            if (min == m)
            {
                return($"YES\n{x} {zi - x} {n - zi}");
            }
        }
        return("NO");
    }
Example #9
0
    static object Solve()
    {
        var qc = int.Parse(Console.ReadLine());
        var qs = Array.ConvertAll(new bool[qc], _ => Read4());

        var xMap = new CompressionHashMap(qs.SelectMany(q => new[] { q.a, q.c }).ToArray());
        var yMap = new CompressionHashMap(qs.SelectMany(q => new[] { q.b, q.d }).ToArray());

        var n2 = 1;

        while (n2 < yMap.Count << 1)
        {
            n2 <<= 1;
        }

        var st  = new ST1 <long>(yMap.Count, (x, y) => x + y, 0, Enumerable.Range(0, yMap.Count - 1).Select(i => (long)yMap.ReverseMap[i + 1] - yMap.ReverseMap[i]).ToArray());
        var lst = new LST <bool, long>(yMap.Count,
                                       (x, y) => x ^ y, false,
                                       (x, y) => x + y, 0,
                                       (b, p, node, l) => st.Get(node.LastLeft(l).i - (n2 >> 1), node.LastRight(l).i - (n2 >> 1)) - p);

        var qd = qs
                 .SelectMany(q => new[] { (add: true, x: q.a, q.b, q.d), (add: false, x: q.c, q.b, q.d) })
Example #10
0
 /// <summary>
 /// Creates a string containing all non-vpu register/flag states"/>
 /// </summary>
 public string GetCPUDebugString()
 {
     return(CreateTable(new int[] { 26, 10, 0 }, new string[][]
     {
         new string[] { $"RAX: {RAX:x16}", $"CF: {(CF ? 1 : 0)}", $"RFLAGS: {RFLAGS:x16}" },
         new string[] { $"RBX: {RBX:x16}", $"PF: {(PF ? 1 : 0)}", $"RIP:    {RIP:x16}" },
         new string[] { $"RCX: {RCX:x16}", $"AF: {(AF ? 1 : 0)}" },
         new string[] { $"RDX: {RDX:x16}", $"ZF: {(ZF ? 1 : 0)}", $"ST0: {(ST_Tag(0) != FPU_Tag_empty ? ST0.ToString() : "Empty")}" },
         new string[] { $"RSI: {RSI:x16}", $"SF: {(SF ? 1 : 0)}", $"ST1: {(ST_Tag(1) != FPU_Tag_empty ? ST1.ToString() : "Empty")}" },
         new string[] { $"RDI: {RDI:x16}", $"OF: {(OF ? 1 : 0)}", $"ST2: {(ST_Tag(2) != FPU_Tag_empty ? ST2.ToString() : "Empty")}" },
         new string[] { $"RBP: {RBP:x16}", null, $"ST3: {(ST_Tag(3) != FPU_Tag_empty ? ST3.ToString() : "Empty")}" },
         new string[] { $"RSP: {RSP:x16}", $"b:  {(cc_b ? 1 : 0)}", $"ST4: {(ST_Tag(4) != FPU_Tag_empty ? ST4.ToString() : "Empty")}" },
         new string[] { $"R8:  {R8:x16}", $"be: {(cc_be ? 1 : 0)}", $"ST5: {(ST_Tag(5) != FPU_Tag_empty ? ST5.ToString() : "Empty")}" },
         new string[] { $"R9:  {R9:x16}", $"a:  {(cc_a ? 1 : 0)}", $"ST6: {(ST_Tag(6) != FPU_Tag_empty ? ST6.ToString() : "Empty")}" },
         new string[] { $"R10: {R10:x16}", $"ae: {(cc_ae ? 1 : 0)}", $"ST7: {(ST_Tag(7) != FPU_Tag_empty ? ST7.ToString() : "Empty")}" },
         new string[] { $"R11: {R11:x16}" },
         new string[] { $"R12: {R12:x16}", $"l:  {(cc_l ? 1 : 0)}", $"C0: {(FPU_C0 ? 1 : 0)}" },
         new string[] { $"R13: {R13:x16}", $"le: {(cc_le ? 1 : 0)}", $"C1: {(FPU_C1 ? 1 : 0)}" },
         new string[] { $"R14: {R14:x16}", $"g:  {(cc_g ? 1 : 0)}", $"C2: {(FPU_C2 ? 1 : 0)}" },
         new string[] { $"R15: {R15:x16}", $"ge: {(cc_ge ? 1 : 0)}", $"C3: {(FPU_C3 ? 1 : 0)}" },
     }));
 }
Example #11
0
    static void Main()
    {
        Console.SetOut(new System.IO.StreamWriter(Console.OpenStandardOutput())
        {
            AutoFlush = false
        });
        var(n, m, qc) = Read3();
        var qs = Array.ConvertAll(new bool[qc], _ => Read3());

        var map = new CompressionHashMap(qs.Select(q => q.y).Append(0).ToArray());

        var a = new int[n];
        var b = new int[m];

        var a_count = new ST1 <long>(map.Count, (x, y) => x + y, 0);
        var b_count = new ST1 <long>(map.Count, (x, y) => x + y, 0);

        var a_sum = new ST1 <long>(map.Count, (x, y) => x + y, 0);
        var b_sum = new ST1 <long>(map.Count, (x, y) => x + y, 0);

        a_count.Set(map[0], n);
        b_count.Set(map[0], m);

        var r = 0L;

        foreach (var(t, x, y) in qs)
        {
            var j = x - 1;

            if (t == 1)
            {
                var y0 = a[j];
                var i  = map[y];
                var i0 = map[y0];

                var sum0 = y0 * b_count.Get(map[0], i0) + b_sum.Get(i0, map.Count);
                var sum  = y * b_count.Get(map[0], i) + b_sum.Get(i, map.Count);
                r += sum - sum0;

                a[j] = y;
                a_count.Set(i0, a_count.Get(i0) - 1);
                a_count.Set(i, a_count.Get(i) + 1);
                a_sum.Set(i0, a_sum.Get(i0) - y0);
                a_sum.Set(i, a_sum.Get(i) + y);
            }
            else
            {
                var y0 = b[j];
                var i  = map[y];
                var i0 = map[y0];

                var sum0 = y0 * a_count.Get(map[0], i0) + a_sum.Get(i0, map.Count);
                var sum  = y * a_count.Get(map[0], i) + a_sum.Get(i, map.Count);
                r += sum - sum0;

                b[j] = y;
                b_count.Set(i0, b_count.Get(i0) - 1);
                b_count.Set(i, b_count.Get(i) + 1);
                b_sum.Set(i0, b_sum.Get(i0) - y0);
                b_sum.Set(i, b_sum.Get(i) + y);
            }
            Console.WriteLine(r);
        }
        Console.Out.Flush();
    }
Example #12
0
    static void Main()
    {
        var(n, qc) = Read2();
        var a  = Read();
        var qs = Array.ConvertAll(new bool[qc], _ => Read3());

        var vs = a.ToList();

        foreach (var(t, x, y) in qs)
        {
            if (t == 1)
            {
                vs.Add(y);
            }
        }
        var vMap = new CompressionHashMap(vs.ToArray());

        // キーの値となりうるインデックスのリスト
        var map0 = Array.ConvertAll(new bool[vMap.Count], _ => new List <int>());

        for (int i = 0; i < n; i++)
        {
            map0[vMap[a[i]]].Add(i);
        }

        foreach (var(t, x, y) in qs)
        {
            if (t == 1)
            {
                map0[vMap[y]].Add(x - 1);
            }
        }

        var map = Array.ConvertAll(map0, l =>
        {
            var b = l.ToArray();
            Array.Sort(b);
            return(b);
        });
        var u      = Array.ConvertAll(map, p => new bool[p.Length]);
        var mapInv = Array.ConvertAll(map, p => ToInverseMap(p));

        for (int i = 0; i < n; i++)
        {
            u[vMap[a[i]]][mapInv[vMap[a[i]]][i]] = true;
        }

        var st = new ST1 <int>(n, Math.Min, int.MaxValue, a);

        var r = new List <int>();

        Console.SetOut(new System.IO.StreamWriter(Console.OpenStandardOutput())
        {
            AutoFlush = false
        });
        foreach (var q in qs)
        {
            var(t, x, y) = q;
            x--;

            if (t == 1)
            {
                u[vMap[a[x]]][mapInv[vMap[a[x]]][x]] = false;
                a[x] = y;
                st.Set(x, y);
                u[vMap[a[x]]][mapInv[vMap[a[x]]][x]] = true;
            }
            else
            {
                r.Clear();

                var p    = st.Get(x, y);
                var inds = map[vMap[p]];
                var j0   = First(0, inds.Length, j => inds[j] >= x);

                for (int j = j0; j < inds.Length && inds[j] < y; j++)
                {
                    if (u[vMap[p]][j])
                    {
                        r.Add(inds[j] + 1);
                    }
                }
                Console.WriteLine($"{r.Count} " + string.Join(" ", r));
            }
        }
        Console.Out.Flush();
    }