• + 0 comments

    def dynamicArray(n, queries): # Initialize the array of n empty lists arr = [[] for _ in range(n)] # Initialize lastAnswer to 0 lastAnswer = 0 # List to store the results of type 2 queries result = []

    # Iterate through each query
    for query in queries:
        # Split the query into components
        q, x, y = map(int, query.split())
    
        # Determine the index using the given formula
        idx = (x ^ lastAnswer) % n
    
        if q == 1:
            # Append y to arr[idx]
            arr[idx].append(y)
        elif q == 2:
            # Find the element at position y % size(arr[idx]) in arr[idx]
            value = arr[idx][y % len(arr[idx])]
            # Assign this value to lastAnswer
            lastAnswer = value
            # Append the result to the result list
            result.append(lastAnswer)
    
    return result
    

    Read the input values

    first_line = input().strip().split() n = int(first_line[0]) q = int(first_line[1]) queries = [input().strip() for _ in range(q)]

    Call the function and get the result

    output = dynamicArray(n, queries)

    Print the results of type 2 queries

    for res in output: print(res)