From 1cc6092b80645ba0ddc9321cdc94e28808af1940 Mon Sep 17 00:00:00 2001 From: yuyu0830 Date: Mon, 22 Jul 2024 22:21:43 +0900 Subject: [PATCH 1/2] =?UTF-8?q?24-07-22=20=EA=B0=80=EC=9E=A5=20=EA=B8=B4?= =?UTF-8?q?=20=EC=A6=9D=EA=B0=80=ED=95=98=EB=8A=94=20=EB=B6=80=EB=B6=84=20?= =?UTF-8?q?=EC=88=98=EC=97=B4=205?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yuyu0830/LIS/14003.cpp | 0 yuyu0830/README.md | 3 ++- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 yuyu0830/LIS/14003.cpp diff --git a/yuyu0830/LIS/14003.cpp b/yuyu0830/LIS/14003.cpp new file mode 100644 index 0000000..e69de29 diff --git a/yuyu0830/README.md b/yuyu0830/README.md index 465df48..094c9ce 100644 --- a/yuyu0830/README.md +++ b/yuyu0830/README.md @@ -16,5 +16,6 @@ | 12차시| 2024.05.13 | 해시 | [두 배열의 합](https://www.acmicpc.net/problem/2143) | - | | 13차시| 2024.05.21 | LIS | [가장 긴 증가하는 부분 수열 2](https://www.acmicpc.net/problem/12015) | - | | 15차시| 2024.06.01 | 기하 | [다각형의 면적](https://www.acmicpc.net/problem/2166) | - | -| 16차시 | 2024.06.04 | 별자리 만들기 | [별자리 만들기](https://www.acmicpc.net/problem/4386) | - | +| 16차시 | 2024.06.04 | MST | [별자리 만들기](https://www.acmicpc.net/problem/4386) | - | +| 20차시 | 2024.07.22 | LIS | [가장 긴 증가하는 부분 수열 5](https://www.acmicpc.net/problem/4386) | - | --- \ No newline at end of file From 9255a94652f914d8fad86b828ec4b45b4d1dd000 Mon Sep 17 00:00:00 2001 From: yuyu0830 Date: Tue, 23 Jul 2024 16:40:01 +0900 Subject: [PATCH 2/2] =?UTF-8?q?24-07-23=201=EC=9D=98=20=EA=B0=9C=EC=88=98?= =?UTF-8?q?=20=EC=84=B8=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yuyu0830/README.md | 3 +- "yuyu0830/\354\210\230\355\225\231/9527.cpp" | 48 ++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 "yuyu0830/\354\210\230\355\225\231/9527.cpp" diff --git a/yuyu0830/README.md b/yuyu0830/README.md index 094c9ce..aa3d0c6 100644 --- a/yuyu0830/README.md +++ b/yuyu0830/README.md @@ -17,5 +17,6 @@ | 13차시| 2024.05.21 | LIS | [가장 긴 증가하는 부분 수열 2](https://www.acmicpc.net/problem/12015) | - | | 15차시| 2024.06.01 | 기하 | [다각형의 면적](https://www.acmicpc.net/problem/2166) | - | | 16차시 | 2024.06.04 | MST | [별자리 만들기](https://www.acmicpc.net/problem/4386) | - | -| 20차시 | 2024.07.22 | LIS | [가장 긴 증가하는 부분 수열 5](https://www.acmicpc.net/problem/4386) | - | +| 20차시 | 2024.07.22 | LIS | [가장 긴 증가하는 부분 수열 5](https://www.acmicpc.net/problem/14003) | - | +| 21차시 | 2024.07.23 | 수학 | [1의 개수 세기](https://www.acmicpc.net/problem/9527) | - | --- \ No newline at end of file diff --git "a/yuyu0830/\354\210\230\355\225\231/9527.cpp" "b/yuyu0830/\354\210\230\355\225\231/9527.cpp" new file mode 100644 index 0000000..3d6db99 --- /dev/null +++ "b/yuyu0830/\354\210\230\355\225\231/9527.cpp" @@ -0,0 +1,48 @@ +#include +#include + +using namespace std; + +typedef unsigned long long int ll; + +ll arr[10000] = {0, }; +int cnt = 1; + +// 0 ~ t 까지의 1의 개수를 반환 +ll f(ll t) { + int ptLog = cnt, tmp = 0; + ll pt = pow(2, ptLog - 1), ans = 0; + + while (pt) { + if (t & pt) { + ans += arr[ptLog - 1] + 1; + ans += pt * tmp++; + } + pt >>= 1; + ptLog--; + } + + return ans; +} + +int main() { + ll a, b, tmp = 1; cin >> a >> b; + + // b까지 arr 배열 누적합 연산 + while (b > tmp) { + arr[cnt] = (arr[cnt - 1] * 2) + tmp; + tmp *= 2; cnt++; + } + + ll ZeroToAVal = f(a); // 0 ~ a - 1 까지의 1의 개수 + ll bVal = f(b); // 0 ~ b 까지의 1의 개수 + ll aVal = 0; // a 의 1의 개수 + + ll pt = pow(2, cnt); + while (pt) { + if (a & pt) aVal++; + pt >>= 1; + } + + printf("%lld\n", bVal - ZeroToAVal + aVal); +} \ No newline at end of file