diff --git "a/JHLEE325/202508/26 BOJ G1 \354\265\234\354\206\237\352\260\222\352\263\274 \354\265\234\353\214\223\352\260\222.md" "b/JHLEE325/202508/26 BOJ G1 \354\265\234\354\206\237\352\260\222\352\263\274 \354\265\234\353\214\223\352\260\222.md" new file mode 100644 index 00000000..d01c04b8 --- /dev/null +++ "b/JHLEE325/202508/26 BOJ G1 \354\265\234\354\206\237\352\260\222\352\263\274 \354\265\234\353\214\223\352\260\222.md" @@ -0,0 +1,95 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + StringBuilder sb = new StringBuilder(); + + int n = Integer.parseInt(st.nextToken()); + int m = Integer.parseInt(st.nextToken()); + int[] arr = new int[n]; + for(int i=0;i end || right < start) { + return -1; + } + if (left <= start && end <= right) { + return tree[node]; + } + int lmin = query(tree, node*2, start, (start+end)/2, left, right); + int rmin = query(tree, node*2+1, (start+end)/2+1, end, left, right); + if (lmin == -1) { + return rmin; + } else if (rmin == -1) { + return lmin; + } else { + return Math.min(lmin, rmin); + } + } + + static void initmax(int[] arr, int[] tree, int node, int start, int end) { + if (start == end) { + tree[node] = arr[start]; + } else { + initmax(arr, tree, node * 2, start, (start + end) / 2); + initmax(arr, tree, node * 2 + 1, (start + end) / 2 + 1, end); + tree[node] = Math.max(tree[node * 2], tree[node * 2 + 1]); + } + } + + static int querymax(int[] tree, int node, int start, int end, int left, int right) { + if (left > end || right < start) { + return -1; + } + if (left <= start && end <= right) { + return tree[node]; + } + int lmax = querymax(tree, node*2, start, (start+end)/2, left, right); + int rmax = querymax(tree, node*2+1, (start+end)/2+1, end, left, right); + if (lmax == -1) { + return rmax; + } else if (rmax == -1) { + return lmax; + } else { + return Math.max(lmax, rmax); + } + } +} + +```