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); + } + +} +```