Esempio n. 1
0
    private static void Main()
    {
        int lightCount = FastIO.ReadNonNegativeInt();
        var solver     = new LITE(lightCount);

        int operationCount = FastIO.ReadNonNegativeInt();

        for (int o = 0; o < operationCount; ++o)
        {
            int operation = FastIO.ReadNonNegativeInt();

            if (operation == 0)
            {
                solver.Push(
                    pushStartIndex: FastIO.ReadNonNegativeInt() - 1,
                    pushEndIndex: FastIO.ReadNonNegativeInt() - 1);
            }
            else
            {
                FastIO.WriteNonNegativeInt(solver.Query(
                                               queryStartIndex: FastIO.ReadNonNegativeInt() - 1,
                                               queryEndIndex: FastIO.ReadNonNegativeInt() - 1));
                FastIO.WriteLine();
            }
        }

        FastIO.Flush();
    }
Esempio 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();
    }
Esempio n. 3
0
    private static void Main()
    {
        int arrayLength = FastIO.ReadNonNegativeInt();
        var solver      = new MULTQ3(arrayLength);

        int operationCount = FastIO.ReadNonNegativeInt();

        for (int o = 0; o < operationCount; ++o)
        {
            int operation = FastIO.ReadNonNegativeInt();

            if (operation == 0)
            {
                solver.Increment(
                    incrementStartIndex: FastIO.ReadNonNegativeInt(),
                    incrementEndIndex: FastIO.ReadNonNegativeInt());
            }
            else
            {
                FastIO.WriteNonNegativeInt(solver.Query(
                                               queryStartIndex: FastIO.ReadNonNegativeInt(),
                                               queryEndIndex: FastIO.ReadNonNegativeInt()));
                FastIO.WriteLine();
            }
        }

        FastIO.Flush();
    }
Esempio n. 4
0
File: RPLN.cs Progetto: 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);
    }
Esempio n. 5
0
    private static void Main()
    {
        int sourceArrayLength = FastIO.ReadNonNegativeInt();

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

        int queryCount = FastIO.ReadNonNegativeInt();
        var queries    = new GreaterThanQuery[queryCount];

        for (int q = 0; q < queryCount; ++q)
        {
            queries[q] = new GreaterThanQuery(
                queryStartIndex: FastIO.ReadNonNegativeInt() - 1,
                queryEndIndex: FastIO.ReadNonNegativeInt() - 1,
                greaterThanLowerLimit: FastIO.ReadNonNegativeInt(),
                resultIndex: q);
        }

        int[] queryResults = KQUERY.SolveOffline(sourceArray, queries);
        foreach (int queryResult in queryResults)
        {
            FastIO.WriteNonNegativeInt(queryResult);
            FastIO.WriteLine();
        }

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

        while (remainingTestCases-- > 0)
        {
            int cityCount      = FastIO.ReadNonNegativeInt();
            int highwayCount   = FastIO.ReadNonNegativeInt();
            int startCityIndex = FastIO.ReadNonNegativeInt() - 1;
            int endCityIndex   = FastIO.ReadNonNegativeInt() - 1;
            var cityGraph      = new WeightedSimpleGraph(cityCount);

            for (int h = 0; h < highwayCount; ++h)
            {
                cityGraph.AddEdge(
                    firstVertexID: FastIO.ReadNonNegativeInt() - 1,
                    secondVertexID: FastIO.ReadNonNegativeInt() - 1,
                    weight: FastIO.ReadNonNegativeInt());
            }

            int?totalMinutes = HIGHWAYS.Solve(cityGraph,
                                              startCity: cityGraph.Vertices[startCityIndex],
                                              endCity: cityGraph.Vertices[endCityIndex]);

            Console.WriteLine(totalMinutes?.ToString() ?? "NONE");
        }
    }
Esempio n. 7
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();
    }
Esempio n. 8
0
    private static void Main()
    {
        var output    = new StringBuilder();
        int testCount = FastIO.ReadNonNegativeInt();

        for (int t = 1; t <= testCount; ++t)
        {
            int bugCount         = FastIO.ReadNonNegativeInt();
            int interactionCount = FastIO.ReadNonNegativeInt();
            var interactionGraph = new SimpleGraph(bugCount);

            for (int i = 0; i < interactionCount; ++i)
            {
                interactionGraph.AddEdge(
                    firstVertexID: FastIO.ReadNonNegativeInt() - 1,
                    secondVertexID: FastIO.ReadNonNegativeInt() - 1);
            }

            output.AppendLine($"Scenario #{t}:");
            output.AppendLine(BUGLIFE.Solve(interactionGraph)
                ? "No suspicious bugs found!" : "Suspicious bugs found!");
        }

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

        while (remainingTestCases-- > 0)
        {
            int stationCount = FastIO.ReadNonNegativeInt();
            int humanLimit   = FastIO.ReadNonNegativeInt();

            int[] stationHumanCounts = new int[stationCount];
            for (int s = 0; s < stationCount; ++s)
            {
                stationHumanCounts[s] = FastIO.ReadNonNegativeInt();
            }

            var solution = ALIEN.Solve(stationCount, humanLimit, stationHumanCounts);

            FastIO.WriteNonNegativeInt(solution.HumansSeen);
            FastIO.WriteSpace();
            FastIO.WriteNonNegativeInt(solution.StationsPassed);
            FastIO.WriteLine();
        }

        FastIO.Flush();
    }
Esempio n. 10
0
    private static void Main()
    {
        var output             = new StringBuilder();
        int remainingTestCases = FastIO.ReadNonNegativeInt();

        while (remainingTestCases-- > 0)
        {
            int cityCount = FastIO.ReadNonNegativeInt();
            var edges     = new List <Edge>(capacity: 2 * cityCount);

            for (int c = 0; c < cityCount; ++c)
            {
                FastIO.ConsumeString(); // Discard city name.

                int neighborCount = FastIO.ReadNonNegativeInt();
                for (int n = 0; n < neighborCount; ++n)
                {
                    edges.Add(new Edge(
                                  sourceCity: c,
                                  destinationCity: FastIO.ReadNonNegativeInt() - 1,
                                  cost: FastIO.ReadNonNegativeInt()));
                }
            }

            output.Append(
                BLINNET.Solve(cityCount, edges));
            output.AppendLine();
        }

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

        while (remainingTestCases-- > 0)
        {
            int   digitCount = FastIO.ReadNonNegativeInt();
            int[] digits     = new int[digitCount];

            for (int d = 0; d < digitCount; ++d)
            {
                digits[d] = FastIO.ReadNonNegativeInt();
            }

            if (JNEXT.Solve(digitCount, digits))
            {
                for (int d = 0; d < digitCount; ++d)
                {
                    FastIO.WriteDigit(digits[d]);
                }
            }
            else
            {
                FastIO.WriteNegativeOne();
            }

            FastIO.WriteLine();
        }

        FastIO.Flush();
    }
Esempio n. 12
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();
    }
Esempio n. 13
0
    private static void Main()
    {
        int remainingTestCases = FastIO.ReadNonNegativeInt();

        while (remainingTestCases-- > 0)
        {
            int arrayLength = FastIO.ReadNonNegativeInt();
            int updateCount = FastIO.ReadNonNegativeInt();

            var solver = new UPDATEIT(arrayLength);

            for (int u = 0; u < updateCount; ++u)
            {
                solver.Update(
                    updateStartIndex: FastIO.ReadNonNegativeInt(),
                    updateEndIndex: FastIO.ReadNonNegativeInt(),
                    delta: FastIO.ReadNonNegativeInt());
            }

            int queryCount = FastIO.ReadNonNegativeInt();
            for (int q = 0; q < queryCount; ++q)
            {
                FastIO.WriteNonNegativeInt(solver.Query(
                                               queryIndex: FastIO.ReadNonNegativeInt()));
                FastIO.WriteLine();
            }
        }

        FastIO.Flush();
    }
Esempio n. 14
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();
    }
Esempio n. 15
0
    private static void Main()
    {
        int remainingTestCases = FastIO.ReadNonNegativeInt();

        while (remainingTestCases-- > 0)
        {
            FastIO.WriteNonNegativeInt(
                COMDIV.Solve(FastIO.ReadNonNegativeInt(), FastIO.ReadNonNegativeInt()));
            FastIO.WriteLine();
        }

        FastIO.Flush();
    }
Esempio n. 16
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);
    }
Esempio n. 17
0
    private static void Main()
    {
        int treeSize = FastIO.ReadNonNegativeInt();
        var tree     = new SimpleGraph(treeSize);

        for (int e = 0; e < treeSize - 1; ++e)
        {
            int firstVertexID  = FastIO.ReadNonNegativeInt() - 1;
            int secondVertexID = FastIO.ReadNonNegativeInt() - 1;
            tree.AddEdge(firstVertexID, secondVertexID);
        }

        Console.Write(PT07X.Solve(tree));
    }
Esempio n. 18
0
File: ZSUM.cs Progetto: Dariasz/SPOJ
    private static void Main()
    {
        int n, k;

        while ((n = FastIO.ReadNonNegativeInt()) != 0)
        {
            k = FastIO.ReadNonNegativeInt();

            FastIO.WriteNonNegativeInt(
                ZSUM.Solve(n, k));
            FastIO.WriteLine();
        }

        FastIO.Flush();
    }
Esempio n. 19
0
    private static void Main()
    {
        int remainingTestCases = FastIO.ReadNonNegativeInt();

        while (remainingTestCases-- > 0)
        {
            int[] array = new int[FastIO.ReadNonNegativeInt()];
            for (int i = 0; i < array.Length; ++i)
            {
                array[i] = FastIO.ReadNonNegativeInt();
            }

            Console.WriteLine(
                CODESPTB.Solve(array));
        }
    }
Esempio n. 20
0
    private static void Main()
    {
        int treeCount      = FastIO.ReadNonNegativeInt();
        int requiredLength = FastIO.ReadNonNegativeInt();

        int[] treeHeights = new int[treeCount];
        for (int t = 0; t < treeCount; ++t)
        {
            treeHeights[t] = FastIO.ReadNonNegativeInt();
        }

        FastIO.WriteNonNegativeInt(
            EKO.Solve(treeCount, requiredLength, treeHeights));

        FastIO.Flush();
    }
Esempio n. 21
0
    private static void Main()
    {
        var output    = new StringBuilder();
        int testCount = FastIO.ReadNonNegativeInt();

        for (int t = 1; t <= testCount; ++t)
        {
            int a = FastIO.ReadNonNegativeInt();
            int b = FastIO.ReadNonNegativeInt();
            int c = FastIO.ReadNonNegativeInt();

            output.AppendLine(
                $"Case {t}: {(CEQU.Solve(a, b, c) ? "Yes" : "No")}");
        }

        Console.Write(output);
    }
Esempio n. 22
0
    private static void Main()
    {
        int n     = FastIO.ReadNonNegativeInt();
        int k     = FastIO.ReadNonNegativeInt();
        int count = 0;

        for (int i = 0; i < n; ++i)
        {
            if (FastIO.ReadNonNegativeInt() % k == 0)
            {
                ++count;
            }
        }

        FastIO.WriteNonNegativeInt(count);
        FastIO.Flush();
    }
Esempio n. 23
0
    private static void Main()
    {
        var output             = new StringBuilder();
        int remainingTestCases = FastIO.ReadNonNegativeInt();

        while (remainingTestCases-- > 0)
        {
            int a = FastIO.ReadNonNegativeInt();
            int b = FastIO.ReadNonNegativeInt();

            output.Append(
                TEMPLATE4.Solve(a, b));
            output.AppendLine();
        }

        Console.Write(output);
    }
Esempio n. 24
0
    private static void Main()
    {
        int remainingPyanis = FastIO.ReadNonNegativeInt();
        int result          = 0;

        while (remainingPyanis-- > 0)
        {
            // It's easy to see XOR'ing will work if all integer pairs arrive adjacent to each
            // other. Since XOR is commutative and associative though, the order the integers
            // arrive doesn't matter. For intuition, all columns of 1s and 0s are independent,
            // and anything XOR'd with 0 is the same thing, so the 0s in a column don't matter,
            // and then it's just a bunch of 1s, independent of the order in which the numbers
            // arrive. The paired 1s cancel, leaving only the 1s from the unique.
            result ^= FastIO.ReadNonNegativeInt();
        }

        FastIO.WriteNonNegativeInt(result);
        FastIO.Flush();
    }
Esempio n. 25
0
    private static void Main()
    {
        int intersectionCount;

        while ((intersectionCount = FastIO.ReadNonNegativeInt()) != 0)
        {
            int streetCount       = FastIO.ReadNonNegativeInt();
            var intersectionGraph = new WeightedSimpleGraph(intersectionCount);

            for (int i = 0; i < streetCount; ++i)
            {
                intersectionGraph.AddEdge(
                    firstVertexID: FastIO.ReadNonNegativeInt() - 1,
                    secondVertexID: FastIO.ReadNonNegativeInt() - 1,
                    weight: FastIO.ReadNonNegativeInt());
            }

            Console.WriteLine(
                $"{CHICAGO.Solve(intersectionGraph):F6} percent");
        }
    }
Esempio n. 26
0
    private static void Main()
    {
        var output    = new StringBuilder();
        int testCount = FastIO.ReadNonNegativeInt();

        for (int t = 0; t < testCount; ++t)
        {
            int cityCount   = FastIO.ReadNonNegativeInt();
            var cityIndices = new Dictionary <string, int>(cityCount);
            var cityGraph   = new List <KeyValuePair <int, int> > [cityCount];

            for (int c = 0; c < cityCount; ++c)
            {
                cityIndices.Add(FastIO.ReadString(), c);
                cityGraph[c] = new List <KeyValuePair <int, int> >();

                int neighborCount = FastIO.ReadNonNegativeInt();
                for (int n = 0; n < neighborCount; ++n)
                {
                    int neighborIndex  = FastIO.ReadNonNegativeInt() - 1;
                    int connectionCost = FastIO.ReadNonNegativeInt();

                    cityGraph[c].Add(new KeyValuePair <int, int>(neighborIndex, connectionCost));
                }
            }

            int pathCount = FastIO.ReadNonNegativeInt();
            for (int p = 0; p < pathCount; ++p)
            {
                int sourceCity      = cityIndices[FastIO.ReadString()];
                int destinationCity = cityIndices[FastIO.ReadString()];

                output.Append(
                    SHPATH.Solve(cityGraph, sourceCity, destinationCity));
                output.AppendLine();
            }
        }

        Console.Write(output);
    }
Esempio n. 27
0
    private static void Main()
    {
        var output      = new StringBuilder();
        int gameCounter = 0;
        int cardCount;

        while ((cardCount = FastIO.ReadNonNegativeInt()) != 0)
        {
            int[] cards = new int[cardCount];
            for (int c = 0; c < cardCount; ++c)
            {
                cards[c] = FastIO.ReadNonNegativeInt();
            }

            output.Append(
                $"In game {++gameCounter}, the greedy strategy might lose by as" +
                $" many as {TWENDS.Solve(cardCount, cards)} points.");
            output.AppendLine();
        }

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

        while (remainingTestCases-- > 0)
        {
            var solver = new CAM5(peerCount: FastIO.ReadNonNegativeInt());

            int friendCount = FastIO.ReadNonNegativeInt();
            for (int i = 0; i < friendCount; ++i)
            {
                solver.AddFriendAssociation(
                    firstPeer: FastIO.ReadNonNegativeInt(),
                    secondPeer: FastIO.ReadNonNegativeInt());
            }

            FastIO.WriteNonNegativeInt(solver.Solve());
            FastIO.WriteLine();
        }

        FastIO.Flush();
    }
Esempio n. 29
0
    private static void Main()
    {
        int[,] edges = new int[9999, 3];
        int remainingTestCases = FastIO.ReadNonNegativeInt();

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

            for (int i = 0; i < vertexCount - 1; ++i)
            {
                edges[i, 0] = FastIO.ReadNonNegativeInt() - 1; // first vertex ID
                edges[i, 1] = FastIO.ReadNonNegativeInt() - 1; // second vertex ID
                edges[i, 2] = FastIO.ReadNonNegativeInt();     // weight
            }

            var solver = new QTREE(vertexCount, edges);

            char instruction;
            while ((instruction = FastIO.ReadInstruction()) != 'D')
            {
                if (instruction == 'Q')
                {
                    FastIO.WriteNonNegativeInt(solver.Query(
                                                   firstVertexID: FastIO.ReadNonNegativeInt() - 1,
                                                   secondVertexID: FastIO.ReadNonNegativeInt() - 1));
                    FastIO.WriteLine();
                }
                else
                {
                    solver.Change(
                        edgeID: FastIO.ReadNonNegativeInt() - 1,
                        weight: FastIO.ReadNonNegativeInt());
                }
            }
        }

        FastIO.Flush();
    }
Esempio n. 30
0
    private static void Main()
    {
        var output             = new StringBuilder();
        int remainingTestCases = FastIO.ReadNonNegativeInt();

        while (remainingTestCases-- > 0)
        {
            int maxWeight = FastIO.ReadNonNegativeInt();
            int bagCount  = FastIO.ReadNonNegativeInt();

            int[,] bags = new int[bagCount, 2];
            for (int b = 0; b < bagCount; ++b)
            {
                bags[b, 0] = FastIO.ReadNonNegativeInt(); // bag weight
                bags[b, 1] = FastIO.ReadNonNegativeInt(); // bag value
            }

            int result = WACHOVIA.Solve(maxWeight, bagCount, bags);
            output.AppendLine($"Hey stupid robber, you can get {result}.");
        }

        Console.Write(output);
    }