diff --git a/.obsidian/workspace.json b/.obsidian/workspace.json index d655f1f5f..5e6516e87 100644 --- a/.obsidian/workspace.json +++ b/.obsidian/workspace.json @@ -4,16 +4,16 @@ "type": "split", "children": [ { - "id": "2676f6981de71d52", + "id": "5618ed33c29b957d", "type": "tabs", "children": [ { - "id": "a33d3c979b188989", + "id": "72d69f1c38fd96fe", "type": "leaf", "state": { "type": "markdown", "state": { - "file": "src/content/blog/boj-15661-링크와-스타트.md", + "file": "src/content/blog/boj-2564-경비원.md", "mode": "source", "source": false } @@ -22,16 +22,16 @@ ] }, { - "id": "5618ed33c29b957d", + "id": "d569986bbfee2eb7", "type": "tabs", "children": [ { - "id": "72d69f1c38fd96fe", + "id": "a9e50a64c182f8d4", "type": "leaf", "state": { "type": "markdown", "state": { - "file": "src/content/blog/boj-2564-경비원.md", + "file": "src/content/blog/boj-19951-태상이의-훈련소-생활.md", "mode": "source", "source": false } @@ -103,7 +103,7 @@ "state": { "type": "backlink", "state": { - "file": "src/content/blog/boj-2564-경비원.md", + "file": "src/content/blog/boj-19951-태상이의-훈련소-생활.md", "collapseAll": false, "extraContext": false, "sortOrder": "alphabetical", @@ -120,7 +120,7 @@ "state": { "type": "outgoing-link", "state": { - "file": "src/content/blog/boj-2564-경비원.md", + "file": "src/content/blog/boj-19951-태상이의-훈련소-생활.md", "linksCollapsed": false, "unlinkedCollapsed": true } @@ -143,7 +143,7 @@ "state": { "type": "outline", "state": { - "file": "src/content/blog/boj-2564-경비원.md" + "file": "src/content/blog/boj-19951-태상이의-훈련소-생활.md" } } } @@ -166,9 +166,10 @@ "table-editor-obsidian:Advanced Tables Toolbar": false } }, - "active": "72d69f1c38fd96fe", + "active": "a9e50a64c182f8d4", "lastOpenFiles": [ "src/content/blog/boj-2564-경비원.md", + "src/content/blog/boj-19951-태상이의-훈련소-생활.md", "src/content/blog/boj-15661-링크와-스타트.md", "src/content/blog/boj-2529-부등호.md", "src/content/blog/leet-code-919-complete-binary tree-inserter.md", @@ -194,7 +195,6 @@ "src/content/blog/boj-11057-.md", "src/content/blog/boj-1940-주몽.md", "src/content/blog/install-neovim-using-aqua-on-ubuntu.md", - "src/content/blog/how-to-connect-wifi-on-ubuntu-server.md", "dist/posts/aqua를-이용해-wsl-ubuntu에-neovim을-설치하자.png", "dist/assets/forrest-gump-quote@900w.jpeg", "dist/assets/forrest-gump-quote.webp.jpg", diff --git "a/src/content/blog/boj-19951-\355\203\234\354\203\201\354\235\264\354\235\230-\355\233\210\353\240\250\354\206\214-\354\203\235\355\231\234.md" "b/src/content/blog/boj-19951-\355\203\234\354\203\201\354\235\264\354\235\230-\355\233\210\353\240\250\354\206\214-\354\203\235\355\231\234.md" new file mode 100644 index 000000000..166436b59 --- /dev/null +++ "b/src/content/blog/boj-19951-\355\203\234\354\203\201\354\235\264\354\235\230-\355\233\210\353\240\250\354\206\214-\354\203\235\355\231\234.md" @@ -0,0 +1,56 @@ +--- +author: Gyunseo Lee +title: "BOJ 백준 19951: 태상이의 훈련소 생활" +pubDatetime: 2024-07-20T00:55:00+09:00 +modDatetime: 2024-07-20T00:55:00+09:00 +featured: false +draft: false +tags: + - PS + - BOJ + - Algorithms + - 실랜디 + - 골랜디 + - PrefixSum +description: 시간 복잡도를 보면서 어떤 알고리즘을 쓸지 잘 생각해 보자 +ogImage: "" +--- + +## Table of contents + +## 들어가며 + +걸린 시간: 1시간 (자력으로 풀지 못함) + +문제를 읽고, N이 최대 10만이길래, query를 최적화하면 되겠거니 했습니다. + +## 접근 + +![](https://res.cloudinary.com/gyunseo-blog/image/upload/f_auto/v1721404675/image_diwxzn.png) + +근데 query에서의 시간 복잡도를 도저히 최적화를 하지 못하겠어서, 풀지 못했습니다. +태그를 까보니 누적합이었고, 사실 누적합인 걸 봐도 못 풀겠어서 인터넷에서 솔루션을 보고 이해를 했습니다. + +## 구현 + +```python +import sys + +input = sys.stdin.readline +from bisect import bisect_left, bisect_right +if __name__ == "__main__": + N, M = map(int, input().strip().split()) + HList = [0] + [*map(int, input().strip().split())] + prefixSumList = [0 for _ in range(N + 1 + 1)] + + for _ in range(M): + a, b, k = map(int, input().strip().split()) + prefixSumList[a] += k + prefixSumList[b + 1] += -k + + for i in range(1, N + 1): + prefixSumList[i + 1] += prefixSumList[i] + + for i in range(1, N + 1): + print(HList[i] + prefixSumList[i], end = " ") +```