예제 #1
0
    static object Solve()
    {
        var n = int.Parse(Console.ReadLine());
        var a = Read();

        var map = new CompressionHashMap(a);

        var lst = new LST <long, long>(map.Count,
                                       (x, y) => y == -1 ? x : x * y % M, -1,
                                       (x, y) => (x + y) % M, 0,
                                       (x, p, _, l) => x == 0 ? p + 1 : p * x % M);

        var r = 0L;

        foreach (var av in a)
        {
            var v = map[av];

            r += lst.Get(0, v + 1);
            r %= M;

            lst.Set(0, map.Count, 2);
            lst.Set(v, 0);
        }

        return(r);
    }
예제 #2
0
    static void Main()
    {
        var n  = int.Parse(Console.ReadLine());
        var c  = Read();
        var qc = int.Parse(Console.ReadLine());

        Func <int, int> map = i => i % 2 == 0 ? i / 2 : (n + i) / 2;

        var c2 = new int[n];

        for (int i = 0; i < n; i++)
        {
            c2[map(i)] = c[i];
        }

        var st = new LST <int, int>(n,
                                    (x, y) => x + y, 0,
                                    Math.Min, int.MaxValue,
                                    (x, p, _, l) => p + x,
                                    c2);

        var r = 0L;

        for (int k = 0; k < qc; k++)
        {
            var q = Read();
            if (q[0] == 1)
            {
                if (st.Get(map(q[1] - 1)) >= q[2])
                {
                    st.Set(map(q[1] - 1), -q[2]);
                    r += q[2];
                }
            }
            else if (q[0] == 2)
            {
                if (st.Get(0, n / 2) >= q[1])
                {
                    st.Set(0, n / 2, -q[1]);
                    r += (long)(n + 1) / 2 * q[1];
                }
            }
            else
            {
                if (st.Get(0, n) >= q[1])
                {
                    st.Set(0, n, -q[1]);
                    r += (long)n * q[1];
                }
            }
        }
        Console.WriteLine(r);
    }
예제 #3
0
    static void Main()
    {
        Console.SetOut(new System.IO.StreamWriter(Console.OpenStandardOutput())
        {
            AutoFlush = false
        });
        var h = Read();
        var n = h[0];
        var a = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);

        var st = new LST <long, long>(n,
                                      (x, y) => x + y, 0,
                                      (x, y) => x + y, 0,
                                      (x, p, _, l) => p + x * l,
                                      a);

        for (int k = 0; k < h[1]; k++)
        {
            var q = Read();
            if (q[0] == 0)
            {
                st.Set(q[1], q[2]);
            }
            else
            {
                Console.WriteLine(st.Get(q[1], q[2]));
            }
        }
        Console.Out.Flush();
    }
예제 #4
0
    static void Main()
    {
        Console.SetOut(new System.IO.StreamWriter(Console.OpenStandardOutput())
        {
            AutoFlush = false
        });
        var h = Read();
        var n = h[0];

        var p = Powers(n - 1, 10);

        Array.Reverse(p);

        long[] unit = null;
        var    st   = new LST <int, long>(n,
                                          (x, y) => x == -1 ? y : x, -1,
                                          (x, y) => (x + y) % M, 0,
                                          (x, p, node, l) => x == -1 ? p : x * unit[node.i] % M,
                                          p);

        unit = (long[])st.a2.Clone();

        for (int k = 0; k < h[1]; k++)
        {
            var q = Read();
            st.Set(q[0] - 1, q[1], q[2]);
            Console.WriteLine(st.Get(0, n));
        }
        Console.Out.Flush();
    }
예제 #5
0
    static void Main()
    {
        Console.SetOut(new System.IO.StreamWriter(Console.OpenStandardOutput())
        {
            AutoFlush = false
        });
        var h = Read();
        var n = h[0];

        var st = new LST <long, long>(n + 1,
                                      (x, y) => x + y, 0,
                                      (x, y) => x + y, 0,
                                      (x, p, _, l) => p + x * l);

        for (int k = 0; k < h[1]; k++)
        {
            var q = Read();
            if (q[0] == 0)
            {
                st.Set(q[1], q[2] + 1, q[3]);
            }
            else
            {
                Console.WriteLine(st.Get(q[1], q[2] + 1));
            }
        }
        Console.Out.Flush();
    }
예제 #6
0
    static void Main()
    {
        var n  = int.Parse(Console.ReadLine());
        var rs = new int[n].Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()).ToArray();

        var xqs = rs.Select(r => new { x = r[0], d = 1, y1 = r[1], y2 = r[3] })
                  .Concat(rs.Select(r => new { x = r[2], d = -1, y1 = r[1], y2 = r[3] }))
                  .OrderBy(q => q.x);

        var st = new LST <int, int>(1000,
                                    (x, y) => x + y, 0,
                                    Math.Max, 0,
                                    (x, p, _, l) => p + x);
        int M = 0, xt = -1;

        foreach (var q in xqs)
        {
            if (xt < q.x)
            {
                M  = Math.Max(M, st.Get(0, 1000));
                xt = q.x;
            }

            st.Set(q.y1, q.y2, q.d);
        }
        Console.WriteLine(M);
    }
예제 #7
0
    static void Main()
    {
        Console.SetOut(new System.IO.StreamWriter(Console.OpenStandardOutput())
        {
            AutoFlush = false
        });
        var h = Read();
        var n = h[0];

        var st = new LST <int, int>(n,
                                    (x, y) => x == int.MinValue ? y : x, int.MinValue,
                                    Math.Min, int.MaxValue,
                                    (x, p, _, l) => x == int.MinValue ? p : x);

        for (int k = 0; k < h[1]; k++)
        {
            var q = Read();
            if (q[0] == 0)
            {
                st.Set(q[1], q[2] + 1, q[3]);
            }
            else
            {
                Console.WriteLine(st.Get(q[1], q[2] + 1));
            }
        }
        Console.Out.Flush();
    }
예제 #8
0
    static void Main()
    {
        var(n, qc) = Read2();
        var s  = Console.ReadLine().Select(c => c == '(' ? 1 : -1).ToArray();
        var qs = Array.ConvertAll(new bool[qc], _ => Read());

        var cs = new int[n + 1];

        for (int i = 0; i < n; ++i)
        {
            cs[i + 1] = cs[i] + s[i];
        }

        var st = new LST <int, int>(n + 1,
                                    (x, y) => x + y, 0,
                                    Math.Min, 1 << 30,
                                    (x, p, _, l) => x + p,
                                    cs);

        Console.SetOut(new System.IO.StreamWriter(Console.OpenStandardOutput())
        {
            AutoFlush = false
        });
        foreach (var q in qs)
        {
            var(l, r) = (q[1], q[2]);

            if (q[0] == 1)
            {
                if (s[l - 1] == s[r - 1])
                {
                    continue;
                }

                st.Set(l, r, s[l - 1] == 1 ? -2 : 2);
                s[l - 1] *= -1;
                s[r - 1] *= -1;
            }
            else
            {
                if ((r - l) % 2 == 0)
                {
                    WriteYesNo(false);
                    continue;
                }

                var vl = st.Get(l - 1);
                var vr = st.Get(r);
                if (vl != vr)
                {
                    WriteYesNo(false);
                    continue;
                }

                WriteYesNo(st.Get(l, r) >= vl);
            }
        }
        Console.Out.Flush();
    }
예제 #9
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 LST <int, int>(n,
                                    (x, y) => x == int.MinValue ? y : x, int.MinValue,
                                    Math.Max, int.MinValue,
                                    (x, p, _, l) => x == int.MinValue ? p : x,
                                    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.a2[node.i] < q[2])
                    {
                        return(p);
                    }
                    while (node.i < st.n2 >> 1)
                    {
                        node = q[2] <= st.a2[node.Child0.i] ? node.Child0 : node.Child1;
                    }
                    return(st.Original(node));
                }));
            }
        }
        Console.Out.Flush();
    }
예제 #10
0
    static void Main()
    {
        var h = Read();
        int n = h[0], k = h[1];
        var a = Array.ConvertAll(new int[n], _ => int.Parse(Console.ReadLine()));

        var st = new LST <int, int>(kM + 1,
                                    Math.Max, 0,
                                    Math.Max, 0,
                                    (x, p, _, l) => Math.Max(x, p));

        for (int i = 0; i < n; i++)
        {
            st.Set(Math.Max(0, a[i] - k), Math.Min(kM + 1, a[i] + k + 1), st.Get(a[i]) + 1);
        }

        Console.WriteLine(st.Get(0, kM + 1));
    }
예제 #11
0
    static void Main()
    {
        var(w, n) = Read2();
        var qs = Array.ConvertAll(new bool[n], _ => Read2());

        var st = new LST <int, int>(w,
                                    (x, y) => x == int.MinValue ? y : x, int.MinValue,
                                    Math.Max, int.MinValue,
                                    (x, p, _, l) => x == int.MinValue ? p : x,
                                    new int[w]);

        Console.SetOut(new System.IO.StreamWriter(Console.OpenStandardOutput())
        {
            AutoFlush = false
        });
        foreach (var(l, r) in qs)
        {
            var m = st.Get(l - 1, r) + 1;
            st.Set(l - 1, r, m);
            Console.WriteLine(m);
        }
        Console.Out.Flush();
    }
예제 #12
0
    static object Solve()
    {
        var(n, m, p) = Read3();
        var acs  = Array.ConvertAll(new bool[n], _ => Read2());
        var bcs  = Array.ConvertAll(new bool[m], _ => Read2());
        var xyzs = Array.ConvertAll(new bool[p], _ => Read3()).OrderBy(t => t.Item1).ToArray();

        // price of armor set for each defence
        var b0 = Array.ConvertAll(new bool[max + 1], _ => int.MinValue);

        foreach (var(b, c) in bcs)
        {
            b0[b] = Math.Max(b0[b], -c);
        }

        var st = new LST <int, int>(max + 1,
                                    (x, y) => x + y, 0,
                                    Math.Max, int.MinValue,
                                    (x, p, _, l) => p + x,
                                    b0);

        var r  = int.MinValue;
        var xi = 0;

        foreach (var(a, c) in acs.OrderBy(t => t.Item2))
        {
            for (; xi < p && xyzs[xi].Item1 < a; xi++)
            {
                var(_, y, z) = xyzs[xi];
                st.Set(y + 1, max + 1, z);
            }

            r = Math.Max(r, st.Get(0, max + 1) - c);
        }
        return(r);
    }