-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathSolution.java
More file actions
38 lines (34 loc) · 1.27 KB
/
Solution.java
File metadata and controls
38 lines (34 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package Practice.DataStructures.Arrays.DynamicArray;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int numberOfSequences = sc.nextInt();
int numberOfQueries = sc.nextInt();
int lastAnswer = 0;
List<List<Integer>> sequences = new ArrayList<>();
for (int i = 0; i < numberOfSequences; i++) {
sequences.add(new ArrayList<>());
}
for (int i = 0; i < numberOfQueries; i++) {
int queryType = sc.nextInt();
int x = sc.nextInt();
int y = sc.nextInt();
int sequenceIndex = (x ^ lastAnswer) % numberOfSequences;
switch (queryType) {
case 1:
// Index of sequence to append y to.
sequences.get(sequenceIndex).add(y);
break;
case 2:
List<Integer> sequence = sequences.get(sequenceIndex);
int elementIndex = y % sequence.size();
lastAnswer = sequence.get(elementIndex);
System.out.println(lastAnswer);
break;
}
}
}
}