Beispiel #1
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();
    }
Beispiel #2
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();
    }
Beispiel #3
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();
    }
Beispiel #4
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();
    }
Beispiel #5
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();
    }
Beispiel #6
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();
    }
Beispiel #7
0
    private static void Main()
    {
        int remainingTestCases = FastIO.ReadNonNegativeInt();

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

        FastIO.Flush();
    }
Beispiel #8
0
    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();
    }
Beispiel #9
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();
    }
Beispiel #10
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();
    }
Beispiel #11
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();
    }
Beispiel #12
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();
    }
Beispiel #13
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();
    }
Beispiel #14
0
    private static void Main()
    {
        int remainingTestCases = FastIO.ReadNonNegativeInt();

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

            for (int vertexID = 0; vertexID < _vertexCount; ++vertexID)
            {
                _verticesNeighbors[vertexID]   = new List <int>();
                _verticesEdgeWeights[vertexID] = new List <int>();
                _verticesEdges[vertexID]       = new List <int>();
            }

            for (int edgeID = 0; edgeID < _vertexCount - 1; ++edgeID)
            {
                int firstVertexID  = FastIO.ReadNonNegativeInt() - 1;
                int secondVertexID = FastIO.ReadNonNegativeInt() - 1;
                int edgeWeight     = FastIO.ReadNonNegativeInt();

                _verticesNeighbors[firstVertexID].Add(secondVertexID);
                _verticesNeighbors[secondVertexID].Add(firstVertexID);

                _verticesEdgeWeights[firstVertexID].Add(edgeWeight);
                _verticesEdgeWeights[secondVertexID].Add(edgeWeight);

                _verticesEdges[firstVertexID].Add(edgeID);
                _verticesEdges[secondVertexID].Add(edgeID);
            }

            BuildRootedStructure(
                parentVertexID: -1,
                vertexID: 0,
                depth: 0,
                costToRoot: 0);

            BuildAncestorTable();

            char instruction;
            while ((instruction = FastIO.ReadInstruction()) != 'S')
            {
                if (instruction == 'D')
                {
                    FastIO.WriteNonNegativeInt(GetDistanceBetween(
                                                   firstVertexID: FastIO.ReadNonNegativeInt() - 1,
                                                   secondVertexID: FastIO.ReadNonNegativeInt() - 1));
                    FastIO.WriteLine();
                }
                else
                {
                    FastIO.WriteNonNegativeInt(GetKthVertexBetween(
                                                   firstVertexID: FastIO.ReadNonNegativeInt() - 1,
                                                   secondVertexID: FastIO.ReadNonNegativeInt() - 1,
                                                   k: FastIO.ReadNonNegativeInt()) + 1);
                    FastIO.WriteLine();
                }
            }
        }

        FastIO.Flush();
    }
Beispiel #15
0
    private static void Main()
    {
        int remainingTestCases = FastIO.ReadNonNegativeInt();

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

            for (int vertexID = 0; vertexID < _vertexCount; ++vertexID)
            {
                _verticesNeighbors[vertexID]   = new List <int>();
                _verticesEdgeWeights[vertexID] = new List <int>();
                _verticesEdges[vertexID]       = new List <int>();
                // Can't be more chain heads than vertices, so this definitely resets enough.
                _chainsHeadVertices[vertexID] = -1;
            }

            for (int edgeID = 0; edgeID < _vertexCount - 1; ++edgeID)
            {
                int firstVertexID  = FastIO.ReadNonNegativeInt() - 1;
                int secondVertexID = FastIO.ReadNonNegativeInt() - 1;
                int edgeWeight     = FastIO.ReadNonNegativeInt();

                _verticesNeighbors[firstVertexID].Add(secondVertexID);
                _verticesNeighbors[secondVertexID].Add(firstVertexID);

                _verticesEdgeWeights[firstVertexID].Add(edgeWeight);
                _verticesEdgeWeights[secondVertexID].Add(edgeWeight);

                _verticesEdges[firstVertexID].Add(edgeID);
                _verticesEdges[secondVertexID].Add(edgeID);
            }

            BuildRootedStructure(
                parentVertexID: -1,
                vertexID: 0,
                depth: 0);

            _chainIndex     = 0;
            _baseArrayIndex = 0;
            RunHLD(
                parentVertexID: -1,
                vertexID: 0,
                edgeWeight: 0);

            BuildAncestorTable();

            BuildSegmentTree(
                segmentTreeIndex: 0,
                segmentStartIndex: 0,
                segmentEndIndex: _vertexCount - 1);

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

        FastIO.Flush();
    }