Exemplo n.º 1
0
    private static void Main()
    {
        int arrayLength;

        while ((arrayLength = FastIO.ReadNonNegativeInt()) != 0)
        {
            int   queryCount  = FastIO.ReadNonNegativeInt();
            int[] sourceArray = new int[arrayLength];
            for (int i = 0; i < arrayLength; ++i)
            {
                sourceArray[i] = FastIO.ReadInt();
            }

            var solver = new FREQUENT(sourceArray);

            for (int q = 0; q < queryCount; ++q)
            {
                FastIO.WriteInt(solver.Query(
                                    queryStartIndex: FastIO.ReadNonNegativeInt() - 1,
                                    queryEndIndex: FastIO.ReadNonNegativeInt() - 1));
                FastIO.WriteLine();
            }
        }

        FastIO.Flush();
    }
Exemplo n.º 2
0
    private static void Main()
    {
        int remainingTestCases = FastIO.ReadNonNegativeInt();

        while (remainingTestCases-- > 0)
        {
            int knownLength   = FastIO.ReadNonNegativeInt();
            int unknownLength = FastIO.ReadNonNegativeInt();

            int?[] sequence = new int?[knownLength + unknownLength];
            for (int i = 0; i < knownLength; ++i)
            {
                sequence[i] = FastIO.ReadInt();
            }

            CMPLS.Solve(sequence, knownLength, unknownLength);

            for (int i = knownLength; i < sequence.Length; ++i)
            {
                FastIO.WriteNonNegativeInt(sequence[i].Value);
                FastIO.WriteSpace();
            }

            FastIO.WriteLine();
        }

        FastIO.Flush();
    }
Exemplo n.º 3
0
Arquivo: RPLN.cs Projeto: Dariasz/SPOJ
    private static void Main()
    {
        var output    = new StringBuilder();
        int testCount = FastIO.ReadNonNegativeInt();

        for (int t = 1; t <= testCount; ++t)
        {
            int scoreCount = FastIO.ReadNonNegativeInt();
            int queryCount = FastIO.ReadNonNegativeInt();

            int[] scores = new int[scoreCount];
            for (int s = 0; s < scoreCount; ++s)
            {
                scores[s] = FastIO.ReadInt();
            }

            var solver = new RPLN(scores);

            output.AppendLine($"Scenario #{t}:");
            for (int q = 0; q < queryCount; ++q)
            {
                output.Append(solver.Solve(
                                  queryStartIndex: FastIO.ReadNonNegativeInt() - 1,
                                  queryEndIndex: FastIO.ReadNonNegativeInt() - 1));
                output.AppendLine();
            }
        }

        Console.Write(output);
    }
Exemplo n.º 4
0
    private static void Main()
    {
        int remainingTestCases = FastIO.ReadNonNegativeInt();

        while (remainingTestCases-- > 0)
        {
            int matrixSize = FastIO.ReadNonNegativeInt();
            var solver     = new MATSUM(matrixSize);

            char command;
            while ((command = FastIO.ReadCommand()) != 'E')
            {
                if (command == 'S')
                {
                    solver.Set(
                        rowIndex: FastIO.ReadNonNegativeInt(),
                        columnIndex: FastIO.ReadNonNegativeInt(),
                        value: FastIO.ReadInt());
                }
                else
                {
                    FastIO.WriteInt(solver.Query(
                                        nearRowIndex: FastIO.ReadNonNegativeInt(),
                                        nearColumnIndex: FastIO.ReadNonNegativeInt(),
                                        farRowIndex: FastIO.ReadNonNegativeInt(),
                                        farColumnIndex: FastIO.ReadNonNegativeInt()));
                    FastIO.WriteLine();
                }
            }
            FastIO.WriteLine();
        }

        FastIO.Flush();
    }
Exemplo n.º 5
0
    private static void Main()
    {
        int n = FastIO.ReadNonNegativeInt();

        for (int i = 0; i < n; ++i)
        {
            FastIO.WriteInt(FastIO.ReadInt() * FastIO.ReadInt());
            FastIO.WriteLine();
        }

        FastIO.Flush();
    }
Exemplo n.º 6
0
    private static void Main()
    {
        int remainingTestCases = FastIO.ReadNonNegativeInt();

        while (remainingTestCases-- > 0)
        {
            FastIO.WriteInt(
                TEMPLATE3.Solve(FastIO.ReadInt(), FastIO.ReadInt()));
            FastIO.WriteLine();
        }

        FastIO.Flush();
    }
Exemplo n.º 7
0
    private static void Main()
    {
        int operationCount = FastIO.ReadNonNegativeInt();
        var operations     = new Operation[operationCount];
        var possibleValues = new HashSet <int>();

        for (int o = 0; o < operationCount; ++o)
        {
            operations[o] = new Operation(
                operationType: FastIO.ReadOperationType(),
                operationParameter: FastIO.ReadInt());

            if (operations[o].OperationType == 'I')
            {
                possibleValues.Add(operations[o].OperationParameter);
            }
        }

        var solver = new ORDERSET(possibleValues);
        var output = new StringBuilder();

        for (int o = 0; o < operationCount; ++o)
        {
            switch (operations[o].OperationType)
            {
            case 'I':
                solver.Insert(value: operations[o].OperationParameter);
                break;

            case 'D':
                solver.Delete(value: operations[o].OperationParameter);
                break;

            case 'K':
                output.AppendLine(solver
                                  .GetKthSmallest(k: operations[o].OperationParameter)
                                  ?.ToString() ?? "invalid");
                break;

            case 'C':
                output.AppendLine(solver
                                  .CountValuesSmallerThan(value: operations[o].OperationParameter)
                                  .ToString());
                break;

            default: throw new InvalidOperationException();
            }
        }

        Console.Write(output);
    }
Exemplo n.º 8
0
    private static void Main()
    {
        int sourceArrayLength = FastIO.ReadNonNegativeInt();
        int queryCount        = FastIO.ReadNonNegativeInt();

        int[] sourceArray = new int[sourceArrayLength];
        for (int i = 0; i < sourceArrayLength; ++i)
        {
            sourceArray[i] = FastIO.ReadInt();
        }

        var solver = new MKTHNUM(sourceArray);

        for (int q = 0; q < queryCount; ++q)
        {
            FastIO.WriteInt(solver.Query(
                                queryStartIndex: FastIO.ReadNonNegativeInt() - 1,
                                queryEndIndex: FastIO.ReadNonNegativeInt() - 1,
                                k: FastIO.ReadNonNegativeInt()));
            FastIO.WriteLine();
        }

        FastIO.Flush();
    }