-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculateMin.java
More file actions
48 lines (39 loc) · 990 Bytes
/
CalculateMin.java
File metadata and controls
48 lines (39 loc) · 990 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import java.util.Scanner;
import java.io.*;
import java.lang.String;
import java.lang.Integer;
class CalculateMin {
int[] array;
public static void main(String[] args) {
CalculateMin tree = new CalculateMin();
Scanner in = new Scanner(new InputStreamReader(System.in));
int n = in.nextInt();
int m = in.nextInt();
tree.array = new int[n+1];
for(int i = 1; i <= n; i++){
tree.array[i] = in.nextInt();
}
//Execute commands
String command;
for(int i = 0; i < m; i++){
command = in.next();
if(command.equals("Min")) {
System.out.println(tree.Min(in.nextInt(), in.nextInt()));
}
else tree.Set(in.nextInt(), in.nextInt());
}
}
public int Min(int left, int right){
if(left == right)
return this.array[left];
int minimum = this.array[left];
for(int i = left; i <= right; i++){
if(this.array[i] < minimum)
minimum = this.array[i];
}
return minimum;
}
public void Set(int index, int value){
this.array[index] = value;
}
}