From d380629abb658b9f007f329f5d47bd23f64b78b9 Mon Sep 17 00:00:00 2001 From: lkhyun <102892446+lkhyun@users.noreply.github.com> Date: Wed, 19 Mar 2025 17:15:01 +0900 Subject: [PATCH] =?UTF-8?q?[20250319]=20BOJ=20/=20=EA=B3=A8=EB=93=9C1=20/?= =?UTF-8?q?=20=EC=B5=9C=EC=86=9F=EA=B0=92=20/=20=EC=9D=B4=EA=B0=95?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...1 \354\265\234\354\206\237\352\260\222.md" | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 "lkhyun/202503/19 BOJ \352\263\250\353\223\2341 \354\265\234\354\206\237\352\260\222.md" diff --git "a/lkhyun/202503/19 BOJ \352\263\250\353\223\2341 \354\265\234\354\206\237\352\260\222.md" "b/lkhyun/202503/19 BOJ \352\263\250\353\223\2341 \354\265\234\354\206\237\352\260\222.md" new file mode 100644 index 00000000..a42e65a3 --- /dev/null +++ "b/lkhyun/202503/19 BOJ \352\263\250\353\223\2341 \354\265\234\354\206\237\352\260\222.md" @@ -0,0 +1,62 @@ +```java +import java.util.*; +import java.io.*; + +class Node{ + long min; + long max; + Node(long min,long max){ + this.min = min; + this.max = max; + } +} +public class Main { + static int N; + static int M; + static long[] arr; + static Node[] tree; + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + StringTokenizer st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + arr = new long[N*4]; + tree = new Node[N*4]; + + for(int i=1;i<=N;i++){ + arr[i] = Long.parseLong(br.readLine()); + } + init(1,1,N); + for(int i=0;iend || right=end) return tree[cur]; + + Node l = query(cur*2,start,(start+end)/2,left,right); + Node r = query(cur*2+1,(start+end)/2 + 1, end,left,right); + if(l==null)return r; + else if(r==null) return l; + else return new Node(Math.min(l.min,r.min),Math.max(l.max,r.max)); + } +} +```