-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayRotation.java
More file actions
68 lines (57 loc) · 1.63 KB
/
ArrayRotation.java
File metadata and controls
68 lines (57 loc) · 1.63 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package problems.codechef;
import java.io.BufferedInputStream;
import java.util.ArrayList;
import java.util.Iterator;
public class ArrayRotation {
public static String readInputDemo(){
BufferedInputStream b=new BufferedInputStream(System.in);
StringBuilder s=new StringBuilder();
long val=0;
try {
int c=b.read();
while(c!='\n'){
s.append((char)c);
c=b.read();
}
} catch (Exception e) {
// TODO: handle exception
}
return s.toString();
}
public static void main(String[] args) {
int n,q,t=0,l=0,r=0;
String s[]=readInputDemo().split("\\s");
n=Integer.parseInt(s[0]);
q=Integer.parseInt(s[1]);
n++;
ArrayList<Integer> list=new ArrayList<Integer>(n);
list.add(-1);
String p[]=readInputDemo().split("\\s");
for (int i=0;i<n-1;i++)list.add(Integer.parseInt(p[i]));
System.out.println(list+" "+list.size());
while(q-->0){
ArrayList<Integer> tempList=new ArrayList<Integer>(n);
tempList.add(-1);
String query[]=readInputDemo().split("\\s");
t=Integer.parseInt(query[0]);
l=Integer.parseInt(query[1]);
r=Integer.parseInt(query[2]);
System.out.println(t+" "+l+" "+r);
System.out.println("size : "+list.size());
if (t==1) {
tempList.addAll(list.subList(l, r+1));
tempList.addAll(list.subList(1, l));
tempList.addAll(list.subList(r+1,n));
}
else{
tempList.addAll(list.subList(1,l));
tempList.addAll(list.subList(r+1,n));
tempList.addAll(list.subList(l, r+1));
}
System.out.println(tempList);
list=tempList;
}
Iterator iterator=list.listIterator(1);
while (iterator.hasNext())System.out.print(iterator.next()+" ");
}
}