-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution2.java
More file actions
52 lines (46 loc) · 1.49 KB
/
Solution2.java
File metadata and controls
52 lines (46 loc) · 1.49 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution2 {
public static void main(String[] args) {
try {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner in = new Scanner(new File("input06.txt"));
// Create a list, seqList, of N empty sequences, where each sequence is indexed from 0
// to N -1. The elements within each of the sequences also use 0-indexing.
int N = in.nextInt();
int Q = in.nextInt(); // Number of Queries
//List []seqList = new List[99999];
List<List<Integer>> seqList = new ArrayList<List<Integer>>();
for (int i = 0; i < N; i++) {
seqList.add(new ArrayList<Integer>());
}
// Create an integer, lastAnswer, and initialize it to 0
int lastAnswer = 0;
int x = 0;
int y = 0;
int seqIndex = 0;
for (int i = 0; i < Q; i++) {
int queryType = in.nextInt();
x = in.nextInt();
y = in.nextInt();
seqIndex = seqIndex = (x^lastAnswer)%N;
switch (queryType) {
case 1:
List<Integer> seqElement = seqList.get(seqIndex);
seqElement.add(Integer.valueOf(y));
break;
case 2:
int element = y%(seqList.get(seqIndex).size());
lastAnswer = seqList.get(seqIndex).get(element);
System.out.println(lastAnswer);
break;
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}