์๊ฐ ์ ํ | ๋ฉ๋ชจ๋ฆฌ ์ ํ | ์ ๋ต ๋น์จ |
1 ์ด | 256 MB | 33.686 % |
๋ฌธ์
ํด๊ฒฐ
key point, ์ธ๊ทธ๋จผํธ ํธ๋ฆฌ, '์ต์๊ฐ'๊ณผ ๋ฐฉ์ ๋์ผ
2021/02/15 - [๐ฅ PS(Problem Solving) ๐ฅ/BOJ] - [BOJ] #10868 ์ต์๊ฐ
- ์์ ๋ณด์ด๋ ์ต์๊ฐ ๋ฌธ์ ์ ๋ฐฉ๋ฒ์ ๋์ผํ๋ ๊ตฌ๊ฐ์ ๊ณฑ์ ๊ตฌํด์ผ ํ๋ ๋ฌธ์ ์ด๋ค.
- ๋ฐ๋ผ์, ์ด๊ธฐํ๋ฅผ ๋ฐ๋ก ํด์ค ํ์๊ฐ ์๊ณ ,
- update ํจ์์์ seg[i]๊ฐ์ ์ ์ฅํ ๋, ๊ตฌ๊ฐ์ ๊ณฑ์ ์ ์ฅํด์ผ ํ๋ฉฐ
- queryํจ์์์ ๊ตฌ๊ฐ์ ๊ณฑ์ ๋ฆฌํดํด์ผ ํ๋ค.
์ฝ๋
๋ฉ๋ชจ๋ฆฌ | ์๊ฐ |
17616 KB | 324 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<vector>
#include<algorithm>
using namespace std;
#define mod 1000000007
vector<long long int>seg;
int n, m, k;
int h = 1;
void update(int i, int val) {
i += h - 1;
seg[i] = val;
while (i > 1) {
i /= 2;
seg[i] = (seg[i * 2] * seg[i * 2 + 1]) % mod;
}
}
long long int query(int l, int r, int num, int nl, int nr) {
//l,r์ด ์ฐพ์ผ๋ ค๋ ๋ฒ์, num์ด ํ์ฌ ๋ณด๊ณ ์๋ ๋
ธ๋
//nl,nr ํ์ฌ ๋ณด๊ณ ์๋ ๋ฒ์
if (l <= nl && nr <= r) return seg[num];
else if (nl > r || nr < l) return 1;
int mid = (nl + nr) / 2;
return (query(l, r, num * 2, nl, mid) * query(l, r, num * 2 + 1, mid + 1, nr)) % mod;
}
int main() {
scanf("%d %d %d", &n, &m, &k);
while (h < n) h <<= 1; //๋์ด๊ตฌํ๊ธฐ 1 2 4 8
seg.resize(h * 2);
for (int i = 0; i < n; i++) {
int num;
scanf("%d", &num);
update(i + 1, num);
}
for (int i = 0, a, b, c; i < m + k; i++) {
scanf("%d %d %d", &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] #3653 ์ํ ์์ง (0) | 2021.02.17 |
---|---|
[BOJ] #2042 ๊ตฌ๊ฐ ํฉ ๊ตฌํ๊ธฐ (0) | 2021.02.15 |
[BOJ] #10868 ์ต์๊ฐ (0) | 2021.02.15 |
[BOJ] #1509 ํฐ๋ฆฐ๋๋กฌ ๋ถํ (0) | 2021.02.09 |
[BOJ] #10942 ํฐ๋ฆฐ๋๋กฌ? (0) | 2021.02.09 |
๋๊ธ