示例#1
0
    void F(RangeMinimumQuerry RMQ, int l, int r)
    {
        RMQ.Querry(l, r);
        int s = RMQ.C;

        Add(l, s, s, r, RMQ.D);
        if (s != l)
        {
            F(RMQ, l, s - 1);
        }
        if (s != r)
        {
            F(RMQ, s + 1, r);
        }
    }
示例#2
0
    void Calc()
    {
        string[] str = Console.ReadLine().Split(' ');
        N = int.Parse(str[0]);
        int M = int.Parse(str[1]);

        long[] A = new long[N];
        str = Console.ReadLine().Split(' ');
        for (int i = 0; i < N - 1; i++)
        {
            A[i + 1] = A[i] + int.Parse(str[i]);
        }
        long[,] B = new long[N, M];
        for (int i = 0; i < N; i++)
        {
            str = Console.ReadLine().Split(' ');
            for (int j = 0; j < M; j++)
            {
                B[i, j] = int.Parse(str[j]);
            }
        }
        Map = new long[N, N];
        for (int j = 0; j < M; j++)
        {
            RangeMinimumQuerry RMQ = new RangeMinimumQuerry(N, this);
            for (int i = 2 * N - 2; i >= 0; i--)
            {
                if (i >= RMQ.segf)
                {
                    RMQ.X[i] = B[RMQ.ToPoint(i), j];
                    RMQ.Y[i] = RMQ.ToPoint(i);
                }
                else
                {
                    int sl = i * 2 + 1;
                    int sr = i * 2 + 2;
                    if (RMQ.X[sl] > RMQ.X[sr])
                    {
                        RMQ.X[i] = RMQ.X[sl];
                        RMQ.Y[i] = RMQ.Y[sl];
                    }
                    else
                    {
                        RMQ.X[i] = RMQ.X[sr];
                        RMQ.Y[i] = RMQ.Y[sr];
                    }
                }
            }
            F(RMQ, 0, N - 1);
        }
        long max = 0;

        for (int i = 0; i < N; i++)
        {
            for (int j = 0; j < N; j++)
            {
                Map[i, j] += (i == 0 ? 0 : Map[i - 1, j]) + (j == 0 ? 0 : Map[i, j - 1]) - ((i == 0 || j == 0) ? 0 : Map[i - 1, j - 1]);
            }
        }
        for (int i = 0; i < N; i++)
        {
            for (int j = i; j < N; j++)
            {
                max = Math.Max(max, Map[i, j] + A[i] - A[j]);
            }
        }
        sb.Append(max + "\n");
    }