์๊ฐ ์ ํ | ๋ฉ๋ชจ๋ฆฌ ์ ํ | ์ ๋ต ๋น์จ |
2 ์ด | 256 MB | 23.830 % |
๋ฌธ์
ํด๊ฒฐ
key point, ์ธ๊ทธ๋จผํธ ํธ๋ฆฌ
2021/02/15 - [๐ฅ PS(Problem Solving) ๐ฅ/BOJ] - [BOJ] #10868 ์ต์๊ฐ
2021/02/15 - [๐ฅ PS(Problem Solving) ๐ฅ/BOJ] - [BOJ] #11505 ๊ตฌ๊ฐ ๊ณฑ ๊ตฌํ๊ธฐ
- ์์ ๋ ๋ฌธ์ ์ ๋ฐฉ์์ ๋์ผํ์ง๋ง ์ด ๋ฌธ์ ๋ ๊ตฌ๊ฐ์ ํฉ์ ๊ตฌํ๋ ๋ฌธ์ ์ด๋ค.
- ๋ฐ๋ผ์ ๊ตฌ๊ฐ ๊ณฑ ๊ตฌํ๊ธฐ ๋ฌธ์ ์ ์ข ๋ ์ ์ฌํ๋ฉฐ
- ์ ๋ ฅ์ผ๋ก ์ฃผ์ด์ง๋ ๋ชจ๋ ์๊ฐ long long ๋ฒ์์ด๊ธฐ ๋๋ฌธ์ ์ ๋ถ long long ์ฒ๋ฆฌ๋ฅผ ํด์ผ๋ง '๋ง์์ต๋๋ค.'๋ฅผ ๋ฐ์ ์ ์์๋ค.
์ฝ๋
๋ฉ๋ชจ๋ฆฌ | ์๊ฐ |
17616 KB | 268 ms |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long int ll;
int n, m, k, h = 1;
vector<ll> seg;
void update(ll i, ll num) {
i += h - 1;
seg[i] = num;
while (i > 1) {
i /= 2;
seg[i] = seg[i * 2] + seg[i * 2 + 1];
}
}
// l, r ์ฐพ๋ ๋ฒ์, num ํ์ฌ ๋
ธ๋ ๋ฒํธ, nl, nr ํ์ฌ ๋ฒ์
ll query(ll l, ll r, ll num, ll nl, ll nr) {
if (l <= nl && nr <= r) return seg[num];
if (nl > r || nr < l) return 0;
int mid = (nl + nr) / 2;
return query(l, r, num * 2, nl, mid) + query(l, r, num * 2 + 1, mid + 1, nr);
}
int main() {
scanf("%d%d%d", &n, &m, &k);
while (h < n) h <<= 1;
seg.resize(h * 2);
ll a, b, c;
for (int i = 0; i < n; i++) {
scanf("%lld", &a);
update(i + 1, a);
}
for (int i = 0; i < m + k; i++) {
scanf("%lld%lld%lld", &a, &b, &c);
if (a == 1) update(b, c);
else printf("%lld\n", query(b, c, 1, 1, h));
}
return 0;
}
|
cs |
'๐ฅ PS(Problem Solving) ๐ฅ > BOJ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[BOJ] #1522 ๋ฌธ์์ด ๊ตํ (0) | 2021.03.05 |
---|---|
[BOJ] #3653 ์ํ ์์ง (0) | 2021.02.17 |
[BOJ] #11505 ๊ตฌ๊ฐ ๊ณฑ ๊ตฌํ๊ธฐ (0) | 2021.02.15 |
[BOJ] #10868 ์ต์๊ฐ (0) | 2021.02.15 |
[BOJ] #1509 ํฐ๋ฆฐ๋๋กฌ ๋ถํ (0) | 2021.02.09 |
๋๊ธ