From dd981363686c7a949548e264bedeff7b0e8195ec Mon Sep 17 00:00:00 2001 From: Jonghwan Lee <123362165+0224LJH@users.noreply.github.com> Date: Sat, 2 Aug 2025 21:17:44 +0900 Subject: [PATCH 1/3] Add files via upload --- 0224LJH/202508/2 BOJ XOR.md | 175 +++++++++++++++++++++++++++++++++++ 1 file changed, 175 insertions(+) create mode 100644 0224LJH/202508/2 BOJ XOR.md diff --git a/0224LJH/202508/2 BOJ XOR.md b/0224LJH/202508/2 BOJ XOR.md new file mode 100644 index 00000000..f85d4f07 --- /dev/null +++ b/0224LJH/202508/2 BOJ XOR.md @@ -0,0 +1,175 @@ +```java +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + + +public class Main { + + static final int UPDATE = 1; + static final int QUERY = 2; + static int size, changeCnt, sumCnt,queryCnt; + static long[] input; + static StringBuilder sb = new StringBuilder(); + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + static class SegmentTree{ + private long[] lazy; //레이지 프로파게이션 + public long[] tree; + private int size; // 원본 배열의 크기 + + public SegmentTree(long[] arr){ + size = arr.length; + this.lazy = new long[size*4]; + this.tree = new long[size*4]; + build(arr,1,0,size-1); + } + + private void build(long[] arr, int node, int startIdx, int endIdx){ + if(startIdx == endIdx){ + tree[node] = arr[startIdx]; + return; + } + + int mid = (startIdx + endIdx)/2; + build(arr,node*2,startIdx,mid); + build(arr,node*2+1,mid+1,endIdx); + tree[node] = tree[node*2]^tree[node*2+1]; + } + + public void updateRange(int startIdx , int endIdx, long k ){ + updateRange(1, 0, size-1, startIdx, endIdx, k); + } + + private void updateRange(int node,int left,int right, int startIdx , int endIdx, long k){ + updateLazy(node, left, right); + + if ( left > endIdx || right < startIdx) return; //현 구간과 업데이트 구간이 아예 안겹칩 + + if (left >= startIdx && right <= endIdx){ // 완전히 포함되는 경우 + // XOR의 특성: 구간 길이가 홀수일 때만 실제로 값이 변함 + int rangeLength = right - left + 1; + if (rangeLength % 2 == 1) { + tree[node] ^= k; + } + + // 리프 노드가 아니라면 lazy 전파 + if (left != right) { + lazy[2*node] ^= k; + lazy[2*node+1] ^= k; + } + return; + } + + int mid = (left+right)/2; + + updateRange(node*2, left, mid, startIdx, endIdx, k); + updateRange(node*2+1, mid+1, right, startIdx, endIdx, k); + + updateLazy(node*2, left, mid); + updateLazy(node*2+1, mid+1,right); + tree[node] = tree[node*2]^tree[node*2+1]; + } + + private void updateLazy(int node, int left, int right){ + if (lazy[node] == 0) return; + + long k = lazy[node]; + // XOR의 특성: 구간 길이가 홀수일 때만 실제로 값이 변함 + int rangeLength = right - left + 1; + if (rangeLength % 2 == 1) { + tree[node] ^= k; + } + + if (left != right){ + lazy[node*2] ^= k; + lazy[node*2+1] ^= k; + } + lazy[node] = 0; + } + + public long query(int startIdx, int endIdx){ + return query(1,0, size-1, startIdx, endIdx); + } + + private long query(int node , int left, int right, int startIdx , int endIdx){ + updateLazy(node, left, right); + if ( left > endIdx || right < startIdx) return 0; + if (left >= startIdx && right <= endIdx) return tree[node]; + + int mid = (left+right)/2; + return query(node*2, left, mid, startIdx, endIdx)^query(node*2+1, mid+1, right, startIdx, endIdx); + } + } + + + + public static void main(String[] args) throws IOException { + init(); + process(); + print(); + } + + private static void init() throws IOException { + size = Integer.parseInt(br.readLine()); + input = new long[size]; + + + StringTokenizer st = new StringTokenizer(br.readLine()); + for (int i = 0; i < size; i++) { + input[i] = Long.parseLong(st.nextToken()); + } + + queryCnt = Integer.parseInt(br.readLine()); + + } + + private static void process() throws IOException { + + SegmentTree tree = new SegmentTree(input); + + for (int i = 0; i < queryCnt; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + int order = Integer.parseInt(st.nextToken()); + int start = Integer.parseInt(st.nextToken()); + int end = Integer.parseInt(st.nextToken()); + + + if (order == UPDATE) { + long plus = Long.parseLong(st.nextToken()); + tree.updateRange(start, end, plus); + } else sb.append(tree.query(start, end)).append("\n"); + + + int power = 2; + for (int j = 1; j < tree.tree.length; j++) { + if (j == power) { + System.out.println(); + power *= 2; + } + System.out.print(tree.tree[j] +" "); + } + System.out.println(); + + + power = 2; + for (int j = 1; j < tree.tree.length; j++) { + if (j == power) { + System.out.println(); + power *= 2; + } + System.out.print(tree.lazy[j] +" "); + } + System.out.println(); + } + + } + + + private static void print() { + System.out.println(sb.toString()); + + } +} +``` \ No newline at end of file From 85d19ab47e255917caea7e199b641021b8b32144 Mon Sep 17 00:00:00 2001 From: Jonghwan Lee <123362165+0224LJH@users.noreply.github.com> Date: Sat, 2 Aug 2025 21:18:22 +0900 Subject: [PATCH 2/3] =?UTF-8?q?[20250802]=20BOJ=20/=20P3=20/=20XOR=20/=20?= =?UTF-8?q?=EC=9D=B4=EC=A2=85=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 0224LJH/202508/2 BOJ XOR.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/0224LJH/202508/2 BOJ XOR.md b/0224LJH/202508/2 BOJ XOR.md index f85d4f07..017cafce 100644 --- a/0224LJH/202508/2 BOJ XOR.md +++ b/0224LJH/202508/2 BOJ XOR.md @@ -172,4 +172,4 @@ public class Main { } } -``` \ No newline at end of file +``` From 5650e5b23ce85224cd507b32fda9f8d3a0b68ffb Mon Sep 17 00:00:00 2001 From: Jonghwan Lee <123362165+0224LJH@users.noreply.github.com> Date: Sun, 3 Aug 2025 13:27:43 +0900 Subject: [PATCH 3/3] =?UTF-8?q?[20250803]=20BOJ=20/=20G4=20/=20=EC=97=AC?= =?UTF-8?q?=ED=96=89=20=EA=B0=80=EC=9E=90=20/=20=EC=9D=B4=EC=A2=85?= =?UTF-8?q?=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\355\226\211 \352\260\200\354\236\220.md" | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 "0224LJH/202508/3 BOJ \354\227\254\355\226\211 \352\260\200\354\236\220.md" diff --git "a/0224LJH/202508/3 BOJ \354\227\254\355\226\211 \352\260\200\354\236\220.md" "b/0224LJH/202508/3 BOJ \354\227\254\355\226\211 \352\260\200\354\236\220.md" new file mode 100644 index 00000000..5b956aac --- /dev/null +++ "b/0224LJH/202508/3 BOJ \354\227\254\355\226\211 \352\260\200\354\236\220.md" @@ -0,0 +1,95 @@ +```java + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + + +public class Main { + + + static StringBuilder sb = new StringBuilder(); + static int cityCnt,planCityCnt; + static int[][] arr; + static int[] plan,parent; + + + public static void main(String[] args) throws IOException { + init(); + process(); + print(); + } + + private static void init() throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + cityCnt = Integer.parseInt(br.readLine()); + planCityCnt = Integer.parseInt(br.readLine()); + arr = new int[cityCnt][cityCnt]; + parent = new int[cityCnt]; + for (int i = 0; i < cityCnt; i++) { + parent[i] = i; + } + plan = new int[planCityCnt]; + + for (int i = 0; i < cityCnt; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + for (int j = 0; j < cityCnt; j++) { + arr[i][j] = Integer.parseInt(st.nextToken()); + } + } + + StringTokenizer st = new StringTokenizer(br.readLine()); + for (int i = 0; i < planCityCnt; i++) { + plan[i] = Integer.parseInt(st.nextToken())-1; + } + + } + + private static void process() throws IOException { + for (int i = 0; i < cityCnt; i++) { + for (int j = 0; j < cityCnt; j++) { + if (arr[i][j] == 1) union(i,j); + } + } + + for (int i = 1; i < planCityCnt; i++) { + int preRoot = find(plan[i-1]); + int curRoot = find(plan[i]); + if (preRoot != curRoot) { + System.out.println("NO"); + return; + } + } + + System.out.println("YES"); + + } + + private static void union(int a, int b) { + int aRoot = find(a); + int bRoot = find(b); + + if (aRoot == bRoot) return; + + if (aRoot > bRoot) { + parent[bRoot] = aRoot; + } else { + parent[aRoot] = bRoot; + } + + } + + private static int find(int x) { + if (x == parent[x]) return x; + + return parent[x] = find(parent[x]); + } + + + + private static void print() { + System.out.print(sb.toString()); + } +} +``` \ No newline at end of file