{"id":21948560,"url":"https://github.com/faresbakhit/cp","last_synced_at":"2025-03-22T17:15:29.479Z","repository":{"id":193617543,"uuid":"689181454","full_name":"faresbakhit/cp","owner":"faresbakhit","description":"competitive programming ⚔️ resources and notes 🤺 ","archived":false,"fork":false,"pushed_at":"2023-12-11T00:28:45.000Z","size":54,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-27T19:55:13.852Z","etag":null,"topics":["algorithms","competitive-programming","cpp","data-structures","problem-solving"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"0bsd","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/faresbakhit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-09-09T02:43:02.000Z","updated_at":"2023-12-11T00:28:48.000Z","dependencies_parsed_at":"2023-12-17T23:03:13.153Z","dependency_job_id":null,"html_url":"https://github.com/faresbakhit/cp","commit_stats":{"total_commits":28,"total_committers":1,"mean_commits":28.0,"dds":0.0,"last_synced_commit":"fff3d230cb6aaa6c8fc833dcbbeb14f1c76cbf62"},"previous_names":["faresbakhit/cp"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/faresbakhit%2Fcp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/faresbakhit%2Fcp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/faresbakhit%2Fcp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/faresbakhit%2Fcp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/faresbakhit","download_url":"https://codeload.github.com/faresbakhit/cp/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244991176,"owners_count":20543627,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithms","competitive-programming","cpp","data-structures","problem-solving"],"created_at":"2024-11-29T05:15:50.241Z","updated_at":"2025-03-22T17:15:29.439Z","avatar_url":"https://github.com/faresbakhit.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Competitive Programming\n\ncompetitive programming ⚔️ resources and notes 🤺\n\n- [Fast I/O](#fast-io)\n- [Numeric types](#numeric-types23)\n- [Bit manipulation](#bit-manipulation4)\n  - [Multiply or divide by 2^k](#multiply-or-divide-by-2k)\n  - [Change the n-th bit](#change-the-n-th-bit)\n  - [Is a power of 2](#is-a-power-of-2)\n  - [Is the n-th bit set](#is-the-n-th-bit-set)\n- [How-to TeX algorithms](#how-to-tex-algorithms)\n  - [Arithmetic operations](#arithmetic-operations)\n  - [Comparison operations](#comparison-operations)\n  - [Bitwise operations](#bitwise-operations)\n  - [Constants](#constants)\n\n## Fast I/O\n\n```cpp\nios::sync_with_stdio(false);\ncin.tie(nullptr);\n```\n\n## Numeric types[^2][^3]\n\n[^2]: [Fundamental types](https://en.cppreference.com/w/cpp/language/types) - cppreference.com\n[^3]: [Numeric types](https://doc.rust-lang.org/reference/types/numeric.html) - The Rust Reference\n\n| C/C++ Type | Rust Type | Size    | Minimum                   | Maximum                  |\n|------------|-----------|---------|---------------------------|--------------------------|\n| uint8_t    | u8        | 8-bit   | $0$                       | $2^{8}-1$                |\n| uint16_t   | u16       | 16-bit  | $0$                       | $2^{16}-1$               |\n| uint32_t   | u32       | 32-bit  | $0$                       | $2^{32}-1$               |\n| uint64_t   | u64       | 64-bit  | $0$                       | $2^{64}-1$               |\n|            | u128      | 128-bit | $0$                       | $2^{128}-1$              |\n| int8_t     | i8        | 8-bit   | $-2^{7}$                  | $2^{7}-1$                |\n| int16_t    | i16       | 16-bit  | $-2^{15}$                 | $2^{15}-1$               |\n| int32_t    | i32       | 32-bit  | $-2^{31}$                 | $2^{31}-1$               |\n| int64_t    | i64       | 64-bit  | $-2^{63}$                 | $2^{63}-1$               |\n|            | i128      | 128-bit | $-2^{127}$                | $2^{127}-1$              |\n| size_t     | isize     | arch    |                           |                          |\n| ssize_t    | usize     | arch    |                           |                          |\n| float      | f32       | 32-bit  | $-3.40282 \\cdot 10^{38}$  | $3.40282 \\cdot 10^{38}$  |\n| double     | f64       | 64-bit  | $-1.79769 \\cdot 10^{308}$ | $1.79769 \\cdot 10^{308}$ |\n\n---\n\n## Bit manipulation[^4]\n\n[^4]: [Bit Twiddling Hacks](https://graphics.stanford.edu/~seander/bithacks.html) - Sean Anderson\n\n### Multiply or divide by $2^k$\n\n- $x \\cdot 2^k = x \\ll k$\n- $x / 2^k = x \\gg k$\n\n### Change the $n$-th bit\n\n- set — $x \\lor (1 \\ll n)$\n- unset — $x \\land \\lnot(1 \\ll n)$\n- toggle — $x \\oplus (1 \\ll n)$\n\n### Is a power of $2$\n\n$$f_1(x) = x \\land (x - 1)$$\n\n$$\nf_2(x) =\n\\begin{cases}\n  \\top \u0026 x = 0 \\\\\n  \\bot \u0026 x \\neq 0\n\\end{cases}\n$$\n\n$$f(x) = (f_2 \\circ f_1)(x)$$\n\n#### Is the $n$-th bit set\n\n$$f_1(x, n) = x \\land (1 \\ll n)$$\n\n$$\nf_2(x) =\n\\begin{cases}\n\\top \u0026 x \\neq 0 \\\\\n\\bot \u0026 x = 0\n\\end{cases}\n$$\n\n$$f(x, n) = (f_2 \\circ f_1)(x, n)$$\n\n---\n\n## Language Syntax\n\n### Arithmetic operations\n\n| Operation        | C/C++ Syntax    | Rust Syntax | LaTex       | LaTex (Rendered) |\n|------------------|-----------------|-------------|-------------|------------------|\n| *Addition*       | `x + y`         | `x + y`     | `+`         | $x + y$          |\n| *Subtraction*    | `x - y`         | `x - y`     | `-`         | $x - y$          |\n| *Multiplication* | `x * y`         | `x * y`     | `\\cdot`     | $x \\cdot y$      |\n| *Division*       | `x / y`         | `x / y`     | `/`         | $x / y$          |\n| *Remainder*      | `x % y`         | `x % y`     | `\\bmod`     | $x \\bmod y$      |\n| *Exponentiation* | `pow`           | `T::pow`    | `^`         | $x ^ y$          |\n| *Square root*    | `sqrt`          | `T::sqrt`   | `\\sqrt{}`   | $\\sqrt{x}$       |\n| $n$*-th root*    |                 |             | `\\sqrt[]{}` | $\\sqrt[n]{x}$    |\n\n### Comparison operations\n\n| Operation               | C/C++ Syntax | Rust Syntax | LaTex     | Latex (Rendered) |\n|-------------------------|--------------|-------------|-----------|------------------|\n| *Equality*              | `x == y`     | `x == y`    | `=`       | $x = y$          |\n| *Approximate-equality*  |              |             | `\\approx` | $x \\approx y$    |\n| *Inequality*            | `x != y`     | `x != y`    | `\\neq`    | $x \\neq y$       |\n| *Greater than*          | `x \u003e y`      | `x \u003e y`     | `\u003e`       | $x \u003e y$          |\n| *Less than*             | `x \u003c y`      | `x \u003c y`     | `\u003c`       | $x \u003c y$          |\n| *Greater than or equal* | `x \u003e= y`     | `x \u003e= y`    | `\\geq`    | $x \\geq y$       |\n| *Less than or equal*    | `x \u003c= y`     | `x \u003c= y`    | `\\leq`    | $x \\leq y$       |\n\n### Bitwise operations\n\n| Operation              | C/C++ Syntax          | Rust Syntax       | LaTex    | LaTex (Rendered) |\n|------------------------|-----------------------|-------------------|----------|------------------|\n| *Bitwise NOT*          | `~x`                  | `!x`              | `\\lnot`  | $\\lnot x$        |\n| *Bitwise AND*          | `x \u0026 y`               | `x \u0026 y`           | `\\land`  | $x \\land y$      |\n| *Bitwise OR*           | `x \\| y`              | `x \\| y`          | `\\lor`   | $x \\lor y$       |\n| *Bitwise XOR*          | `x ^ y`               | `x ^ y`           | `\\oplus` | $x \\oplus y$     |\n| *Bitwise left shift*   | `x \u003c\u003c n`              | `x \u003c\u003c n`          | `\\ll`    | $x \\ll n$        |\n| *Bitwise right shift*  | `x \u003e\u003e n`              | `x \u003e\u003e n`          | `\\gg`    | $x \\gg n$        |\n| *Bitwise left rotate*  | `std::rotl` **C++20** | `T::rotate_left`  | `\\lll`   | $x \\lll n$       |\n| *Bitwise right rotate* | `std::rotl` **C++20** | `T::rotate_right` | `\\ggg`   | $x \\ggg n$       |\n\n### Constants\n\n| Constant                       | [C/C++ Syntax][constants-c] | [Rust Syntax][constants-rust] | LaTeX          | LaTeX (Rendered) |\n|:-------------------------------|-----------------------------|-------------------------------|----------------|------------------|\n| true                           | `true`                      | `true`                        | `\\top`         | $\\top$           |\n| false                          | `false`                     | `false`                       | `\\bot`         | $\\bot$           |\n| Archimedes' constant           | `M_PI`                      | `PI`                          | `\\pi`          | $\\pi$            |\n| Euler's number                 | `M_E`                       | `E`                           | `e`            | $e$              |\n| The full circle constant       |                             | `TAU`                         | `\\tau`         | $\\tau$           |\n| The logarithm to base 10 of e  | `M_LOG2E`                   | `LOG2_E`                      | `\\log_{2}{e}`  | $\\log_{2}{e}$    |\n| The logarithm to base 10 of e  | `M_LOG10E`                  | `LOG10_E`                     | `\\log_{10}{e}` | $\\log_{10}{e}$   |\n| The logarithm to base 2 of ten |                             | `LOG2_10`                     | `\\log_{2}{10}` | $\\log_{2}{10}$   |\n| The logarithm to base 10 of 2  |                             | `LOG10_2`                     | `\\log_{10}{2}` | $\\log_{10}{2}$   |\n| The natural logarithm of 2     | `M_LN2`                     | `LN_2`                        | `\\ln{2}`       | $\\ln{2}$         |\n| The natural logarithm of 10    | `M_LN10`                    | `LN_10`                       | `\\ln{10}`      | $\\ln{10}$        |\n| The square root of 2           | `M_SQRT2`                   | `SQRT_2`                      | `\\sqrt{2}`     | $\\sqrt{2}$       |\n\n[constants-c]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/math.h.html \"math.h\"\n[constants-rust]: https://doc.rust-lang.org/core/f64/consts/index.html \"core::{f64, f32}::consts\"\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffaresbakhit%2Fcp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffaresbakhit%2Fcp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffaresbakhit%2Fcp/lists"}