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(); }
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(); }
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(); }
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(); }
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(); }
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(); }
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(); }
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(); }
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(); }
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(); }
private static void Main() { int remainingTestCases = FastIO.ReadNonNegativeInt(); while (remainingTestCases-- > 0) { FastIO.WriteNonNegativeInt( COMDIV.Solve(FastIO.ReadNonNegativeInt(), FastIO.ReadNonNegativeInt())); FastIO.WriteLine(); } FastIO.Flush(); }
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(); }
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(); }
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(); }
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(); }
private static void Main() { int remainingTestCases = FastIO.ReadNonNegativeInt(); while (remainingTestCases-- > 0) { int studentCount = FastIO.ReadNonNegativeInt(); bool[,] studentPreferences = new bool[studentCount, studentCount]; for (int s = 0; s < studentCount; ++s) { for (int t = 0; t < studentCount; ++t) { studentPreferences[s, t] = FastIO.ReadNonNegativeInt() == 1; } } FastIO.WriteNonNegativeLong( ASSIGN.Solve(studentCount, studentPreferences)); FastIO.WriteLine(); } FastIO.Flush(); }
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(); }
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(); }