コード例 #1
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);
    }