From 4d7320aecd75f53874db7f85781236673fbbfecd Mon Sep 17 00:00:00 2001 From: lkhyun <102892446+lkhyun@users.noreply.github.com> Date: Sun, 23 Mar 2025 11:50:41 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[20250323]=20BOJ=20/=20G5=20/=20=EB=B9=97?= =?UTF-8?q?=EB=AC=BC=20/=20=EC=9D=B4=EA=B0=95=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../23 BOJ G5 \353\271\227\353\254\274.md" | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 "lkhyun/202503/23 BOJ G5 \353\271\227\353\254\274.md" diff --git "a/lkhyun/202503/23 BOJ G5 \353\271\227\353\254\274.md" "b/lkhyun/202503/23 BOJ G5 \353\271\227\353\254\274.md" new file mode 100644 index 00000000..663fd4d1 --- /dev/null +++ "b/lkhyun/202503/23 BOJ G5 \353\271\227\353\254\274.md" @@ -0,0 +1,55 @@ +```java +import java.util.*; +import java.io.*; +public class Main { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + static int H = 0; + static int W = 0; + static int[] world; + static int answer = 0; + public static void main(String[] args) throws Exception { + st = new StringTokenizer(br.readLine()); + H = Integer.parseInt(st.nextToken()); + W = Integer.parseInt(st.nextToken()); + world = new int[W]; + + st = new StringTokenizer(br.readLine()); + for(int i=0;i world[k]) { + left = i; + break; + } + } + int right = 0; + for(int i=1;i world[k]) { + right = i; + break; + } + } + if(left!=0 && right!=0){ + if(world[k] Date: Sun, 23 Mar 2025 11:59:45 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[20250323]=20BOJ=20/=20G1=20/=20=EC=9D=8C?= =?UTF-8?q?=EC=A3=BC=EC=BD=94=EB=94=A9=20/=20=EC=9D=B4=EA=B0=95=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...14\354\243\274\354\275\224\353\224\251.md" | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 "lkhyun/202503/23 BOJ G1 \354\235\214\354\243\274\354\275\224\353\224\251.md" diff --git "a/lkhyun/202503/23 BOJ G1 \354\235\214\354\243\274\354\275\224\353\224\251.md" "b/lkhyun/202503/23 BOJ G1 \354\235\214\354\243\274\354\275\224\353\224\251.md" new file mode 100644 index 00000000..ebc4daf6 --- /dev/null +++ "b/lkhyun/202503/23 BOJ G1 \354\235\214\354\243\274\354\275\224\353\224\251.md" @@ -0,0 +1,84 @@ +```java +import java.util.*; +import java.io.*; +public class Main { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + static int N = 0; + static int K = 0; + static int[] arr; + static int[] tree; + public static void main(String[] args) throws Exception { + st = new StringTokenizer(br.readLine()); + while(st.hasMoreTokens()){ + N = Integer.parseInt(st.nextToken()); + K = Integer.parseInt(st.nextToken()); + arr = new int[N+1]; + tree = new int[4*N]; + + st = new StringTokenizer(br.readLine()); + for(int i=1;i<=N;i++){ + arr[i] = Integer.parseInt(st.nextToken()); + } + init(1,1,N); + for(int i=1;i<=K;i++){ + st = new StringTokenizer(br.readLine()); + String cmd = st.nextToken(); + if(cmd.equals("C")){//변경 + int idx = Integer.parseInt(st.nextToken()); + int newValue = Integer.parseInt(st.nextToken()); + + if(newValue>0) update(1,1,N,idx,1); + else if(newValue<0) update(1,1,N,idx,-1); + else update(1,1,N,idx,0); + + }else if(cmd.equals("P")){//곱셈 + int left = Integer.parseInt(st.nextToken()); + int right = Integer.parseInt(st.nextToken()); + int result = multiplication(1,1,N,left,right); + if(result>0) bw.write("+"); + else if(result<0) bw.write("-"); + else bw.write("0"); + } + } + bw.write("\n"); + + String nextcmd = br.readLine(); + if(nextcmd == null) break; + else st = new StringTokenizer(nextcmd); + } + bw.close(); + } + public static void init(int cur, int start, int end){ + if(start==end){ + if(arr[start]>0) tree[cur] = 1; + else if(arr[start]<0) tree[cur] = -1; + else tree[cur] = 0; + }else{ + init(cur*2,start,(start+end)/2); + init(cur*2 + 1, (start+end)/2 + 1,end); + tree[cur] = tree[cur*2] * tree[cur*2 + 1]; + } + } + public static void update(int cur, int start, int end, int idx, int newValue){ + if(idxend) return; + if(start == end) { + tree[cur] = newValue; + return; + } + update(cur * 2, start, (start + end) / 2, idx, newValue); + update(cur * 2 + 1, (start + end) / 2 + 1, end, idx, newValue); + tree[cur] = tree[cur*2] * tree[cur*2 + 1]; + } + public static int multiplication(int cur, int start, int end, int left, int right){ + if(rightend) return 1; + if(left<=start && right>=end) return tree[cur]; + + int l = multiplication(cur*2,start,(start+end)/2,left,right); + int r = multiplication(cur*2 + 1, (start+end)/2 + 1,end,left,right); + return l*r; + } +} + +```