forked from satnaing/astro-paper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Affected files: .obsidian/workspace.json src/content/blog/boj-19951-태상이의-훈련소-생활.md
- Loading branch information
Showing
2 changed files
with
67 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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/[email protected]", | ||
"dist/assets/forrest-gump-quote.webp.jpg", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 = " ") | ||
``` |