From 033c83689bd747a833dc909c078e0f330cfe14a6 Mon Sep 17 00:00:00 2001 From: oncsr Date: Sat, 9 Aug 2025 23:43:00 +0900 Subject: [PATCH] =?UTF-8?q?[20250809]=20BOJ=20/=20P4=20/=20=EB=8B=A4?= =?UTF-8?q?=EC=98=A4=EC=9D=98=20=ED=96=89=EC=82=AC=20=EA=B3=84=ED=9A=8D?= =?UTF-8?q?=ED=95=98=EA=B8=B0=20/=20=EA=B6=8C=ED=98=81=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...04\355\232\215\355\225\230\352\270\260.md" | 157 ++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 "khj20006/202508/09 BOJ P4 \353\213\244\354\230\244\354\235\230 \355\226\211\354\202\254 \352\263\204\355\232\215\355\225\230\352\270\260.md" diff --git "a/khj20006/202508/09 BOJ P4 \353\213\244\354\230\244\354\235\230 \355\226\211\354\202\254 \352\263\204\355\232\215\355\225\230\352\270\260.md" "b/khj20006/202508/09 BOJ P4 \353\213\244\354\230\244\354\235\230 \355\226\211\354\202\254 \352\263\204\355\232\215\355\225\230\352\270\260.md" new file mode 100644 index 00000000..de4d0f60 --- /dev/null +++ "b/khj20006/202508/09 BOJ P4 \353\213\244\354\230\244\354\235\230 \355\226\211\354\202\254 \352\263\204\355\232\215\355\225\230\352\270\260.md" @@ -0,0 +1,157 @@ +```java +import java.util.*; +import java.io.*; + +class IOController { + BufferedReader br; + BufferedWriter bw; + StringTokenizer st; + + public IOController() { + br = new BufferedReader(new InputStreamReader(System.in)); + bw = new BufferedWriter(new OutputStreamWriter(System.out)); + st = new StringTokenizer(""); + } + + String nextLine() throws Exception { + String line = br.readLine(); + st = new StringTokenizer(line); + return line; + } + + String nextToken() throws Exception { + while (!st.hasMoreTokens()) nextLine(); + return st.nextToken(); + } + + int nextInt() throws Exception { + return Integer.parseInt(nextToken()); + } + + long nextLong() throws Exception { + return Long.parseLong(nextToken()); + } + + double nextDouble() throws Exception { + return Double.parseDouble(nextToken()); + } + + void close() throws Exception { + bw.flush(); + bw.close(); + } + + void write(String content) throws Exception { + bw.write(content); + } + +} + +public class Main { + + static IOController io; + + // + + static int N, M, T; + static int[][] row, col; + static List[] graph; + static int[][] par; + static int[] dep; + static long[] arr; + + public static void main(String[] args) throws Exception { + + io = new IOController(); + + init(); + solve(); + + io.close(); + + } + + static void init() throws Exception { + + N = io.nextInt(); + M = io.nextInt(); + T = io.nextInt(); + row = new int[N][M]; + col = new int[N][M]; + for(int i=0;i(); + par = new int[N*M+1][17]; + dep = new int[N*M]; + arr = new long[T+2]; + + } + + static void solve() throws Exception { + + for(int i=0;i0;) { + int s = io.nextInt(); + int e = io.nextInt(); + int a = io.nextInt(); + int b = io.nextInt(); + int c = io.nextInt(); + int d = io.nextInt(); + int v = io.nextInt(); + + int x = a*M+b, y = c*M+d; + + int dist = 1, diff = Math.abs(dep[x]-dep[y]); + for(int k=0;k<17;k++) if((diff & (1< dep[y]) { + dist += (1<=0;k--) if(par[x][k] != par[y][k]) { + dist += (1<<(k+1)); + x = par[x][k]; + y = par[y][k]; + } + if(x != y) dist += 2; + + arr[s] += v*dist; + arr[e+1] -= v*dist; + + } + + long s = 0; + for(int i=1;i<=T;i++) { + s += arr[i]; + io.write(s + "\n"); + } + + } + + static void dfs(int n, int p, int d) { + dep[n] = d; + par[n][0] = p; + for(int i:graph[n]) if(i != p) dfs(i,n,d+1); + } + +} +```