Created
October 23, 2016 01:04
-
-
Save SahilKadam/17474350e561812438efe8eee3a25294 to your computer and use it in GitHub Desktop.
Create a list, , of empty sequences, where each sequence is indexed from to . The elements within each of the sequences also use -indexing. Create an integer, , and initialize it to . The types of queries that can be performed on your list of sequences () are described below: Query: Find the sequence, , at index in . Append integer to sequence .…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
first_line = [int(item) for item in input().strip().split(" ")] | |
N = first_line[0] | |
seqList = [[] for i in range(N)] | |
lastAns = 0 | |
def query1(x,y): | |
global N, seqList, lastAns | |
seqList[(x^lastAns) % N].append(y) | |
def query2(x,y): | |
global N, seqList, lastAns | |
if len(seqList[(x^lastAns) % N]) != 0: | |
temp = y%len(seqList[(x^lastAns) % N]) | |
lastAns = seqList[(x^lastAns) % N][temp] | |
else: | |
temp = y | |
lastAns = seqList[(x^lastAns) % N][temp] | |
print (lastAns) | |
queries = [input().strip().split(" ") for i in range(first_line[1])] | |
[query1(int(queries[i][1]), int(queries[i][2])) if int(queries[i][0]) == 1 else query2(int(queries[i][1]), int(queries[i][2])) for i in range(len(queries))] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment