Skip to content

Commit

Permalink
2024-07-20 00:58:40
Browse files Browse the repository at this point in the history
Affected files:
.obsidian/workspace.json
src/content/blog/boj-19951-태상이의-훈련소-생활.md
  • Loading branch information
gyunseo committed Jul 19, 2024
1 parent 673a6dd commit fdb8f19
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 11 deletions.
22 changes: 11 additions & 11 deletions .obsidian/workspace.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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",
Expand All @@ -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
}
Expand All @@ -143,7 +143,7 @@
"state": {
"type": "outline",
"state": {
"file": "src/content/blog/boj-2564-경비원.md"
"file": "src/content/blog/boj-19951-태상이의-훈련소-생활.md"
}
}
}
Expand All @@ -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",
Expand All @@ -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",
Expand Down
56 changes: 56 additions & 0 deletions src/content/blog/boj-19951-태상이의-훈련소-생활.md
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 = " ")
```

0 comments on commit fdb8f19

Please sign in to comment.