From b05372b1e02bbbda00d9a57aa27afb3b1e011558 Mon Sep 17 00:00:00 2001 From: JHLEE325 <82587652+JHLEE325@users.noreply.github.com> Date: Tue, 26 Aug 2025 13:44:38 +0900 Subject: [PATCH] =?UTF-8?q?[20250826]=20BOJ=20/=20G1=20/=20=EC=B5=9C?= =?UTF-8?q?=EC=86=9F=EA=B0=92=EA=B3=BC=20=EC=B5=9C=EB=8C=93=EA=B0=92=20/?= =?UTF-8?q?=20=EC=9D=B4=EC=A4=80=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4 \354\265\234\353\214\223\352\260\222.md" | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 "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" 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); + } + } +} + +```