Ejemplo n.º 1
0
    void Calc()
    {
        string[] str = Console.ReadLine().Split(' ');
        int      N   = int.Parse(str[0]);
        int      M   = int.Parse(str[1]);

        int[] L = new int[N];
        int[] R = new int[N];
        int[] C = new int[N];
        for (int i = 0; i < N; i++)
        {
            str  = Console.ReadLine().Split(' ');
            L[i] = int.Parse(str[0]);
            R[i] = int.Parse(str[1]);
            C[i] = i;
        }
        Array.Sort(C, (x, y) => (R[y] - R[x]));
        int     count = Math.Max(N - M, 0);
        SegTree Seg   = new SegTree(M + 2, this);

        for (int i = 2 * M + 2; i >= 0; i--)
        {
            if (i >= Seg.segf)
            {
                Seg.Z[i] = -Seg.ToPoint(i);
            }
            else
            {
                int sl = i * 2 + 1;
                int sr = i * 2 + 2;
                Seg.Z[i] = Math.Max(Seg.Z[sl], Seg.Z[sr]);
            }
        }
        int p = 0;

        for (int i = M; i >= 0; i--)
        {
            while (p < N && R[C[p]] >= i + 1)
            {
                Seg.Add(L[C[p]], M + 1);
                p++;
            }
            int A = Seg.Max(0, i) - (M - i);
            count = Math.Max(count, A);
        }
        sb.Append(count + "\n");
    }
Ejemplo n.º 2
0
    void Calc()
    {
        string[] str = Console.ReadLine().Split(' ');
        long     x1  = int.Parse(str[0]);
        long     y1  = int.Parse(str[1]);
        long     x2  = int.Parse(str[2]);
        long     y2  = int.Parse(str[3]);
        int      N   = int.Parse(Console.ReadLine());
        double   count;

        if (x1 == x2)
        {
            bool b = false;
            for (int i = 0; i < N; i++)
            {
                str = Console.ReadLine().Split(' ');
                long X = int.Parse(str[0]);
                if (x1 == X)
                {
                    long Y = int.Parse(str[1]);
                    if (Math.Min(y1, y2) < Y && Y < Math.Max(y1, y2))
                    {
                        b = true;
                    }
                    break;
                }
            }
            count = (Math.Max(y1, y2) - Math.Min(y1, y2)) * 100 + (b ? (20 * (Math.PI / 2 - 1)) : 0);
        }
        else if (y1 == y2)
        {
            bool b = false;
            for (int i = 0; i < N; i++)
            {
                str = Console.ReadLine().Split(' ');
                long Y = int.Parse(str[1]);
                if (y1 == Y)
                {
                    long X = int.Parse(str[0]);
                    if (Math.Min(x1, x2) < X && X < Math.Max(x1, x2))
                    {
                        b = true;
                    }
                    break;
                }
            }
            count = (Math.Max(x1, x2) - Math.Min(x1, x2)) * 100 + (b ? (20 * (Math.PI / 2 - 1)) : 0);
        }
        else
        {
            long[] xp = new long[N];
            long[] yp = new long[N];
            for (int i = 0; i < N; i++)
            {
                str = Console.ReadLine().Split(' ');
                long X = int.Parse(str[0]);
                if (x1 > x2)
                {
                    X = 100000000 - 1 - X;
                }
                long Y = int.Parse(str[1]);
                if (y1 > y2)
                {
                    Y = 100000000 - 1 - Y;
                }
                xp[i] = X;
                yp[i] = Y;
            }
            if (x1 > x2)
            {
                x1 = 100000000 - 1 - x1;
                x2 = 100000000 - 1 - x2;
            }
            if (y1 > y2)
            {
                y1 = 100000000 - 1 - y1;
                y2 = 100000000 - 1 - y2;
            }
            long[]      DX;
            long[]      DY;
            Compression YC;
            {
                List <long> LX = new List <long>();
                List <long> LY = new List <long>();
                for (int i = 0; i < N; i++)
                {
                    if (x1 <= xp[i] && xp[i] <= x2 && y1 <= yp[i] && yp[i] <= y2)
                    {
                        LX.Add(xp[i]);
                        LY.Add(yp[i]);
                    }
                }
                DX = LX.ToArray();
                DY = LY.ToArray();
                YC = new Compression(LY.ToArray());
            }
            Array.Sort(DX, DY);
            if (DY.Length != 0)
            {
                bool b1 = (DY[0] == y1 && DY[DY.Length - 1] == y2);
                bool b2 = (DX[0] == x1 && DX[DX.Length - 1] == x2);
                for (int i = 1; i < DY.Length; i++)
                {
                    b2 &= DX[i] == DX[i - 1] + 1 && DY[i] > DY[i - 1];
                    b1 &= DY[i] == DY[i - 1] + 1;
                }
                SegTree Seg = new SegTree(YC.size, this);
                for (int i = 0; i < DY.Length; i++)
                {
                    int YP = YC.ToPoint(DY[i]);
                    Seg.Add(YP, Seg.Max(0, YP) + 1);
                }
                count = (y2 - y1 + x2 - x1) * 100 - (20 - 5 * Math.PI) * Seg.Max(0, YC.size - 1) + ((b1 || b2) ? 5 * Math.PI : 0);
            }
            else
            {
                count = (y2 - y1 + x2 - x1) * 100;
            }
        }
        sb.Append(count + "\n");
    }