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(); }
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 arrayLength = FastIO.ReadNonNegativeInt(); int[] sourceArray = new int[arrayLength]; for (int i = 0; i < arrayLength; ++i) { sourceArray[i] = FastIO.ReadInt(); } var solver = new GSS1(sourceArray); int queryCount = FastIO.ReadNonNegativeInt(); 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 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(); }