-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdynamic array.java
More file actions
26 lines (24 loc) · 842 Bytes
/
dynamic array.java
File metadata and controls
26 lines (24 loc) · 842 Bytes
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
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
ArrayList<ArrayList<Integer>> lists = new ArrayList<ArrayList<Integer>>(n);
for (int i = 0; i < n; i++) {
lists.add(new ArrayList<Integer>());
}
int q = sc.nextInt();
int lastans = 0;
for (int i = 0; i < q; i++) {
if (sc.nextInt() == 1) {
lists.get((sc.nextInt() ^ lastans) % n).add(sc.nextInt());
}
else {
ArrayList<Integer> l = lists.get((sc.nextInt() ^ lastans) % n);
lastans = l.get(sc.nextInt() % l.size());
System.out.println(lastans);
}
}
}
}