├── .gitattributes ├── tools ├── linux │ ├── storage │ ├── compile │ ├── run │ ├── addSample │ ├── testSample │ ├── sample │ └── comp.cpp └── windows │ ├── storage.bat │ ├── testSample.bat │ ├── compile.bat │ ├── addSample.bat │ ├── sample.bat │ └── comp.cpp ├── compile_flags.txt ├── .gitignore ├── .gitmodules ├── Codeforces Gym ├── 100199A.py ├── 100201D.py ├── 535265C.cpp ├── 102428M.cpp ├── 102465A.cpp ├── 105481B.cpp ├── 104396I.cpp ├── 102428K.cpp ├── 105631A.cpp ├── 101808A.cpp ├── 104772A.cpp ├── 101981A.cpp ├── 101981K.cpp ├── 102428E.cpp ├── 103860F.cpp ├── 105631E.cpp ├── 102428F.cpp ├── 103860G.cpp ├── 535265A.cpp ├── 105586E.cpp ├── 102465B.cpp ├── 104772K.cpp ├── 105586N.cpp ├── 104772D.cpp ├── 105586A.cpp ├── 102428I.cpp ├── 101808F.cpp ├── 104772G.cpp ├── 102465D.cpp ├── 101808I.cpp └── 105481J.cpp ├── .vscode ├── keybindings.json ├── launch.json └── extensions.json ├── Nowcoder ├── 231369.cpp ├── 108306J.cpp ├── 108307D.cpp ├── 108302I.cpp ├── 108307H.cpp ├── 108330F.cpp ├── 108217C.cpp ├── 81605A.cpp ├── 231167.cpp ├── 81602I.cpp ├── 231376.cpp ├── 248247.cpp ├── 231193.cpp ├── 81600E.cpp ├── 247578.cpp ├── 247575.cpp ├── 108306F.cpp ├── 108330D.cpp ├── 108302E.cpp ├── 108298G.cpp ├── 81600B.cpp ├── 81603K.cpp ├── 247577.cpp └── 108298L.cpp ├── AtCoder ├── abc210_a.cpp ├── abc207_a.cpp ├── abc210_b.cpp ├── abc218_b.cpp ├── abc218_a.cpp ├── abc207_b.cpp ├── arc120_a.cpp ├── abc210_c.cpp ├── abc216_a.cpp ├── abc216_c.cpp ├── abc227_a.cpp ├── abc210_e.cpp ├── abc216_b.cpp ├── arc203_a.cpp ├── abc227_c.cpp ├── abc366_a.cpp ├── abc360_a.cpp ├── abc207_e.cpp ├── arc127_a.cpp ├── arc148_a.cpp ├── arc120_d.cpp ├── abc210_d.cpp ├── arc127_b.cpp ├── agc061_a.cpp └── arc120_b.cpp ├── Codeforces ├── 1566A.cpp ├── 1594A.cpp ├── 1560A.cpp ├── 1395A.cpp ├── 1560B.cpp ├── 1560C.cpp ├── 1566B.cpp ├── 1543B.cpp ├── 1530A.cpp ├── 1579A.cpp ├── 1543A.cpp ├── 1573A.cpp ├── 1594B.cpp ├── 1593A.cpp ├── 1906M.cpp ├── 1594E1.cpp ├── 1543D1.cpp ├── 1593D1.cpp ├── 1593C.cpp ├── 1023B.cpp ├── 1542A.cpp ├── 1542B.cpp ├── 2068J.cpp ├── 1748A.cpp ├── 1987A.cpp ├── 1542C.cpp ├── 2104A.cpp ├── 1603B.cpp ├── 1600E.cpp ├── 1566D1.cpp ├── 2108A.cpp ├── 2122A.cpp ├── 1750A.cpp ├── 1616B.cpp ├── 1459B.cpp ├── 1603A.cpp ├── 1998A.cpp ├── 1632A.cpp ├── 1998B.cpp ├── 1352C.cpp ├── 1573B.cpp ├── 1632B.cpp ├── 1605B.cpp ├── 1749B.cpp ├── 1629B.cpp ├── 1625B.cpp ├── 1583B.cpp ├── 1987C.cpp ├── 1566C.cpp ├── 1729A.cpp ├── 2042A.cpp ├── 1616A.cpp ├── 1634A.cpp ├── 1622A.cpp ├── 1625A.cpp ├── 2180A.cpp ├── 1704B.cpp ├── 2053A.cpp ├── 2180B.cpp ├── 1801A.cpp ├── 1593B.cpp ├── 1352A.cpp ├── 1718A1.cpp ├── 1718A2.cpp ├── 1579E1.cpp ├── 2042B.cpp ├── 2104B.cpp └── 1623A.cpp ├── LibreOJ ├── 6866.py ├── 6877.cpp ├── 2875.cpp └── 6875.cpp ├── QOJ ├── 14302.cpp ├── 5462.cpp ├── 14551.cpp ├── 5422.cpp ├── 9917.cpp ├── 9142.cpp ├── 4837.cpp ├── 9483.cpp ├── 7747.cpp ├── 11222.cpp ├── 10868.cpp ├── 7585.cpp ├── 14687.cpp ├── 6138.cpp ├── 14948.cpp ├── 11376.cpp ├── 11429.cpp ├── 6131.cpp ├── 969.cpp ├── 141-Alice.cpp ├── 5471.cpp ├── 9328.cpp ├── 7757.cpp ├── 6128.cpp ├── 9136.cpp ├── 10117.cpp ├── 14724.cpp └── 9521.cpp ├── HDOJ ├── 6702.cpp ├── 7515.cpp ├── 6983.cpp ├── 6707.cpp ├── 7551.cpp ├── 7457.cpp ├── 7454.cpp ├── 7486.cpp ├── 7491.cpp ├── 6709.cpp ├── 1176-1009.cpp ├── 7440.cpp ├── 7535.cpp ├── 6954.cpp ├── 7055.cpp ├── 7514.cpp ├── 1174-1007.cpp ├── 7445.cpp ├── 6708.cpp ├── 7468.cpp ├── 7533.cpp ├── 6182.cpp └── 7451.cpp ├── .github └── workflows │ └── clang-format.yml ├── Luogu └── P10678.cpp ├── Misc ├── Tsinghua University Bootcamp 2025 │ ├── Tsinghua Bootcamp 2025, Day 5 │ │ ├── G.cpp │ │ └── L.cpp │ ├── Tsinghua Bootcamp 2025, Day 4 │ │ └── D.cpp │ └── Tsinghua Bootcamp 2025, Qualification Round │ │ └── A.cpp └── Tsinghua University Bootcamp in Summer 2024 │ ├── Tsinghua Bootcamp. Finals │ └── K.cpp │ ├── Tsinghua Bootcamp 2024. Qualification Round │ └── A.cpp │ └── Tsinghua Bootcamp 2024. Day 3 │ └── D.cpp ├── UOJ └── 235.cpp ├── FDUOJ └── FDUPC_2025 │ ├── FDUPC25P-B.cpp │ └── FDUPC25P-D.cpp └── Online Judge └── 10104.cpp /.gitattributes: -------------------------------------------------------------------------------- 1 | * text eol=lf -------------------------------------------------------------------------------- /tools/linux/storage: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | mv $1 ../$2/ -------------------------------------------------------------------------------- /tools/windows/storage.bat: -------------------------------------------------------------------------------- 1 | move %1 \Workspace\Code\%2\ -------------------------------------------------------------------------------- /compile_flags.txt: -------------------------------------------------------------------------------- 1 | -xc++ 2 | -Wall 3 | -Wextra 4 | -DLOCAL -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | _work 2 | tools/linux/check 3 | tools/windows/check.exe -------------------------------------------------------------------------------- /tools/linux/compile: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | g++ $1.cpp -o $1 -std=c++14 -Wall -Wextra -O2 -DLOCAL -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "libs/testlib"] 2 | path = libs/testlib 3 | url = https://github.com/MikeMirzayanov/testlib 4 | -------------------------------------------------------------------------------- /tools/windows/testSample.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | echo Compiling... 3 | call compile %1 4 | echo Running... 5 | .\%1.exe < .\sample\%1\%2.in -------------------------------------------------------------------------------- /tools/linux/run: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo Compiling... 3 | compile $1 4 | echo Running... 5 | ulimit -s unlimited 6 | ./$1 7 | rm $1 &>/dev/null -------------------------------------------------------------------------------- /tools/windows/compile.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | g++ %1.cpp -o %1 -std=c++17 -Wall -Wextra -O2 -Wl,--stack=512000000 -IE:/Code/libs/testlib -DLOCAL -------------------------------------------------------------------------------- /tools/linux/addSample: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | mkdir -p ./samp/$1 3 | touch ./samp/$1/$2.in 4 | touch ./samp/$1/$2.ans 5 | subl ./samp/$1/$2.in 6 | subl ./samp/$1/$2.ans -------------------------------------------------------------------------------- /tools/linux/testSample: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo Compiling... 3 | compile $1 4 | echo Running... 5 | ulimit -s unlimited 6 | ./$1 < ./samp/$1/$2.in 7 | rm $1 &>/dev/null -------------------------------------------------------------------------------- /tools/windows/addSample.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | mkdir sample\%1 3 | type nul > sample\%1\%2.in 4 | type nul > sample\%1\%2.ans 5 | start sample\%1\%2.in 6 | start sample\%1\%2.ans -------------------------------------------------------------------------------- /Codeforces Gym/100199A.py: -------------------------------------------------------------------------------- 1 | import math; 2 | 3 | fin = open("china.in", "r") 4 | fout = open("china.out", "w") 5 | 6 | n = int(fin.read()) 7 | 8 | m = n // 2 9 | 10 | while math.gcd(n, m) != 1: 11 | m -= 1 12 | 13 | fout.write(str(m)) -------------------------------------------------------------------------------- /tools/windows/sample.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | echo Compiling... 3 | call compile %1 4 | echo Running... 5 | %1.exe < .\sample\%1\%2.in > .\sample\%1\%2.out 6 | echo Checking... 7 | check .\sample\%1\%2.in .\sample\%1\%2.out .\sample\%1\%2.ans 8 | del %1.exe -------------------------------------------------------------------------------- /tools/linux/sample: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo Compiling... 3 | compile $1 4 | echo Running... 5 | ulimit -s unlimited 6 | ./$1 < ./samp/$1/$2.in > ./samp/$1/$2.out 7 | echo Checking... 8 | check ./samp/$1/$2.in ./samp/$1/$2.out ./samp/$1/$2.ans 9 | rm $1 &>/dev/null -------------------------------------------------------------------------------- /Codeforces Gym/100201D.py: -------------------------------------------------------------------------------- 1 | n = int(open("digit.in", "r").read()) 2 | 3 | f0, f1 = 1, 0 4 | 5 | v = 1 6 | 7 | while v <= n: 8 | if n % (2 * v) >= v: 9 | f0, f1 = f0 + f1, f1 10 | else: 11 | f0, f1 = f0, f0 + f1 12 | v *= 2 13 | 14 | open("digit.out", "w").write(str(f0)) -------------------------------------------------------------------------------- /.vscode/keybindings.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "key": "f9", 4 | "command": "workbench.action.tasks.runTask" 5 | }, 6 | { 7 | "key": "f11", 8 | "command": "workbench.action.tasks.test" 9 | }, 10 | { 11 | "key": "ctrl+shift+b", 12 | "command": "-workbench.action.tasks.build" 13 | } 14 | ] -------------------------------------------------------------------------------- /Nowcoder/231369.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void solve(void) { 5 | int n; 6 | cin >> n; 7 | int ans = 2; 8 | for (int i = 2; i <= n; i++) 9 | if (n / i != n / (i - 1)) ans++; 10 | cout << ans << endl; 11 | return; 12 | } 13 | 14 | int main() { 15 | ios::sync_with_stdio(false); 16 | int _; 17 | cin >> _; 18 | while (_--) solve(); 19 | return 0; 20 | } -------------------------------------------------------------------------------- /AtCoder/abc210_a.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Macesuted (i@macesuted.moe) 3 | * @copyright Copyright (c) 2021 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | 9 | #define int long long 10 | 11 | signed main() { 12 | ios::sync_with_stdio(false); 13 | int n, a, x, y; 14 | cin >> n >> a >> x >> y; 15 | if (n <= a) 16 | cout << n * x << endl; 17 | else 18 | cout << a * x + (n - a) * y << endl; 19 | return 0; 20 | } -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "LLDB Debug", 6 | "type": "lldb", 7 | "request": "launch", 8 | "program": "${fileDirname}/${fileBasenameNoExtension}.exe", 9 | "args": [], 10 | "cwd": "${workspaceFolder}", 11 | "sourceLanguages": [ 12 | "C++" 13 | ], 14 | "preLaunchTask": "LLDB Build" 15 | }, 16 | ] 17 | } -------------------------------------------------------------------------------- /AtCoder/abc207_a.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Macesuted (i@macesuted.moe) 3 | * @copyright Copyright (c) 2021 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | 9 | #define int long long 10 | 11 | void work(void) { 12 | int a, b, c; 13 | cin >> a >> b >> c; 14 | cout << max(max(a + b, a + c), b + c) << endl; 15 | return; 16 | } 17 | 18 | signed main() { 19 | ios::sync_with_stdio(false); 20 | int _ = 1; 21 | // cin >> _; 22 | while (_--) work(); 23 | return 0; 24 | } -------------------------------------------------------------------------------- /Codeforces/1566A.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Macesuted (i@macesuted.moe) 3 | * @copyright Copyright (c) 2021 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | 9 | #define int long long 10 | 11 | void work(void) { 12 | int n, s; 13 | cin >> n >> s; 14 | int mid = (n + 1) / 2; 15 | cout << s / (n - mid + 1) << endl; 16 | return; 17 | } 18 | 19 | signed main() { 20 | ios::sync_with_stdio(false); 21 | int _ = 1; 22 | cin >> _; 23 | while (_--) work(); 24 | return 0; 25 | } -------------------------------------------------------------------------------- /LibreOJ/6866.py: -------------------------------------------------------------------------------- 1 | """ 2 | File: 6866.py 3 | Author: Macesuted (i@macesuted.moe) 4 | Date: 2023-03-05 5 | 6 | Copyright (c) 2023 7 | """ 8 | 9 | n, k = input().split(' '); 10 | n, k = int(n), int(k) 11 | 12 | if k == 1: 13 | if n == 1: 14 | print(1) 15 | else: 16 | print('Poor E.S.!') 17 | exit() 18 | 19 | if k == 2: 20 | print(2 ** (n - 2)) 21 | exit() 22 | 23 | k -= 1 24 | 25 | f = v = 1 26 | for i in range(2, n + 1): 27 | v = (f + k - 1) // k 28 | f += v 29 | 30 | print(v) -------------------------------------------------------------------------------- /Nowcoder/108306J.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 108306J.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-08-12 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define endl '\n' 14 | 15 | void solve(void) { 16 | string s; 17 | while (getline(cin, s)) cout << s << " nya" << endl; 18 | return; 19 | } 20 | 21 | int main() { 22 | ios::sync_with_stdio(false), cin.tie(nullptr); 23 | 24 | int _ = 1; 25 | while (_--) solve(); 26 | 27 | return 0; 28 | } -------------------------------------------------------------------------------- /Codeforces/1594A.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Macesuted (i@macesuted.moe) 3 | * @copyright Copyright (c) 2021 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | 9 | #define int long long 10 | 11 | typedef pair pii; 12 | 13 | void work(void) { 14 | int n; 15 | cin >> n; 16 | cout << -n + 1 << ' ' << n << endl; 17 | return; 18 | } 19 | 20 | signed main() { 21 | ios::sync_with_stdio(false); 22 | cout << setiosflags(ios::fixed) << setprecision(11); 23 | int _ = 1; 24 | cin >> _; 25 | while (_--) work(); 26 | return 0; 27 | } -------------------------------------------------------------------------------- /Nowcoder/108307D.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 108307D.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-08-14 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define endl '\n' 14 | 15 | void solve(void) { 16 | int64_t n; 17 | cin >> n; 18 | cout << ((n - 4) % 6 == 0 ? 2 : 0) << endl; 19 | return; 20 | } 21 | 22 | int main() { 23 | ios::sync_with_stdio(false), cin.tie(nullptr); 24 | 25 | int _ = 1; 26 | cin >> _; 27 | while (_--) solve(); 28 | 29 | return 0; 30 | } -------------------------------------------------------------------------------- /QOJ/14302.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 14302.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-09-07 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define endl '\n' 14 | 15 | void solve(void) { 16 | int n, k; 17 | cin >> n >> k; 18 | for (int i = 1; i <= k; i++) cout << i << ' '; 19 | cout << endl; 20 | return; 21 | } 22 | 23 | int main() { 24 | ios::sync_with_stdio(false), cin.tie(nullptr); 25 | 26 | int _ = 1; 27 | while (_--) solve(); 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /Nowcoder/108302I.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 108302I.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-07-29 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define endl '\n' 14 | 15 | void solve(void) { 16 | int64_t n; 17 | cin >> n; 18 | cout << ((n & 1) ? 2 * (n + (n + 1) / 2) : 2 * (n + 1 + n / 2)) << endl; 19 | return; 20 | } 21 | 22 | int main() { 23 | ios::sync_with_stdio(false), cin.tie(nullptr); 24 | 25 | int _ = 1; 26 | while (_--) solve(); 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Codeforces/1560A.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Macesuted (i@macesuted.moe) 3 | * @copyright Copyright (c) 2021 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | 9 | int a[1001], n = 0; 10 | 11 | void work(void) { 12 | int i; 13 | cin >> i; 14 | cout << a[i] << endl; 15 | return; 16 | } 17 | 18 | signed main() { 19 | ios::sync_with_stdio(false); 20 | for (register int i = 1; n <= 1000; i++) { 21 | if (i % 3 == 0 || i % 10 == 3) continue; 22 | a[++n] = i; 23 | } 24 | int _ = 1; 25 | cin >> _; 26 | while (_--) work(); 27 | return 0; 28 | } -------------------------------------------------------------------------------- /QOJ/5462.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 5462.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-10-24 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define endl '\n' 14 | 15 | void solve(void) { 16 | int l, r, b, k; 17 | cin >> l >> r >> b >> k; 18 | int64_t range = (l / b + (l % b > 0)) * b; 19 | cout << k * range << endl; 20 | return; 21 | } 22 | 23 | int main() { 24 | ios::sync_with_stdio(false), cin.tie(nullptr); 25 | 26 | int _ = 1; 27 | while (_--) solve(); 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /QOJ/14551.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 14551.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-09-06 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define endl '\n' 14 | 15 | void solve(void) { 16 | int n, m; 17 | cin >> n >> m; 18 | int x = (n + 1) / 2, y = m - x; 19 | cout << 2 * min(x, y) + 1 << endl; 20 | return; 21 | } 22 | 23 | int main() { 24 | ios::sync_with_stdio(false), cin.tie(nullptr); 25 | 26 | int _ = 1; 27 | cin >> _; 28 | while (_--) solve(); 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /Codeforces/1395A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int T; 6 | scanf("%d", &T); 7 | while (T--) { 8 | int a, b, c, d; 9 | scanf("%d%d%d%d", &a, &b, &c, &d); 10 | if ((a & 1) + (b & 1) + (c & 1) + (d & 1) <= 1) 11 | puts("Yes"); 12 | else if (a && b && c) { 13 | a--, b--, c--, d += 3; 14 | if ((a & 1) + (b & 1) + (c & 1) + (d & 1) <= 1) 15 | puts("Yes"); 16 | else 17 | puts("No"); 18 | } else 19 | puts("No"); 20 | } 21 | return 0; 22 | } -------------------------------------------------------------------------------- /Codeforces/1560B.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Macesuted (i@macesuted.moe) 3 | * @copyright Copyright (c) 2021 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | 9 | int a[1001], n = 0; 10 | 11 | void work(void) { 12 | int a, b, c; 13 | cin >> a >> b >> c; 14 | int t = abs(a - b), n = 2 * t; 15 | if (a > n || b > n || c > n) 16 | cout << -1 << endl; 17 | else 18 | cout << (c + t - 1) % n + 1 << endl; 19 | return; 20 | } 21 | 22 | signed main() { 23 | ios::sync_with_stdio(false); 24 | int _ = 1; 25 | cin >> _; 26 | while (_--) work(); 27 | return 0; 28 | } -------------------------------------------------------------------------------- /HDOJ/6702.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 6702.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-07-18 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | void solve(void) { 14 | long long A, B, C = 0; 15 | cin >> A >> B; 16 | if (!(A & B)) return cout << 1 << endl, void(); 17 | for (int i = 0; i < 32; i++) 18 | if ((A >> i & 1) && (B >> i & 1)) C |= (long long)1 << i; 19 | cout << C << endl; 20 | return; 21 | } 22 | 23 | int main() { 24 | int _; 25 | cin >> _; 26 | while (_--) solve(); 27 | return 0; 28 | } -------------------------------------------------------------------------------- /HDOJ/7515.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 7515.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-08-09 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | void solve(void) { 14 | int64_t x, y; 15 | cin >> x >> y; 16 | if (x % y == 0) return cout << y << ' ' << x / y << endl, void(); 17 | cout << y << ' ' << 2 * x / gcd(2 * x, y) << endl; 18 | return; 19 | } 20 | 21 | int main() { 22 | ios::sync_with_stdio(false), cin.tie(nullptr); 23 | 24 | int _; 25 | cin >> _; 26 | while (_--) solve(); 27 | 28 | return 0; 29 | } -------------------------------------------------------------------------------- /AtCoder/abc210_b.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Macesuted (i@macesuted.moe) 3 | * @copyright Copyright (c) 2021 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | 9 | #define int long long 10 | 11 | string str; 12 | 13 | signed main() { 14 | ios::sync_with_stdio(false); 15 | int n; 16 | cin >> n >> str; 17 | str = ' ' + str; 18 | for (register int i = 1; i <= n; i++) 19 | if (str[i] == '1') { 20 | if (i & 1) 21 | cout << "Takahashi" << endl; 22 | else 23 | cout << "Aoki" << endl; 24 | break; 25 | } 26 | return 0; 27 | } -------------------------------------------------------------------------------- /AtCoder/abc218_b.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Macesuted (i@macesuted.moe) 3 | * @copyright Copyright (c) 2021 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | 9 | #define int long long 10 | 11 | typedef pair pii; 12 | 13 | void work(void) { 14 | for (register int i = 1; i <= 26; i++) { 15 | int t; 16 | cin >> t; 17 | cout << (char)('a' + t - 1); 18 | } 19 | cout << endl; 20 | return; 21 | } 22 | 23 | signed main() { 24 | ios::sync_with_stdio(false); 25 | int _ = 1; 26 | cout << setprecision(11); 27 | // cin >> _; 28 | while (_--) work(); 29 | return 0; 30 | } -------------------------------------------------------------------------------- /HDOJ/6983.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #define int long long 5 | 6 | bool mem1; 7 | 8 | map S; 9 | int n, k; 10 | 11 | int dfs(int p) { 12 | if (p <= k) return 1; 13 | if (S.find(p) != S.end()) return S[p]; 14 | int mid = p >> 1; 15 | return S[p] = 1 + dfs(mid) + dfs(p - mid); 16 | } 17 | 18 | void solve(void) { 19 | cin >> n >> k; 20 | cout << dfs(n) << endl; 21 | S.clear(); 22 | return; 23 | } 24 | 25 | bool mem2; 26 | 27 | signed main() { 28 | ios::sync_with_stdio(false); 29 | int _ = 1; 30 | cin >> _; 31 | while (_--) solve(); 32 | return 0; 33 | } -------------------------------------------------------------------------------- /AtCoder/abc218_a.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Macesuted (i@macesuted.moe) 3 | * @copyright Copyright (c) 2021 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | 9 | #define int long long 10 | 11 | typedef pair pii; 12 | 13 | void work(void) { 14 | int n; 15 | string s; 16 | cin >> n >> s; 17 | if (s[n - 1] == 'o') 18 | cout << "Yes" << endl; 19 | else 20 | cout << "No" << endl; 21 | return; 22 | } 23 | 24 | signed main() { 25 | ios::sync_with_stdio(false); 26 | int _ = 1; 27 | cout << setprecision(11); 28 | // cin >> _; 29 | while (_--) work(); 30 | return 0; 31 | } -------------------------------------------------------------------------------- /.github/workflows/clang-format.yml: -------------------------------------------------------------------------------- 1 | name: Run clang-format Linter 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | 9 | steps: 10 | - uses: actions/checkout@v4.1.7 11 | - uses: DoozyX/clang-format-lint-action@v0.17 12 | with: 13 | source: '.' 14 | extensions: 'cpp' 15 | clangFormatVersion: 14 16 | inplace: True 17 | - uses: EndBug/add-and-commit@v9.1.4 18 | with: 19 | author_name: Clang Robot 20 | author_email: i@macesuted.moe 21 | message: 'Committing clang-format changes' 22 | env: 23 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} -------------------------------------------------------------------------------- /AtCoder/abc207_b.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Macesuted (i@macesuted.moe) 3 | * @copyright Copyright (c) 2021 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | 9 | #define int long long 10 | 11 | void work(void) { 12 | int a, b, c, d; 13 | cin >> a >> b >> c >> d; 14 | int t = c * d - b; 15 | if (t <= 0) { 16 | cout << -1 << endl; 17 | return; 18 | } 19 | int ans = a / t; 20 | if (a % t) ans++; 21 | cout << ans << endl; 22 | return; 23 | } 24 | 25 | signed main() { 26 | ios::sync_with_stdio(false); 27 | int _ = 1; 28 | // cin >> _; 29 | while (_--) work(); 30 | return 0; 31 | } -------------------------------------------------------------------------------- /Codeforces/1560C.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Macesuted (i@macesuted.moe) 3 | * @copyright Copyright (c) 2021 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | 9 | #define int long long 10 | 11 | void work(void) { 12 | int n; 13 | cin >> n; 14 | int c = 0; 15 | while ((c + 1) * (c + 1) < n) c++; 16 | n -= c * c; 17 | if (n <= c + 1) 18 | cout << n << ' ' << c + 1 << endl; 19 | else 20 | cout << c + 1 << ' ' << 2 * c + 1 - n + 1 << endl; 21 | return; 22 | } 23 | 24 | signed main() { 25 | ios::sync_with_stdio(false); 26 | int _ = 1; 27 | cin >> _; 28 | while (_--) work(); 29 | return 0; 30 | } -------------------------------------------------------------------------------- /Codeforces/1566B.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Macesuted (i@macesuted.moe) 3 | * @copyright Copyright (c) 2021 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | 9 | #define int long long 10 | 11 | string str; 12 | 13 | void work(void) { 14 | cin >> str; 15 | int n = str.size(); 16 | str = "1" + str; 17 | int cnt = 0; 18 | for (register int i = 1; i <= n; i++) 19 | if (str[i] == '0' && str[i - 1] == '1') cnt++; 20 | cout << min(2LL, cnt) << endl; 21 | return; 22 | } 23 | 24 | signed main() { 25 | ios::sync_with_stdio(false); 26 | int _ = 1; 27 | cin >> _; 28 | while (_--) work(); 29 | return 0; 30 | } -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "aaron-bond.better-comments", 4 | "cschlosser.doxdocgen", 5 | "divyanshuagrawal.competitive-programming-helper", 6 | "donjayamanne.githistory", 7 | "equinusocio.vsc-material-theme", 8 | "llvm-vs-code-extensions.vscode-clangd", 9 | "ms-python.python", 10 | "ms-vscode.hexeditor", 11 | "mutantdino.resourcemonitor", 12 | "pdconsec.vscode-print", 13 | "pkief.material-icon-theme", 14 | "usernamehw.errorlens", 15 | "vadimcn.vscode-lldb", 16 | "yzhang.markdown-all-in-one", 17 | "zh9528.file-size", 18 | ] 19 | } -------------------------------------------------------------------------------- /Codeforces/1543B.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Macesuted (i@macesuted.moe) 3 | * @copyright Copyright (c) 2021 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | 9 | #define int long long 10 | 11 | void solve(void) { 12 | int n; 13 | cin >> n; 14 | int sum = 0; 15 | for (register int i = 1, t; i <= n; i++) { 16 | cin >> t; 17 | sum += t; 18 | } 19 | sum %= n; 20 | cout << sum * (n - sum) << endl; 21 | return; 22 | } 23 | 24 | signed main() { 25 | ios::sync_with_stdio(false); 26 | cout << setiosflags(ios::fixed) << setprecision(8); 27 | int _ = 1; 28 | cin >> _; 29 | while (_--) solve(); 30 | return 0; 31 | } -------------------------------------------------------------------------------- /Codeforces/1530A.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Macesuted (i@macesuted.moe) 3 | * @copyright Copyright (c) 2021 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | 9 | #define int long long 10 | 11 | #define maxn 100005 12 | 13 | string str; 14 | 15 | void work(void) { 16 | cin >> str; 17 | int answer = 0; 18 | for (register int i = 0; i < str.size(); i++) answer = max(answer, (int)(str[i] - '0')); 19 | cout << answer << endl; 20 | return; 21 | } 22 | 23 | signed main() { 24 | ios::sync_with_stdio(false); 25 | cout << setiosflags(ios::fixed) << setprecision(8); 26 | int _ = 1; 27 | cin >> _; 28 | while (_--) work(); 29 | return 0; 30 | } -------------------------------------------------------------------------------- /Codeforces/1579A.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Macesuted (i@macesuted.moe) 3 | * @copyright Copyright (c) 2021 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | 9 | #define int long long 10 | 11 | void work(void) { 12 | string s; 13 | cin >> s; 14 | int cnt[3] = {0, 0, 0}; 15 | for (auto i : s) cnt[i - 'A']++; 16 | if (cnt[1] == cnt[0] + cnt[2]) 17 | cout << "YES" << endl; 18 | else 19 | cout << "NO" << endl; 20 | return; 21 | } 22 | 23 | signed main() { 24 | ios::sync_with_stdio(false); 25 | cout << setiosflags(ios::fixed) << setprecision(11); 26 | int _ = 1; 27 | cin >> _; 28 | while (_--) work(); 29 | return 0; 30 | } -------------------------------------------------------------------------------- /Codeforces Gym/535265C.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 535265C.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-07-17 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define mod 1000000007 14 | 15 | stack S; 16 | 17 | int main() { 18 | int q; 19 | cin >> q; 20 | 21 | int64_t ans = 0; 22 | while (q--) { 23 | int t, v; 24 | cin >> t >> v; 25 | while (t--) ans = (ans + mod - (int64_t)S.top() * S.size() % mod) % mod, S.pop(); 26 | S.push(v), ans = (ans + (int64_t)S.top() * S.size() % mod) % mod; 27 | cout << ans << endl; 28 | } 29 | 30 | return 0; 31 | } -------------------------------------------------------------------------------- /Codeforces/1543A.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Macesuted (i@macesuted.moe) 3 | * @copyright Copyright (c) 2021 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | 9 | #define int long long 10 | 11 | void solve(void) { 12 | int x, y; 13 | cin >> x >> y; 14 | if (x < y) swap(x, y); 15 | int a = x - y; 16 | if (a == 0) 17 | cout << 0 << ' ' << 0 << endl; 18 | else 19 | cout << a << ' ' << min(x % a, a - x % a) << endl; 20 | return; 21 | } 22 | 23 | signed main() { 24 | ios::sync_with_stdio(false); 25 | cout << setiosflags(ios::fixed) << setprecision(8); 26 | int _ = 1; 27 | cin >> _; 28 | while (_--) solve(); 29 | return 0; 30 | } -------------------------------------------------------------------------------- /Nowcoder/108307H.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 108307H.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-08-14 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define endl '\n' 14 | 15 | void solve(void) { 16 | string s; 17 | cin >> s; 18 | 19 | if (s[0] == s[2]) return cout << "No" << endl, void(); 20 | if (s[1] == '-' && s[0] != '0') return cout << "No" << endl, void(); 21 | 22 | cout << "Yes" << endl; 23 | 24 | return; 25 | } 26 | 27 | int main() { 28 | ios::sync_with_stdio(false), cin.tie(nullptr); 29 | 30 | int _ = 1; 31 | cin >> _; 32 | while (_--) solve(); 33 | 34 | return 0; 35 | } -------------------------------------------------------------------------------- /QOJ/5422.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 5422.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-10-21 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define endl '\n' 14 | 15 | void solve(void) { 16 | string s; 17 | cin >> s; 18 | vector cnt(26); 19 | for (auto c : s) cnt[c - 'a']++; 20 | int ans = 0; 21 | for (int i = 0; i < 26; i++) ans = max(ans, cnt[i]); 22 | cout << s.size() - ans << endl; 23 | return; 24 | } 25 | 26 | int main() { 27 | ios::sync_with_stdio(false), cin.tie(nullptr); 28 | 29 | int _ = 1; 30 | cin >> _; 31 | while (_--) solve(); 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /Nowcoder/108330F.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 108330F.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-07-22 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define endl '\n' 14 | 15 | void solve(void) { 16 | int n, a, b; 17 | cin >> n >> a >> b; 18 | int t = n % (a + b), ans = 0; 19 | if (1 <= t && t <= a) ans = t, n -= t; 20 | if (n == 0) return cout << "Sayonara" << endl, void(); 21 | cout << ans << endl; 22 | return; 23 | } 24 | 25 | int main() { 26 | ios::sync_with_stdio(false), cin.tie(nullptr); 27 | 28 | int _ = 1; 29 | cin >> _; 30 | while (_--) solve(); 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /Codeforces Gym/102428M.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 102428M.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-07-25 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define maxn 1005 14 | 15 | int s[maxn]; 16 | 17 | int main() { 18 | ios::sync_with_stdio(false), cin.tie(nullptr); 19 | 20 | int n, m; 21 | cin >> n >> m; 22 | 23 | for (int i = 1; i <= n; i++) cin >> s[i]; 24 | 25 | int ans = 0; 26 | for (int i = 1; i <= n; i++) { 27 | int j = i; 28 | while (j + 1 <= n && s[j + 1] - s[j] <= m) j++; 29 | ans = max(ans, j - i + 1); 30 | } 31 | cout << ans << endl; 32 | 33 | return 0; 34 | } -------------------------------------------------------------------------------- /Codeforces/1573A.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Macesuted (i@macesuted.moe) 3 | * @copyright Copyright (c) 2021 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | 9 | #define int long long 10 | 11 | #define maxn 200005 12 | 13 | void work(void) { 14 | int n; 15 | string s; 16 | cin >> n >> s; 17 | int answer = 0; 18 | for (register int i = 0; i < s.size(); i++) { 19 | if (s[i] == '0') continue; 20 | answer += s[i] - '0'; 21 | if (i != s.size() - 1) answer++; 22 | } 23 | cout << answer << endl; 24 | return; 25 | } 26 | 27 | signed main() { 28 | ios::sync_with_stdio(false); 29 | int _ = 1; 30 | cin >> _; 31 | while (_--) work(); 32 | return 0; 33 | } -------------------------------------------------------------------------------- /HDOJ/6707.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 6707.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-07-18 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define maxn 100005 14 | 15 | bool use[maxn]; 16 | 17 | int a[maxn], b[maxn]; 18 | 19 | int main() { 20 | int n, m; 21 | cin >> n >> m; 22 | for (int i = 1; i <= n; i++) cin >> a[i]; 23 | for (int i = 1; i <= m; i++) cin >> b[i]; 24 | for (int i = m; i; i--) { 25 | if (use[b[i]]) continue; 26 | cout << b[i] << ' ', use[b[i]] = true; 27 | } 28 | for (int i = 1; i <= n; i++) 29 | if (!use[a[i]]) cout << a[i] << ' '; 30 | cout << endl; 31 | return 0; 32 | } -------------------------------------------------------------------------------- /AtCoder/arc120_a.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Macesuted (i@macesuted.moe) 3 | * @copyright Copyright (c) 2021 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | 9 | #define maxn 200005 10 | 11 | int a[maxn]; 12 | 13 | void work(void) { 14 | int n; 15 | cin >> n; 16 | for (register int i = 1; i <= n; i++) cin >> a[i]; 17 | long long answer = 0, maxx = 0, sum = 0; 18 | for (register int i = 1; i <= n; i++) { 19 | sum += a[i], maxx = max(maxx, 1LL * a[i]); 20 | answer += sum; 21 | cout << answer + maxx * i << endl; 22 | } 23 | return; 24 | } 25 | 26 | int main() { 27 | ios::sync_with_stdio(false); 28 | int _ = 1; 29 | while (_--) work(); 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /Codeforces/1594B.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Macesuted (i@macesuted.moe) 3 | * @copyright Copyright (c) 2021 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | 9 | #define int long long 10 | #define mod 1000000007 11 | 12 | typedef pair pii; 13 | 14 | void work(void) { 15 | int n, k; 16 | cin >> n >> k; 17 | int ans = 0; 18 | for (int i = 0, pow = 1; i < 32; i++, pow = pow * n % mod) 19 | if (k >> i & 1) ans = (ans + pow) % mod; 20 | cout << ans << endl; 21 | return; 22 | } 23 | 24 | signed main() { 25 | ios::sync_with_stdio(false); 26 | cout << setiosflags(ios::fixed) << setprecision(11); 27 | int _ = 1; 28 | cin >> _; 29 | while (_--) work(); 30 | return 0; 31 | } -------------------------------------------------------------------------------- /Codeforces/1593A.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Macesuted (i@macesuted.moe) 3 | * @copyright Copyright (c) 2021 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | 9 | #define int long long 10 | 11 | #define maxn 1000005 12 | 13 | void work(void) { 14 | int a, b, c, maxx; 15 | cin >> a >> b >> c; 16 | maxx = max({a, b, c}); 17 | cout << max({0LL, b - a + 1, c - a + 1}) << ' '; 18 | cout << max({0LL, a - b + 1, c - b + 1}) << ' '; 19 | cout << max({0LL, a - c + 1, b - c + 1}) << endl; 20 | return; 21 | } 22 | 23 | signed main() { 24 | ios::sync_with_stdio(false); 25 | cout << setiosflags(ios::fixed) << setprecision(11); 26 | int _ = 1; 27 | cin >> _; 28 | while (_--) work(); 29 | return 0; 30 | } -------------------------------------------------------------------------------- /QOJ/9917.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 9917.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-04-10 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define endl '\n' 14 | 15 | #define maxn 500005 16 | 17 | int a[maxn]; 18 | 19 | void solve(void) { 20 | int n, mv = 0; 21 | cin >> n; 22 | for (int i = 1; i <= n; i++) cin >> a[i], mv = max(mv, a[i]); 23 | for (int i = 1; i <= n; i++) 24 | if (a[i] == mv) cout << i << ' '; 25 | cout << endl; 26 | return; 27 | } 28 | 29 | int main() { 30 | ios::sync_with_stdio(false), cin.tie(nullptr); 31 | 32 | int _ = 1; 33 | cin >> _; 34 | while (_--) solve(); 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /Codeforces/1906M.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 1906M.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-09-12 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define maxn 200005 14 | 15 | int a[maxn]; 16 | 17 | void solve(void) { 18 | int n; 19 | cin >> n; 20 | int64_t sum = 0; 21 | for (int i = 1; i <= n; i++) cin >> a[i], sum += a[i]; 22 | int64_t ans = sum / 3; 23 | for (int i = 1; i <= n; i++) ans = min(ans, sum - a[i]); 24 | cout << ans << endl; 25 | return; 26 | } 27 | 28 | int main() { 29 | ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); 30 | 31 | int _ = 1; 32 | while (_--) solve(); 33 | 34 | return 0; 35 | } -------------------------------------------------------------------------------- /Codeforces/1594E1.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Macesuted (i@macesuted.moe) 3 | * @copyright Copyright (c) 2021 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | 9 | #define int long long 10 | 11 | #define maxn 200005 12 | #define mod 1000000007 13 | 14 | typedef pair pii; 15 | 16 | int f[maxn]; 17 | 18 | void work(void) { 19 | int n; 20 | cin >> n; 21 | n--; 22 | f[0] = 1; 23 | for (int i = 1; i <= n; i++) f[i] = 16 * f[i - 1] % mod * f[i - 1] % mod; 24 | cout << f[n] * 6 % mod << endl; 25 | return; 26 | } 27 | 28 | signed main() { 29 | ios::sync_with_stdio(false); 30 | cout << setiosflags(ios::fixed) << setprecision(11); 31 | int _ = 1; 32 | // cin >> _; 33 | while (_--) work(); 34 | return 0; 35 | } -------------------------------------------------------------------------------- /QOJ/9142.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 9142.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-09-03 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define endl '\n' 14 | 15 | #define maxn 200005 16 | 17 | int a[maxn]; 18 | 19 | void solve(void) { 20 | int n; 21 | cin >> n; 22 | for (int i = 1; i <= n; i++) cin >> a[i]; 23 | int64_t sum = 0; 24 | sort(a + 1, a + n + 1); 25 | for (int i = 1; i < n; i++) sum += a[i]; 26 | cout << sum << endl; 27 | return; 28 | } 29 | 30 | int main() { 31 | ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); 32 | 33 | int _ = 1; 34 | cin >> _; 35 | while (_--) solve(); 36 | 37 | return 0; 38 | } -------------------------------------------------------------------------------- /AtCoder/abc210_c.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Macesuted (i@macesuted.moe) 3 | * @copyright Copyright (c) 2021 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | 9 | #define int long long 10 | 11 | int a[300005]; 12 | 13 | map record; 14 | 15 | signed main() { 16 | ios::sync_with_stdio(false); 17 | int n, k; 18 | cin >> n >> k; 19 | for (register int i = 1; i <= n; i++) cin >> a[i]; 20 | for (register int i = 1; i <= k; i++) record[a[i]]++; 21 | int answer = record.size(); 22 | for (register int i = k + 1; i <= n; i++) { 23 | record[a[i]]++; 24 | if (!--record[a[i - k]]) record.erase(a[i - k]); 25 | answer = max(answer, (long long)record.size()); 26 | } 27 | cout << answer << endl; 28 | return 0; 29 | } -------------------------------------------------------------------------------- /Nowcoder/108217C.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 108217C.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-05-04 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define endl '\n' 14 | 15 | #define maxn 2000005 16 | 17 | string a[maxn]; 18 | 19 | void solve(void) { 20 | int n; 21 | cin >> n; 22 | for (int i = 1; i <= n; i++) cin >> a[i]; 23 | sort(a + 1, a + n + 1, [](const string& a, const string& b) { return a + b < b + a; }); 24 | for (int i = 1; i <= n; i++) cout << a[i]; 25 | cout << endl; 26 | return; 27 | } 28 | 29 | int main() { 30 | ios::sync_with_stdio(false), cin.tie(nullptr); 31 | 32 | int _ = 1; 33 | while (_--) solve(); 34 | 35 | return 0; 36 | } -------------------------------------------------------------------------------- /AtCoder/abc216_a.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Macesuted (i@macesuted.moe) 3 | * @copyright Copyright (c) 2021 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | 9 | #define int long long 10 | 11 | #define maxn 500005 12 | #define mod 998244353 13 | 14 | typedef pair pii; 15 | 16 | void work(void) { 17 | int x, y; 18 | scanf("%lld.%lld", &x, &y); 19 | if (0 <= y && y <= 2) 20 | printf("%lld-", x); 21 | else if (3 <= y && y <= 6) 22 | printf("%lld", x); 23 | else 24 | printf("%lld+", x); 25 | return; 26 | } 27 | 28 | signed main() { 29 | ios::sync_with_stdio(false); 30 | int _ = 1; 31 | // cin >> _; 32 | cout << setiosflags(ios::fixed) << setprecision(11); 33 | while (_--) work(); 34 | return 0; 35 | } -------------------------------------------------------------------------------- /HDOJ/7551.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 7551.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-08-19 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define maxn 200005 14 | 15 | int a[maxn], b[maxn]; 16 | 17 | void solve(void) { 18 | int n, m, k; 19 | int64_t sum = 0; 20 | cin >> n >> m >> k; 21 | for (int i = 1; i <= n; i++) cin >> a[i], sum += a[i] - 1; 22 | for (int i = 1; i <= n; i++) cin >> b[i]; 23 | cout << (min(sum, (int64_t)m - 1) < k ? "YES" : "NO") << endl; 24 | return; 25 | } 26 | 27 | int main() { 28 | ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); 29 | 30 | int _ = 1; 31 | cin >> _; 32 | while (_--) solve(); 33 | 34 | return 0; 35 | } -------------------------------------------------------------------------------- /Codeforces/1543D1.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Macesuted (i@macesuted.moe) 3 | * @copyright Copyright (c) 2021 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | 9 | #define int long long 10 | 11 | int ask(int x) { 12 | cout << x << endl; 13 | int t; 14 | cin >> t; 15 | return t; 16 | } 17 | 18 | void solve(void) { 19 | int n, k; 20 | cin >> n >> k; 21 | for (register int i = 0, pre = 0; i < n; i++) { 22 | int a = i ^ pre; 23 | int ret = ask(a); 24 | if (ret == 1) return; 25 | pre ^= a; 26 | } 27 | return; 28 | } 29 | 30 | signed main() { 31 | ios::sync_with_stdio(false); 32 | cout << setiosflags(ios::fixed) << setprecision(8); 33 | int _ = 1; 34 | cin >> _; 35 | while (_--) solve(); 36 | return 0; 37 | } -------------------------------------------------------------------------------- /HDOJ/7457.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 7457.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-07-26 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define maxn 1000005 14 | #define mod 998244353 15 | 16 | int f[maxn], g[maxn]; 17 | 18 | int Mod(int x) { return x >= mod ? x - mod : x; } 19 | 20 | int main() { 21 | ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); 22 | 23 | int n; 24 | cin >> n; 25 | 26 | f[1] = 1; 27 | for (int i = 1; i <= n; i++) 28 | for (int j = 1; j * i <= n; j++) f[i * j + 1] = Mod(f[i * j + 1] + f[i]), g[i * j] = Mod(g[i * j] + f[i]); 29 | 30 | for (int i = 1; i <= n; i++) cout << g[i] << ' '; 31 | cout << endl; 32 | 33 | return 0; 34 | } -------------------------------------------------------------------------------- /LibreOJ/6877.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 6877.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2023-03-05 5 | * 6 | * @copyright Copyright (c) 2023 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | void solve(void) { 20 | cout << "China" << endl; 21 | return; 22 | } 23 | 24 | bool mem2; 25 | 26 | int main() { 27 | ios::sync_with_stdio(false), cin.tie(nullptr); 28 | #ifdef LOCAL 29 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 30 | #endif 31 | 32 | int _ = 1; 33 | while (_--) solve(); 34 | 35 | #ifdef LOCAL 36 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 37 | #endif 38 | return 0; 39 | } -------------------------------------------------------------------------------- /Nowcoder/81605A.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 81605A.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-08-15 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | void solve(void) { 14 | string s; 15 | cin >> s; 16 | int cur = 0, rest = 0; 17 | for (int i = 0; i < 5; i++) 18 | if (s[i] == 'Y') 19 | cur++; 20 | else if (s[i] == '-') 21 | rest++; 22 | if (cur + rest < 4) return cout << -1 << endl, void(); 23 | if (cur >= 4) return cout << 1 << endl, void(); 24 | cout << 0 << endl; 25 | return; 26 | } 27 | 28 | int main() { 29 | ios::sync_with_stdio(false), cin.tie(nullptr); 30 | 31 | int _ = 1; 32 | while (_--) solve(); 33 | 34 | return 0; 35 | } -------------------------------------------------------------------------------- /Codeforces Gym/102465A.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 102465A.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-07-23 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define maxn 1000005 14 | 15 | bool f[maxn]; 16 | 17 | int main() { 18 | ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); 19 | 20 | int n, m, cnt = 0, ans = 0; 21 | cin >> n >> m; 22 | for (int i = 1, x; i <= m; i++) { 23 | cin >> x; 24 | for (int j = x; j <= n; j += x) { 25 | if (!f[j]) 26 | cnt++; 27 | else 28 | cnt--; 29 | f[j] = !f[j]; 30 | } 31 | ans = max(ans, cnt); 32 | } 33 | cout << ans << endl; 34 | return 0; 35 | } -------------------------------------------------------------------------------- /HDOJ/7454.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 7454.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-07-22 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define endl '\n' 14 | 15 | void solve(void) { 16 | map cnt; 17 | 18 | string s; 19 | cin >> s, s = ' ' + s; 20 | for (int i = 1; i <= 8; i++) cnt[s[i]]++; 21 | 22 | if (s[1] == s[5]) return cout << s[1] << endl, void(); 23 | if (cnt[s[1]] == cnt[s[5]]) return cout << 'N' << endl, void(); 24 | return cout << (cnt[s[1]] > cnt[s[5]] ? s[1] : s[5]) << endl, void(); 25 | } 26 | 27 | int main() { 28 | ios::sync_with_stdio(false), cin.tie(nullptr); 29 | 30 | int _; 31 | cin >> _; 32 | while (_--) solve(); 33 | 34 | return 0; 35 | } -------------------------------------------------------------------------------- /AtCoder/abc216_c.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Macesuted (i@macesuted.moe) 3 | * @copyright Copyright (c) 2021 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | 9 | #define int long long 10 | 11 | #define maxn 500005 12 | #define mod 998244353 13 | 14 | typedef pair pii; 15 | 16 | stack vec; 17 | 18 | void work(void) { 19 | int n; 20 | cin >> n; 21 | while (n) vec.push(n & 1), n >>= 1; 22 | while (!vec.empty()) { 23 | cout << "B"; 24 | if (vec.top()) cout << "A"; 25 | vec.pop(); 26 | } 27 | cout << endl; 28 | return; 29 | } 30 | 31 | signed main() { 32 | ios::sync_with_stdio(false); 33 | int _ = 1; 34 | // cin >> _; 35 | cout << setiosflags(ios::fixed) << setprecision(11); 36 | while (_--) work(); 37 | return 0; 38 | } -------------------------------------------------------------------------------- /HDOJ/7486.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 7486.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-08-02 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | 12 | using namespace std; 13 | 14 | #define endl '\n' 15 | 16 | bool solve(int a, int b, int c) { 17 | int cnt = a % 2 + b % 2 + c % 2; 18 | if (cnt == 1 || cnt == 2) return true; 19 | if (cnt == 3) return false; 20 | return solve(a / 2, b / 2, c / 2); 21 | } 22 | 23 | void solve(void) { 24 | int a, b, c; 25 | cin >> a >> b >> c; 26 | cout << (solve(a, b, c) ? "YES" : "NO") << endl; 27 | return; 28 | } 29 | 30 | int main() { 31 | ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); 32 | int T; 33 | cin >> T; 34 | while (T--) solve(); 35 | return 0; 36 | } -------------------------------------------------------------------------------- /QOJ/4837.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 4837.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-09-19 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define endl '\n' 14 | 15 | #define maxn 100005 16 | 17 | int64_t a[maxn]; 18 | 19 | void solve(void) { 20 | int n; 21 | cin >> n; 22 | int64_t pre = 0; 23 | for (int i = 1; i <= n; i++) cin >> a[i]; 24 | for (int i = 2; i <= n; i++) a[i] += a[i - 1]; 25 | for (int i = 1; i < n; i++) 26 | if (a[i] <= 0) return cout << "NO" << endl, void(); 27 | cout << "YES" << endl; 28 | return; 29 | } 30 | 31 | int main() { 32 | ios::sync_with_stdio(false), cin.tie(nullptr); 33 | 34 | int _ = 1; 35 | while (_--) solve(); 36 | 37 | return 0; 38 | } -------------------------------------------------------------------------------- /QOJ/9483.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 9483.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-10-22 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define maxn 300005 14 | 15 | int a[maxn], f[maxn]; 16 | 17 | void solve(void) { 18 | int n, k; 19 | cin >> n >> k; 20 | for (int i = 1; i <= n; i++) cin >> a[i], f[i] = a[i]; 21 | for (int i = n - k; i; i--) f[i] = max(f[i], f[i + k]); 22 | for (int i = 1; i <= n; i++) { 23 | while (f[i] != a[i]) i += k; 24 | cout << a[i] << ' '; 25 | } 26 | cout << endl; 27 | return; 28 | } 29 | 30 | int main() { 31 | ios::sync_with_stdio(false), cin.tie(nullptr); 32 | 33 | int _ = 1; 34 | while (_--) solve(); 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /AtCoder/abc227_a.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file abc227_a.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2021-11-13 5 | * 6 | * @copyright Copyright (c) 2021 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | typedef pair pii; 14 | 15 | bool mem1; 16 | 17 | void solve(void) { 18 | int n, k, a; 19 | cin >> n >> k >> a; 20 | k %= n; 21 | a = (a - 1 + k - 1) % n + 1; 22 | cout << a << endl; 23 | return; 24 | } 25 | 26 | bool mem2; 27 | 28 | int main() { 29 | #ifdef LOCAL 30 | cerr << "Memory: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 31 | #endif 32 | 33 | int _ = 1; 34 | while (_--) solve(); 35 | 36 | #ifdef LOCAL 37 | cerr << "Time: " << clock() * 1000. / CLOCKS_PER_SEC << "ms" << endl; 38 | #endif 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /Codeforces/1593D1.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Macesuted (i@macesuted.moe) 3 | * @copyright Copyright (c) 2021 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | 9 | #define int long long 10 | 11 | #define maxn 1005 12 | 13 | int gcd(int x, int y) { return y == 0 ? x : gcd(y, x % y); } 14 | 15 | int a[maxn]; 16 | 17 | void work(void) { 18 | int n, ans = 0; 19 | cin >> n; 20 | for (int i = 1; i <= n; i++) cin >> a[i]; 21 | sort(a + 1, a + n + 1); 22 | for (int i = 2; i <= n; i++) ans = gcd(ans, a[i] - a[i - 1]); 23 | cout << (ans == 0 ? -1 : ans) << endl; 24 | return; 25 | } 26 | 27 | signed main() { 28 | ios::sync_with_stdio(false); 29 | cout << setiosflags(ios::fixed) << setprecision(11); 30 | int _ = 1; 31 | cin >> _; 32 | while (_--) work(); 33 | return 0; 34 | } -------------------------------------------------------------------------------- /HDOJ/7491.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 7491.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-08-02 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | 12 | using namespace std; 13 | 14 | #define endl '\n' 15 | #define mod 998244353 16 | 17 | int qpow(int a, int b) { 18 | int res = 1; 19 | while (b) { 20 | if (b & 1) res = 1ll * res * a % mod; 21 | a = 1ll * a * a % mod; 22 | b >>= 1; 23 | } 24 | return res; 25 | } 26 | 27 | void solve(void) { 28 | int n; 29 | cin >> n; 30 | cout << qpow(2, n - (n % 3 == 2)) << endl; 31 | return; 32 | } 33 | 34 | int main() { 35 | ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); 36 | int T; 37 | cin >> T; 38 | while (T--) solve(); 39 | return 0; 40 | } -------------------------------------------------------------------------------- /QOJ/7747.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 7747.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-11-07 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define endl '\n' 14 | 15 | void solve(void) { 16 | int n; 17 | cin >> n; 18 | bool rest = false; 19 | int v = 0; 20 | for (int i = 1, x; i <= n; i++) { 21 | cin >> x; 22 | if (v % 2) v--, rest = true; 23 | v = v / 2 + x; 24 | if (v == 0 && !rest) 25 | cout << '0'; 26 | else 27 | cout << "-+"[v >= 0]; 28 | } 29 | cout << endl; 30 | return; 31 | } 32 | 33 | int main() { 34 | ios::sync_with_stdio(false), cin.tie(nullptr); 35 | 36 | int _ = 1; 37 | while (_--) solve(); 38 | 39 | return 0; 40 | } -------------------------------------------------------------------------------- /HDOJ/6709.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 6709.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-07-18 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | #include 12 | using namespace std; 13 | 14 | #define maxn 100005 15 | 16 | int a[maxn]; 17 | 18 | void solve(void) { 19 | int n, k; 20 | scanf("%d%d", &n, &k); 21 | long long ans = k, tot = n - 1; 22 | for (int i = 1; i <= n; i++) scanf("%d", a + i), ans += a[i], tot -= a[i] / k, a[i] = k - a[i] % k; 23 | sort(a + 1, a + n + 1); 24 | for (int i = 1; i <= n && tot > 0; i++) tot--, ans += a[i]; 25 | while (tot > 0) tot--, ans += k; 26 | printf("%lld\n", ans); 27 | return; 28 | } 29 | 30 | int main() { 31 | int _; 32 | scanf("%d", &_); 33 | while (_--) solve(); 34 | return 0; 35 | } -------------------------------------------------------------------------------- /Codeforces/1593C.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Macesuted (i@macesuted.moe) 3 | * @copyright Copyright (c) 2021 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | 9 | #define int long long 10 | 11 | #define maxn 400005 12 | 13 | int a[maxn]; 14 | int n, k; 15 | 16 | void work(void) { 17 | cin >> n >> k; 18 | for (int i = 1; i <= k; i++) cin >> a[i]; 19 | sort(a + 1, a + k + 1); 20 | int rest = n - 1, answer = 0; 21 | for (int i = k; i; i--) { 22 | rest -= n - a[i]; 23 | if (rest < 0) break; 24 | answer++; 25 | } 26 | cout << answer << endl; 27 | return; 28 | } 29 | 30 | signed main() { 31 | ios::sync_with_stdio(false); 32 | cout << setiosflags(ios::fixed) << setprecision(11); 33 | int _ = 1; 34 | cin >> _; 35 | while (_--) work(); 36 | return 0; 37 | } -------------------------------------------------------------------------------- /Nowcoder/231167.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | bool mem1; 5 | 6 | #define maxn 105 7 | 8 | int m[maxn], lef[maxn], rig[maxn]; 9 | 10 | bool mem2; 11 | 12 | int main() { 13 | cerr << "Memory: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 14 | ios::sync_with_stdio(false); 15 | int n; 16 | while (cin >> n) { 17 | int len = 2 * n - 1; 18 | for (int i = 1; i < n; i++) { 19 | for (int j = 1; j < i; j++) cout << ' '; 20 | cout << 'V'; 21 | for (int j = i + 1; j + i <= len; j++) cout << ' '; 22 | cout << 'V' << endl; 23 | } 24 | for (int i = 1; i < n; i++) cout << ' '; 25 | cout << 'V' << endl; 26 | } 27 | cerr << "Time: " << clock() * 1000. / CLOCKS_PER_SEC << "ms" << endl; 28 | return 0; 29 | } -------------------------------------------------------------------------------- /Codeforces/1023B.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 1023B.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2021-11-09 5 | * 6 | * @copyright Copyright (c) 2021 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | typedef pair pii; 14 | 15 | bool mem1; 16 | 17 | void solve(void) { 18 | long long n, k; 19 | cin >> n >> k; 20 | long long l = max(1LL, k - n), r = (k - 1) / 2; 21 | cout << max(0LL, r - l + 1) << endl; 22 | return; 23 | } 24 | 25 | bool mem2; 26 | 27 | int main() { 28 | #ifdef LOCAL 29 | cerr << "Memory: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 30 | #endif 31 | 32 | int _ = 1; 33 | while (_--) solve(); 34 | 35 | #ifdef LOCAL 36 | cerr << "Time: " << clock() * 1000. / CLOCKS_PER_SEC << "ms" << endl; 37 | #endif 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /HDOJ/1176-1009.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 1176-1009.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-08-01 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define endl '\n' 14 | 15 | #define maxn 200005 16 | 17 | int a[maxn], p[maxn], b[maxn]; 18 | 19 | void solve(void) { 20 | int n; 21 | cin >> n; 22 | for (int i = 1; i <= n; i++) cin >> a[i], p[a[i]] = i; 23 | for (int i = 1; i <= n; i++) cin >> b[i]; 24 | int ans = 1; 25 | for (int i = 2; i <= n; i++) ans += (p[b[i]] != p[b[i - 1]] + 1); 26 | cout << ans << endl; 27 | return; 28 | } 29 | 30 | int main() { 31 | ios::sync_with_stdio(false), cin.tie(nullptr); 32 | 33 | int _ = 1; 34 | cin >> _; 35 | while (_--) solve(); 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /LibreOJ/2875.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 2875.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2022-03-28 5 | * 6 | * @copyright Copyright (c) 2022 7 | * 8 | */ 9 | 10 | #include "ramen.h" 11 | // 12 | #include 13 | 14 | using namespace std; 15 | 16 | #define maxn 405 17 | 18 | int id[maxn]; 19 | 20 | void Ramen(int n) { 21 | for (int i = 0; i < n; i++) id[i] = i; 22 | if (n & 1) id[n] = n - 1, n++; 23 | for (int i = 0; i < n; i += 2) 24 | if (id[i] != id[i + 1] && Compare(id[i], id[i + 1]) == -1) swap(id[i], id[i + 1]); 25 | int maxp = id[0], minp = id[1]; 26 | for (int i = 2; i < n; i += 2) 27 | if (Compare(id[i], maxp) == 1) maxp = id[i]; 28 | for (int i = 3; i < n; i += 2) 29 | if (Compare(id[i], minp) == -1) minp = id[i]; 30 | Answer(minp, maxp); 31 | return; 32 | } -------------------------------------------------------------------------------- /Codeforces/1542A.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Macesuted (i@macesuted.moe) 3 | * @copyright Copyright (c) 2021 4 | */ 5 | #include 6 | using namespace std; 7 | 8 | #define int long long 9 | 10 | typedef pair pii; 11 | 12 | void solve(void) { 13 | int n; 14 | cin >> n; 15 | int odd = 0, even = 0; 16 | for (register int i = 1; i <= 2 * n; i++) { 17 | int t; 18 | cin >> t; 19 | if (t & 1) 20 | odd++; 21 | else 22 | even++; 23 | } 24 | if (odd == even) 25 | puts("Yes"); 26 | else 27 | puts("No"); 28 | return; 29 | } 30 | 31 | signed main() { 32 | ios::sync_with_stdio(false); 33 | cout << setiosflags(ios::fixed) << setprecision(3); 34 | int _ = 1; 35 | cin >> _; 36 | while (_--) solve(); 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /Luogu/P10678.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file P10678.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-06-30 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | void solve(void) { 20 | string s, v; 21 | cin >> s >> v; 22 | cout << s[0] << v << endl; 23 | return; 24 | } 25 | 26 | bool mem2; 27 | 28 | int main() { 29 | ios::sync_with_stdio(false), cin.tie(nullptr); 30 | #ifdef LOCAL 31 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 32 | #endif 33 | 34 | int _ = 1; 35 | while (_--) solve(); 36 | 37 | #ifdef LOCAL 38 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 39 | #endif 40 | return 0; 41 | } -------------------------------------------------------------------------------- /Codeforces Gym/105481B.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 105481B.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-01-06 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | #include 10 | using namespace std; 11 | 12 | #ifndef LOCAL 13 | #define endl '\n' 14 | #endif 15 | 16 | bool mem1; 17 | 18 | void solve(void) { 19 | string s; 20 | cin >> s; 21 | cout << s[2] << s[1] << s[0] << endl; 22 | return; 23 | } 24 | 25 | bool mem2; 26 | 27 | int main() { 28 | ios::sync_with_stdio(false), cin.tie(nullptr); 29 | #ifdef LOCAL 30 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 31 | #endif 32 | 33 | int _ = 1; 34 | while (_--) solve(); 35 | 36 | #ifdef LOCAL 37 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 38 | #endif 39 | return 0; 40 | } -------------------------------------------------------------------------------- /Codeforces/1542B.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Macesuted (i@macesuted.moe) 3 | * @copyright Copyright (c) 2021 4 | */ 5 | #include 6 | using namespace std; 7 | 8 | #define int long long 9 | #define mod 1000000007 10 | 11 | typedef pair pii; 12 | 13 | int gcd(int x, int y) { return y ? gcd(y, x % y) : x; } 14 | 15 | void solve(void) { 16 | int n, a, b; 17 | cin >> n >> a >> b; 18 | for (register int i = 0, p = 1; i <= 31 && p <= n; i++, p *= a) { 19 | int t = n - p; 20 | if (t % b != 0) continue; 21 | puts("Yes"); 22 | return; 23 | } 24 | puts("No"); 25 | return; 26 | } 27 | 28 | signed main() { 29 | ios::sync_with_stdio(false); 30 | cout << setiosflags(ios::fixed) << setprecision(3); 31 | int _ = 1; 32 | cin >> _; 33 | while (_--) solve(); 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /Nowcoder/81602I.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 81602I.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-08-06 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define endl '\n' 14 | 15 | void solve(void) { 16 | int m, k, h; 17 | cin >> m >> k >> h; 18 | if (k == m) return cout << min(h, m) << endl, void(); 19 | int l = 0, r = h; 20 | while (l + 1 < r) { 21 | int64_t mid = (l + r) >> 1, tot = mid; 22 | if (mid >= m) tot += ((mid - m) / (m - k) + 1) * k; 23 | (tot >= h ? r : l) = mid; 24 | } 25 | cout << r << endl; 26 | return; 27 | } 28 | 29 | int main() { 30 | ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); 31 | 32 | int _; 33 | cin >> _; 34 | while (_--) solve(); 35 | 36 | return 0; 37 | } -------------------------------------------------------------------------------- /Codeforces/2068J.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 2068J.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-04-24 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define endl '\n' 14 | 15 | void solve(void) { 16 | int n; 17 | string s; 18 | cin >> n >> s; 19 | int cnt[2] = {0, 0}; 20 | for (int i = 0; i < n; i++) cnt[s[i] == 'R']++; 21 | if (cnt[0] & 1) return cout << "NO" << endl, void(); 22 | for (int i = 0; i < (cnt[0] >> 1); i++) 23 | if (s[i] == 'R' || s[s.size() - 1 - i] == 'W') return cout << "NO" << endl, void(); 24 | cout << "YES" << endl; 25 | return; 26 | } 27 | 28 | int main() { 29 | ios::sync_with_stdio(false), cin.tie(nullptr); 30 | 31 | int _ = 1; 32 | cin >> _; 33 | while (_--) solve(); 34 | 35 | return 0; 36 | } -------------------------------------------------------------------------------- /QOJ/11222.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 11222.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-10-19 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define endl '\n' 14 | 15 | void solve(void) { 16 | int n; 17 | cin >> n; 18 | cout << "YES" << endl; 19 | for (int i = 1; i <= n; i++) 20 | for (int j = i; j <= n; j++) { 21 | cout << i << ' ' << j << ' '; 22 | cout << 1 << ' ' << j << ' ' << i << ' '; 23 | cout << 2 << ' ' << j << ' ' << i << endl; 24 | } 25 | return; 26 | } 27 | 28 | int main() { 29 | ios::sync_with_stdio(false), cin.tie(nullptr); 30 | 31 | int _ = 1; 32 | cin >> _; 33 | for (int i = 1; i <= _; i++) cout << "Case #" << i << ":" << endl, solve(); 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /AtCoder/abc210_e.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Macesuted (i@macesuted.moe) 3 | * @copyright Copyright (c) 2021 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | 9 | #define int long long 10 | 11 | typedef pair pii; 12 | 13 | pii a[100005]; 14 | 15 | int gcd(int x, int y) { return y == 0 ? x : gcd(y, x % y); } 16 | 17 | signed main() { 18 | ios::sync_with_stdio(false); 19 | int n, m; 20 | cin >> n >> m; 21 | for (register int i = 1; i <= m; i++) cin >> a[i].second >> a[i].first; 22 | sort(a + 1, a + m + 1); 23 | int answer = 0; 24 | for (register int i = 1; n > 1 && i <= m; i++) { 25 | int tn = gcd(n, a[i].second); 26 | answer += (n - tn) * a[i].first; 27 | n = tn; 28 | } 29 | if (n > 1) 30 | cout << -1 << endl; 31 | else 32 | cout << answer << endl; 33 | return 0; 34 | } -------------------------------------------------------------------------------- /Codeforces/1748A.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 1748A.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2022-11-12 5 | * 6 | * @copyright Copyright (c) 2022 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | void solve(void) { 20 | int n; 21 | cin >> n; 22 | cout << n / 2 + (n % 2 > 0) << endl; 23 | return; 24 | } 25 | 26 | bool mem2; 27 | 28 | int main() { 29 | ios::sync_with_stdio(false), cin.tie(nullptr); 30 | #ifdef LOCAL 31 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 32 | #endif 33 | 34 | int _ = 1; 35 | cin >> _; 36 | while (_--) solve(); 37 | 38 | #ifdef LOCAL 39 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 40 | #endif 41 | return 0; 42 | } -------------------------------------------------------------------------------- /HDOJ/7440.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 7440.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-07-19 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | int cnt[2]; 14 | 15 | void solve(void) { 16 | int n, k; 17 | cin >> n >> k; 18 | int64_t ans = 1; 19 | for (int i = 0; i < k; i++) ans *= cnt[n >> i & 1]; 20 | cout << ans << endl; 21 | return; 22 | } 23 | 24 | int main() { 25 | ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); 26 | 27 | cnt[0] = cnt[1] = 0; 28 | for (int a = 0; a < 2; a++) 29 | for (int b = 0; b < 2; b++) 30 | for (int c = 0; c < 2; c++) 31 | for (int d = 0; d < 2; d++) cnt[((a & b) ^ c) | d]++; 32 | 33 | int _; 34 | cin >> _; 35 | while (_--) solve(); 36 | return 0; 37 | } -------------------------------------------------------------------------------- /Nowcoder/231376.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #define mod 998244353 5 | #define maxn 1000005 6 | 7 | long long fac[maxn]; 8 | 9 | long long Pow(long long a, long long x) { 10 | long long ans = 1; 11 | while (x) { 12 | if (x & 1) ans = ans * a % mod; 13 | a = a * a % mod, x >>= 1; 14 | } 15 | return ans; 16 | } 17 | 18 | void solve(void) { 19 | int n, k; 20 | cin >> n >> k; 21 | long long ans = fac[k - 1]; 22 | if (n - k > 0) ans = ans * k % mod; 23 | if (n - k > 1) ans = ans * Pow(n, n - k - 1) % mod; 24 | cout << ans << endl; 25 | return; 26 | } 27 | 28 | int main() { 29 | fac[0] = 1; 30 | for (int i = 1; i < maxn; i++) fac[i] = fac[i - 1] * i % mod; 31 | ios::sync_with_stdio(false); 32 | int _; 33 | cin >> _; 34 | while (_--) solve(); 35 | return 0; 36 | } -------------------------------------------------------------------------------- /QOJ/10868.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 10868.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-10-10 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define endl '\n' 14 | 15 | #define maxn 1000005 16 | 17 | int f[maxn]; 18 | 19 | void solve(void) { 20 | int n; 21 | string s; 22 | cin >> n >> s; 23 | for (int i = 1; i <= n; i++) f[i] = f[i - 1] + (s[i - 1] == 'H'); 24 | 25 | for (int i = 1; i <= n; i++) { 26 | int p = 0, ans = 0; 27 | while (i + f[p] <= n && p < i + f[p]) p = i + f[p], ans++; 28 | cout << ans << ' '; 29 | } 30 | cout << endl; 31 | 32 | return; 33 | } 34 | 35 | int main() { 36 | ios::sync_with_stdio(false), cin.tie(nullptr); 37 | 38 | int _ = 1; 39 | while (_--) solve(); 40 | 41 | return 0; 42 | } -------------------------------------------------------------------------------- /Codeforces Gym/104396I.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 104396I.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-07-24 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | void solve(void) { 20 | int m, n; 21 | cin >> m >> n; 22 | cout << m - n + 1 << endl; 23 | return; 24 | } 25 | 26 | bool mem2; 27 | 28 | int main() { 29 | ios::sync_with_stdio(false), cin.tie(nullptr); 30 | #ifdef LOCAL 31 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 32 | #endif 33 | 34 | int _ = 1; 35 | cin >> _; 36 | while (_--) solve(); 37 | 38 | #ifdef LOCAL 39 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 40 | #endif 41 | return 0; 42 | } -------------------------------------------------------------------------------- /Codeforces/1987A.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 1987A.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-06-30 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | void solve(void) { 20 | int n, k; 21 | cin >> n >> k; 22 | cout << (n - 1) * k + 1 << endl; 23 | return; 24 | } 25 | 26 | bool mem2; 27 | 28 | int main() { 29 | ios::sync_with_stdio(false), cin.tie(nullptr); 30 | #ifdef LOCAL 31 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 32 | #endif 33 | 34 | int _ = 1; 35 | cin >> _; 36 | while (_--) solve(); 37 | 38 | #ifdef LOCAL 39 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 40 | #endif 41 | return 0; 42 | } -------------------------------------------------------------------------------- /AtCoder/abc216_b.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Macesuted (i@macesuted.moe) 3 | * @copyright Copyright (c) 2021 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | 9 | #define int long long 10 | 11 | #define maxn 500005 12 | #define mod 998244353 13 | 14 | typedef pair pii; 15 | 16 | map > record; 17 | 18 | void work(void) { 19 | int n; 20 | cin >> n; 21 | for (register int i = 1; i <= n; i++) { 22 | string a, b; 23 | cin >> a >> b; 24 | if (record[a].count(b)) return cout << "Yes" << endl, void(); 25 | record[a].insert(b); 26 | } 27 | cout << "No" << endl; 28 | return; 29 | } 30 | 31 | signed main() { 32 | ios::sync_with_stdio(false); 33 | int _ = 1; 34 | // cin >> _; 35 | cout << setiosflags(ios::fixed) << setprecision(11); 36 | while (_--) work(); 37 | return 0; 38 | } -------------------------------------------------------------------------------- /AtCoder/arc203_a.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file arc203_a.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-08-03 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | void solve(void) { 20 | int64_t n, m; 21 | cin >> n >> m; 22 | cout << n * (m / 2) + (m % 2) << endl; 23 | return; 24 | } 25 | 26 | bool mem2; 27 | 28 | int main() { 29 | ios::sync_with_stdio(false), cin.tie(nullptr); 30 | #ifdef LOCAL 31 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 32 | #endif 33 | 34 | int _ = 1; 35 | cin >> _; 36 | while (_--) solve(); 37 | 38 | #ifdef LOCAL 39 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 40 | #endif 41 | return 0; 42 | } -------------------------------------------------------------------------------- /Codeforces Gym/102428K.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 102428K.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-07-25 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | vector a, ans; 14 | 15 | int main() { 16 | ios::sync_with_stdio(false), cin.tie(nullptr); 17 | 18 | string s; 19 | cin >> s; 20 | int n = s.size(); 21 | s = ' ' + s; 22 | 23 | for (int i = 1; i < n; i++) 24 | if (s[i] != s[i + 1]) a.push_back(i * 2 + 1); 25 | 26 | ans.push_back(s.back() == 'H' ? +1 : -1); 27 | for (auto i : a) { 28 | ans.push_back(0); 29 | for (int j = (int)ans.size() - 2; ~j; j--) ans[j + 1] -= ans[j] * i; 30 | } 31 | 32 | cout << ans.size() - 1 << endl; 33 | for (auto i : ans) cout << i << ' '; 34 | cout << endl; 35 | 36 | return 0; 37 | } -------------------------------------------------------------------------------- /Codeforces Gym/105631A.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 105631A.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-01-03 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | void solve(void) { 20 | int x, y, z; 21 | cin >> x >> y >> z; 22 | cout << min({x / 2, y, z}) << endl; 23 | return; 24 | } 25 | 26 | bool mem2; 27 | 28 | int main() { 29 | ios::sync_with_stdio(false), cin.tie(nullptr); 30 | #ifdef LOCAL 31 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 32 | #endif 33 | 34 | int _ = 1; 35 | cin >> _; 36 | while (_--) solve(); 37 | 38 | #ifdef LOCAL 39 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 40 | #endif 41 | return 0; 42 | } -------------------------------------------------------------------------------- /Codeforces Gym/101808A.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 101808A.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-07-21 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | void solve(void) { 20 | int64_t R, r; 21 | cin >> R >> r; 22 | cout << 1 + !(R * R > 2 * r * r) << endl; 23 | return; 24 | } 25 | 26 | bool mem2; 27 | 28 | int main() { 29 | ios::sync_with_stdio(false), cin.tie(nullptr); 30 | #ifdef LOCAL 31 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 32 | #endif 33 | 34 | int _ = 1; 35 | cin >> _; 36 | while (_--) solve(); 37 | 38 | #ifdef LOCAL 39 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 40 | #endif 41 | return 0; 42 | } -------------------------------------------------------------------------------- /Nowcoder/248247.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 248247.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2023-02-16 5 | * 6 | * @copyright Copyright (c) 2023 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | void solve(void) { 20 | int a, b, c, d; 21 | cin >> a >> b >> c >> d, a |= b | c | d; 22 | cout << 4 * a << endl; 23 | return; 24 | } 25 | 26 | bool mem2; 27 | 28 | int main() { 29 | ios::sync_with_stdio(false), cin.tie(nullptr); 30 | #ifdef LOCAL 31 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 32 | #endif 33 | 34 | int _ = 1; 35 | cin >> _; 36 | while (_--) solve(); 37 | 38 | #ifdef LOCAL 39 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 40 | #endif 41 | return 0; 42 | } -------------------------------------------------------------------------------- /HDOJ/7535.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 7535.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-08-19 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define endl '\n' 14 | 15 | #define maxn 200005 16 | 17 | int a[maxn], b[maxn]; 18 | 19 | bool solve(void) { 20 | int n; 21 | cin >> n; 22 | for (int i = 1; i <= n; i++) cin >> a[i]; 23 | for (int i = 1; i <= n; i++) cin >> b[i]; 24 | sort(a + 1, a + n + 1), sort(b + 1, b + n + 1); 25 | int cnt = 0; 26 | for (int i = 1; i < n; i++) cnt += (a[i] == a[i + 1]); 27 | if (cnt == 0) return false; 28 | return true; 29 | } 30 | 31 | int main() { 32 | ios::sync_with_stdio(false), cin.tie(nullptr); 33 | 34 | int _ = 1; 35 | cin >> _; 36 | while (_--) cout << (solve() ? "shuishui" : "sha7dow") << endl; 37 | 38 | return 0; 39 | } -------------------------------------------------------------------------------- /AtCoder/abc227_c.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file abc227_c.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2021-11-13 5 | * 6 | * @copyright Copyright (c) 2021 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | typedef pair pii; 14 | 15 | bool mem1; 16 | 17 | void solve(void) { 18 | long long n, ans = 0; 19 | cin >> n; 20 | for (long long i = 1; i * i * i <= n; i++) 21 | for (long long j = i; i * j * j <= n; j++) ans += n / (i * j) - j + 1; 22 | cout << ans << endl; 23 | return; 24 | } 25 | 26 | bool mem2; 27 | 28 | int main() { 29 | #ifdef LOCAL 30 | cerr << "Memory: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 31 | #endif 32 | 33 | int _ = 1; 34 | while (_--) solve(); 35 | 36 | #ifdef LOCAL 37 | cerr << "Time: " << clock() * 1000. / CLOCKS_PER_SEC << "ms" << endl; 38 | #endif 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /Codeforces Gym/104772A.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 104772A.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-07-02 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | void solve(void) { 20 | int a[4]; 21 | for (int i = 0; i < 4; i++) cin >> a[i]; 22 | sort(a, a + 4); 23 | cout << a[0] * a[2] << endl; 24 | return; 25 | } 26 | 27 | bool mem2; 28 | 29 | int main() { 30 | ios::sync_with_stdio(false), cin.tie(nullptr); 31 | #ifdef LOCAL 32 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 33 | #endif 34 | 35 | int _ = 1; 36 | while (_--) solve(); 37 | 38 | #ifdef LOCAL 39 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 40 | #endif 41 | return 0; 42 | } -------------------------------------------------------------------------------- /Codeforces/1542C.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Macesuted (i@macesuted.moe) 3 | * @copyright Copyright (c) 2021 4 | */ 5 | #include 6 | using namespace std; 7 | 8 | #define int long long 9 | #define mod 1000000007 10 | 11 | typedef pair pii; 12 | 13 | int gcd(int x, int y) { return y ? gcd(y, x % y) : x; } 14 | 15 | void solve(void) { 16 | int n; 17 | cin >> n; 18 | int pre = 1, answer = 0; 19 | for (register int i = 2; i <= 43 && pre <= n; i++) { 20 | answer = (answer + i * ((n / pre) % mod + mod - (n / (i / gcd(i, pre) * pre)) % mod)) % mod; 21 | pre = pre / gcd(pre, i) * i; 22 | } 23 | cout << answer << endl; 24 | return; 25 | } 26 | 27 | signed main() { 28 | ios::sync_with_stdio(false); 29 | cout << setiosflags(ios::fixed) << setprecision(3); 30 | int _ = 1; 31 | cin >> _; 32 | while (_--) solve(); 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /HDOJ/6954.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #define int long long 5 | 6 | bool mem1; 7 | 8 | #define maxn 10000005 9 | #define mod 998244353 10 | 11 | vector prime; 12 | bool vis[maxn]; 13 | 14 | void init(void) { 15 | for (int i = 2; i < maxn; i++) { 16 | if (!vis[i]) prime.push_back(i); 17 | for (auto j : prime) { 18 | if (i * j >= maxn) break; 19 | vis[i * j] = true; 20 | if (i % j == 0) break; 21 | } 22 | } 23 | return; 24 | } 25 | void solve(void) { 26 | long long n, ans = 0; 27 | cin >> n; 28 | for (int i = 3; i <= n; i++) ans += i * (1 + !vis[i]); 29 | cout << ans << endl; 30 | return; 31 | } 32 | 33 | bool mem2; 34 | 35 | signed main() { 36 | ios::sync_with_stdio(false); 37 | init(); 38 | int _ = 1; 39 | cin >> _; 40 | while (_--) solve(); 41 | return 0; 42 | } -------------------------------------------------------------------------------- /HDOJ/7055.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #define int long long 5 | 6 | bool mem1; 7 | 8 | #define maxn 100005 9 | #define mod 998244353 10 | 11 | string s; 12 | 13 | vector pos[26]; 14 | 15 | void solve(void) { 16 | cin >> s; 17 | int n = s.size(); 18 | s = ' ' + s; 19 | for (int i = 1; i <= n; i++) pos[s[i] - 'a'].push_back(i); 20 | long long answer = 0; 21 | for (int t = 0; t < 26; t++) { 22 | long long sum = 0; 23 | for (auto i : pos[t]) sum += n - i + 1; 24 | for (auto i : pos[t]) sum -= n - i + 1, answer = (answer + i * sum * 2 + i * (n - i + 1)) % mod; 25 | pos[t].clear(); 26 | } 27 | cout << answer << endl; 28 | return; 29 | } 30 | 31 | bool mem2; 32 | 33 | signed main() { 34 | ios::sync_with_stdio(false); 35 | int _ = 1; 36 | cin >> _; 37 | while (_--) solve(); 38 | return 0; 39 | } -------------------------------------------------------------------------------- /QOJ/7585.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 7585.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-09-10 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define endl '\n' 14 | 15 | void solve(void) { 16 | int64_t k; 17 | int m; 18 | cin >> k >> m; 19 | 20 | int64_t ans = INT64_MAX; 21 | for (int l = 1; l <= 800; l++) { 22 | int64_t n = k ^ l, x = n + l; 23 | int cnt = 0; 24 | for (int64_t i = n + 1; i < x; i++) cnt += (gcd(i, n) == 1); 25 | if (cnt == m - 1 && gcd(x, n) == 1) ans = min(ans, n); 26 | } 27 | 28 | cout << (ans == INT64_MAX ? -1 : ans) << endl; 29 | 30 | return; 31 | } 32 | 33 | int main() { 34 | ios::sync_with_stdio(false), cin.tie(nullptr); 35 | 36 | int _ = 1; 37 | cin >> _; 38 | while (_--) solve(); 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /HDOJ/7514.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 7514.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-08-09 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define maxn 100005 14 | 15 | int a[maxn]; 16 | 17 | void solve(void) { 18 | int n, x, k; 19 | cin >> n >> x >> k; 20 | for (int i = 1; i <= n; i++) cin >> a[i]; 21 | k = min(k, n); 22 | priority_queue, greater> que; 23 | for (int i = 1; i <= k; i++) que.push(a[i]); 24 | int ans = k; 25 | while (ans <= n && x > 0) { 26 | que.push(a[++ans]); 27 | x -= que.top(), que.pop(); 28 | } 29 | cout << ans - 1 << endl; 30 | return; 31 | } 32 | 33 | int main() { 34 | ios::sync_with_stdio(false), cin.tie(nullptr); 35 | 36 | int _; 37 | cin >> _; 38 | while (_--) solve(); 39 | 40 | return 0; 41 | } -------------------------------------------------------------------------------- /Misc/Tsinghua University Bootcamp 2025/Tsinghua Bootcamp 2025, Day 5/G.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file G.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-08-09 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | void solve(void) { 14 | int x, b; 15 | cin >> x >> b; 16 | 17 | if (x >= b) return cout << -1 << endl, void(); 18 | 19 | int r = b % x, t = b / x + (b % x > 0); 20 | if (r == 0) r = x; 21 | 22 | vector ans; 23 | ans.push_back(r); 24 | ans.push_back(0); 25 | for (int i = r + 1; i < b && ans.size() < t; i++) ans.push_back(i); 26 | 27 | for (auto x : ans) cout << x << ' '; 28 | cout << endl; 29 | 30 | return; 31 | } 32 | 33 | int main() { 34 | ios::sync_with_stdio(false), cin.tie(nullptr); 35 | 36 | int _ = 1; 37 | while (_--) solve(); 38 | 39 | return 0; 40 | } -------------------------------------------------------------------------------- /QOJ/14687.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 14687.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-10-22 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define endl '\n' 14 | 15 | #define maxn 100005 16 | 17 | int a[maxn]; 18 | 19 | void solve(void) { 20 | int n; 21 | cin >> n; 22 | for (int i = 1; i <= n; i++) cin >> a[i]; 23 | 24 | auto calc = [&](void) -> int { 25 | int v = 0; 26 | for (int i = 1; i <= n; i++) v += (v >= a[i] ? +1 : -1); 27 | return v; 28 | }; 29 | 30 | sort(a + 1, a + n + 1); 31 | cout << calc() << ' '; 32 | reverse(a + 1, a + n + 1); 33 | cout << calc() << endl; 34 | 35 | return; 36 | } 37 | 38 | int main() { 39 | ios::sync_with_stdio(false), cin.tie(nullptr); 40 | 41 | int _ = 1; 42 | while (_--) solve(); 43 | 44 | return 0; 45 | } -------------------------------------------------------------------------------- /Codeforces/2104A.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 2104A.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-04-28 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | void solve(void) { 20 | int a, b, c; 21 | cin >> a >> b >> c; 22 | cout << (((a + b + c) % 3 == 0 && c - b >= b - a) ? "YES" : "NO") << endl; 23 | return; 24 | } 25 | 26 | bool mem2; 27 | 28 | int main() { 29 | ios::sync_with_stdio(false), cin.tie(nullptr); 30 | #ifdef LOCAL 31 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 32 | #endif 33 | 34 | int _ = 1; 35 | cin >> _; 36 | while (_--) solve(); 37 | 38 | #ifdef LOCAL 39 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 40 | #endif 41 | return 0; 42 | } -------------------------------------------------------------------------------- /Nowcoder/231193.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | bool mem1; 5 | 6 | #define maxn 105 7 | 8 | int m[maxn], lef[maxn], rig[maxn]; 9 | 10 | bool mem2; 11 | 12 | int main() { 13 | cerr << "Memory: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 14 | ios::sync_with_stdio(false); 15 | int n, k; 16 | while (cin >> n >> k) { 17 | for (int i = 0; i < k; i++) cin >> m[i]; 18 | for (int i = 0; i < n; i++) lef[i] = i - 1, rig[i] = i + 1; 19 | rig[n - 1] = 0, lef[0] = n - 1; 20 | int p = 0; 21 | for (int t = 1, mp = 0; t < n; p = rig[p], t++, mp = (mp + 1) % k) { 22 | int x = m[mp] - 1; 23 | while (x--) p = rig[p]; 24 | lef[rig[lef[p]] = rig[p]] = lef[p]; 25 | } 26 | cout << p << endl; 27 | } 28 | cerr << "Time: " << clock() * 1000. / CLOCKS_PER_SEC << "ms" << endl; 29 | return 0; 30 | } -------------------------------------------------------------------------------- /Nowcoder/81600E.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 81600E.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-07-30 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define endl '\n' 14 | #define maxn 100005 15 | 16 | int a[maxn], b[maxn]; 17 | 18 | void solve(void) { 19 | int n; 20 | cin >> n; 21 | for (int i = 1; i <= n; i++) cin >> a[i]; 22 | for (int i = 1; i <= n; i++) cin >> b[i]; 23 | int ans = 0, cnt = 0; 24 | for (int i = 1; i <= n; i++) 25 | if (a[i] > b[i]) 26 | ans++; 27 | else if (a[i] == b[i]) 28 | cnt++; 29 | cout << ans + ((cnt + 1) / 2) << endl; 30 | return; 31 | } 32 | 33 | int main() { 34 | ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); 35 | 36 | int _ = 1; 37 | cin >> _; 38 | while (_--) solve(); 39 | 40 | return 0; 41 | } -------------------------------------------------------------------------------- /QOJ/6138.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 6138.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-10-18 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define endl '\n' 14 | 15 | void solve(void) { 16 | int x, k; 17 | cin >> x >> k; 18 | while (x >= 2 && k) { 19 | int v = x, sum = 0; 20 | while (v) { 21 | int t = v % 10; 22 | v /= 10; 23 | if (t == 8) 24 | sum += 2; 25 | else if (t == 0 || t == 4 || t == 6 || t == 9) 26 | sum++; 27 | } 28 | x = sum, k--; 29 | } 30 | if (k) x ^= k & 1; 31 | cout << x << endl; 32 | return; 33 | } 34 | 35 | int main() { 36 | ios::sync_with_stdio(false), cin.tie(nullptr); 37 | 38 | int _ = 1; 39 | cin >> _; 40 | while (_--) solve(); 41 | 42 | return 0; 43 | } -------------------------------------------------------------------------------- /Codeforces Gym/101981A.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 101981A.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-07-04 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | bool solve(void) { 20 | int n, m; 21 | cin >> n >> m; 22 | if (n == 0) return 0; 23 | if (m == 1) return n % 2; 24 | return 1; 25 | } 26 | 27 | bool mem2; 28 | 29 | int main() { 30 | ios::sync_with_stdio(false), cin.tie(nullptr); 31 | #ifdef LOCAL 32 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 33 | #endif 34 | 35 | int _ = 1; 36 | while (_--) cout << (solve() ? "Adrien" : "Austin") << endl; 37 | 38 | #ifdef LOCAL 39 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 40 | #endif 41 | return 0; 42 | } -------------------------------------------------------------------------------- /Codeforces Gym/101981K.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 101981K.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-07-04 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | void solve(void) { 20 | mt19937 rnd(time(NULL)); 21 | string ans; 22 | while (ans.size() < 50000) ans.push_back("UDLR"[rnd() % 4]); 23 | cout << ans << endl; 24 | return; 25 | } 26 | 27 | bool mem2; 28 | 29 | int main() { 30 | ios::sync_with_stdio(false), cin.tie(nullptr); 31 | #ifdef LOCAL 32 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 33 | #endif 34 | 35 | int _ = 1; 36 | while (_--) solve(); 37 | 38 | #ifdef LOCAL 39 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 40 | #endif 41 | return 0; 42 | } -------------------------------------------------------------------------------- /Codeforces/1603B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #define int long long 5 | 6 | bool mem1; 7 | 8 | #define maxn 100005 9 | 10 | long long gcd(long long x, long long y) { return y == 0 ? x : gcd(y, x % y); } 11 | 12 | int a[maxn]; 13 | 14 | void solve(void) { 15 | int x, y; 16 | cin >> x >> y; 17 | if (x > y) 18 | cout << x + y << endl; 19 | else if (x == y) 20 | cout << x << endl; 21 | else 22 | cout << y - y % x / 2 << endl; 23 | return; 24 | } 25 | 26 | bool mem2; 27 | 28 | signed main() { 29 | clock_t t1 = clock(); 30 | cerr << "Memory: " << abs(&mem1 - &mem2) / 1024.0 / 1024.0 << "MB" << endl; 31 | ios::sync_with_stdio(false); 32 | 33 | int _ = 1; 34 | cin >> _; 35 | while (_--) solve(); 36 | 37 | clock_t t2 = clock(); 38 | cerr << "Time: " << (t2 - t1) * 1000.0 / CLOCKS_PER_SEC << "ms" << endl; 39 | return 0; 40 | } -------------------------------------------------------------------------------- /Codeforces/1600E.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Macesuted (i@macesuted.moe) 3 | * @copyright Copyright (c) 2021 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | 9 | template 10 | inline T read() { 11 | T x = 0, f = 1; 12 | char c = getchar(); 13 | for (; c < '0' || c > '9'; c = getchar()) 14 | if (c == '-') f = -1; 15 | for (; c <= '9' && c >= '0'; c = getchar()) x = x * 10 + (c & 15); 16 | return x * f; 17 | } 18 | 19 | #define maxn 200005 20 | 21 | int a[maxn]; 22 | 23 | int main() { 24 | ios::sync_with_stdio(false); 25 | int n = read(); 26 | for (int i = 1; i <= n; i++) a[i] = read(); 27 | int l = 1, r = n; 28 | while (l < n && a[l] < a[l + 1]) l++; 29 | while (r > 1 && a[r - 1] > a[r]) r--; 30 | r = n - r + 1; 31 | if (a[1] > a[n]) swap(l, r); 32 | return cout << ((l & 1) || (r & 1) ? "Alice" : "Bob") << endl, 0; 33 | return 0; 34 | } -------------------------------------------------------------------------------- /Nowcoder/247578.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 247578.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2023-01-06 5 | * 6 | * @copyright Copyright (c) 2023 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | bool solve(void) { 20 | int64_t a, b; 21 | cin >> a >> b; 22 | if (a == b) return a % 3 == 2; 23 | return min(a, b) % 3 != 0; 24 | } 25 | 26 | bool mem2; 27 | 28 | int main() { 29 | ios::sync_with_stdio(false), cin.tie(nullptr); 30 | #ifdef LOCAL 31 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 32 | #endif 33 | 34 | int _ = 1; 35 | cin >> _; 36 | while (_--) cout << (solve() ? "niuniu" : "niumei") << endl; 37 | 38 | #ifdef LOCAL 39 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 40 | #endif 41 | return 0; 42 | } -------------------------------------------------------------------------------- /Nowcoder/247575.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 247575.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2023-01-06 5 | * 6 | * @copyright Copyright (c) 2023 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | void solve(void) { 20 | int n, a, b, ans; 21 | cin >> n >> a >> b, ans = n; 22 | for (int i = 0; a * i <= n; i++) ans = min(ans, (n - i * a) % b); 23 | cout << ans << endl; 24 | return; 25 | } 26 | 27 | bool mem2; 28 | 29 | int main() { 30 | ios::sync_with_stdio(false), cin.tie(nullptr); 31 | #ifdef LOCAL 32 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 33 | #endif 34 | 35 | int _ = 1; 36 | while (_--) solve(); 37 | 38 | #ifdef LOCAL 39 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 40 | #endif 41 | return 0; 42 | } -------------------------------------------------------------------------------- /QOJ/14948.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 14948.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-11-12 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define endl '\n' 14 | 15 | bool ac[450][20]; 16 | int cnt[450]; 17 | 18 | void solve(void) { 19 | int n; 20 | cin >> n; 21 | while (n--) { 22 | int a, b, c; 23 | cin >> a >> b >> c; 24 | 25 | if (ac[a][b]) { 26 | cout << 0 << endl; 27 | continue; 28 | } 29 | 30 | if (c < 240 || cnt[a] < 3) 31 | cout << b << endl; 32 | else 33 | cout << 0 << endl; 34 | 35 | ac[a][b] = true, cnt[a]++; 36 | } 37 | 38 | return; 39 | } 40 | 41 | int main() { 42 | ios::sync_with_stdio(false), cin.tie(nullptr); 43 | 44 | int _ = 1; 45 | while (_--) solve(); 46 | 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /Codeforces Gym/102428E.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 102428E.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-07-25 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define maxn 100005 14 | 15 | string s; 16 | vector a; 17 | 18 | int main() { 19 | ios::sync_with_stdio(false), cin.tie(nullptr); 20 | 21 | cin >> s; 22 | int n = s.size(), m; 23 | cin >> m; 24 | 25 | for (int i = 0; i < n; i++) 26 | if (s[i] == 'E') a.push_back(i); 27 | int len = a.size(); 28 | for (int i = 0; i < len; i++) a.push_back(a[i] + n); 29 | for (int i = 0; i < len; i++) a.push_back(a[i] + 2 * n); 30 | 31 | int64_t ans = 0; 32 | for (int i = len; i < 2 * len; i++) { 33 | int l = a[i] - a[i - 1], c = min(l, m); 34 | ans += int64_t(m + (m - c + 1)) * c / 2; 35 | } 36 | cout << ans << endl; 37 | return 0; 38 | } -------------------------------------------------------------------------------- /HDOJ/1174-1007.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 1174-1007.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-07-25 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define endl '\n' 14 | 15 | mt19937_64 rnd(114514); 16 | 17 | void solve(void) { 18 | int n; 19 | cin >> n; 20 | 21 | map delt; 22 | for (int i = 1, l, r; i <= n; i++) { 23 | cin >> l >> r; 24 | uint64_t v = rnd(); 25 | delt[l] ^= v, delt[r + 1] ^= v; 26 | } 27 | 28 | set S; 29 | S.insert(0); 30 | uint64_t cur = 0; 31 | for (auto [x, v] : delt) S.insert(cur ^= v); 32 | 33 | cout << S.size() << endl; 34 | 35 | return; 36 | } 37 | 38 | int main() { 39 | ios::sync_with_stdio(false), cin.tie(nullptr); 40 | 41 | int _ = 1; 42 | cin >> _; 43 | while (_--) solve(); 44 | 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /AtCoder/abc366_a.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file abc366_a.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-08-10 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | void solve(void) { 20 | int n, a, b; 21 | cin >> n >> a >> b; 22 | n -= a + b; 23 | if (a + n < b || b + n < a) return cout << "Yes" << endl, void(); 24 | cout << "No" << endl; 25 | return; 26 | } 27 | 28 | bool mem2; 29 | 30 | int main() { 31 | ios::sync_with_stdio(false), cin.tie(nullptr); 32 | #ifdef LOCAL 33 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 34 | #endif 35 | 36 | int _ = 1; 37 | while (_--) solve(); 38 | 39 | #ifdef LOCAL 40 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 41 | #endif 42 | return 0; 43 | } -------------------------------------------------------------------------------- /Codeforces Gym/103860F.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 103860F.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-03-27 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | int64_t a[21]; 14 | int64_t f[1 << 21]; 15 | 16 | void solve(void) { 17 | int n; 18 | cin >> n; 19 | for (int i = 0; i < n; i++) cin >> a[i]; 20 | sort(a, a + n, greater()); 21 | int64_t v; 22 | cin >> v; 23 | 24 | int64_t ans = 0; 25 | for (int S = 0; S < (1 << (n - 1)); S++) { 26 | int64_t cur = v; 27 | for (int x = 0; x < n - 1; x++) 28 | if (S >> x & 1) cur %= a[x]; 29 | ans = max(ans, cur % a[n - 1]); 30 | } 31 | cout << ans << endl; 32 | return; 33 | } 34 | 35 | int main() { 36 | ios::sync_with_stdio(false), cin.tie(nullptr); 37 | 38 | int _ = 1; 39 | while (_--) solve(); 40 | 41 | return 0; 42 | } -------------------------------------------------------------------------------- /Codeforces Gym/105631E.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 105631E.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-01-03 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | void solve(void) { 20 | int n; 21 | cin >> n; 22 | string s; 23 | cin >> s; 24 | cout << (s.front() == '1' || s.back() == '1' ? "Alice" : "Bob") << endl; 25 | return; 26 | } 27 | 28 | bool mem2; 29 | 30 | int main() { 31 | ios::sync_with_stdio(false), cin.tie(nullptr); 32 | #ifdef LOCAL 33 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 34 | #endif 35 | 36 | int _ = 1; 37 | cin >> _; 38 | while (_--) solve(); 39 | 40 | #ifdef LOCAL 41 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 42 | #endif 43 | return 0; 44 | } -------------------------------------------------------------------------------- /Codeforces/1566D1.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Macesuted (i@macesuted.moe) 3 | * @copyright Copyright (c) 2021 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | 9 | #define int long long 10 | 11 | #define maxn 305 12 | 13 | int a[maxn]; 14 | 15 | int t[maxn]; 16 | 17 | map > S; 18 | 19 | void work(void) { 20 | int n, m; 21 | cin >> n >> m; 22 | S.clear(); 23 | for (register int i = 1; i <= m; i++) cin >> a[i], S[a[i]].push_back(i), t[i] = 0; 24 | int answer = 0; 25 | for (auto i = S.rbegin(); i != S.rend(); i++) { 26 | for (auto j : i->second) 27 | for (register int x = j + 1; x <= m; x++) answer += t[x]; 28 | for (auto j : i->second) t[j] = true; 29 | } 30 | cout << answer << endl; 31 | return; 32 | } 33 | 34 | signed main() { 35 | ios::sync_with_stdio(false); 36 | int _ = 1; 37 | cin >> _; 38 | while (_--) work(); 39 | return 0; 40 | } -------------------------------------------------------------------------------- /QOJ/11376.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 11376.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-09-13 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | void solve(void) { 20 | int64_t v; 21 | cin >> v; 22 | int64_t ans = 0; 23 | for (int i = 0; i <= 18; i++) ans += v % 10 * (1 << i), v /= 10; 24 | cout << ans << endl; 25 | return; 26 | } 27 | 28 | bool mem2; 29 | 30 | int main() { 31 | ios::sync_with_stdio(false), cin.tie(nullptr); 32 | #ifdef LOCAL 33 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 34 | #endif 35 | 36 | int _ = 1; 37 | cin >> _; 38 | while (_--) solve(); 39 | 40 | #ifdef LOCAL 41 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 42 | #endif 43 | return 0; 44 | } -------------------------------------------------------------------------------- /AtCoder/abc360_a.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file abc360_a.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-06-30 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | void solve(void) { 20 | string s; 21 | cin >> s; 22 | if (s[0] == 'R' || (s[1] == 'R' && s[2] == 'M')) 23 | cout << "Yes" << endl; 24 | else 25 | cout << "No" << endl; 26 | return; 27 | } 28 | 29 | bool mem2; 30 | 31 | int main() { 32 | ios::sync_with_stdio(false), cin.tie(nullptr); 33 | #ifdef LOCAL 34 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 35 | #endif 36 | 37 | int _ = 1; 38 | while (_--) solve(); 39 | 40 | #ifdef LOCAL 41 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 42 | #endif 43 | return 0; 44 | } -------------------------------------------------------------------------------- /Codeforces/2108A.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 2108A.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-05-07 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | void solve(void) { 20 | int n; 21 | cin >> n; 22 | int64_t sum = 0; 23 | for (int i = 1; i <= n; i++) sum += abs((n - i + 1) - i); 24 | cout << 1 + sum / 2 << endl; 25 | return; 26 | } 27 | 28 | bool mem2; 29 | 30 | int main() { 31 | ios::sync_with_stdio(false), cin.tie(nullptr); 32 | #ifdef LOCAL 33 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 34 | #endif 35 | 36 | int _ = 1; 37 | cin >> _; 38 | while (_--) solve(); 39 | 40 | #ifdef LOCAL 41 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 42 | #endif 43 | return 0; 44 | } -------------------------------------------------------------------------------- /AtCoder/abc207_e.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Macesuted (i@macesuted.moe) 3 | * @copyright Copyright (c) 2021 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | 9 | #define int long long 10 | 11 | #define maxn 3005 12 | #define mod 1000000007 13 | 14 | int a[maxn], f[maxn][maxn], cnt[maxn]; 15 | 16 | void work(void) { 17 | int n; 18 | cin >> n; 19 | for (register int i = 1; i <= n; i++) cin >> a[i]; 20 | for (register int j = n; j; j--) { 21 | memset(cnt, 0, sizeof(cnt)); 22 | cnt[0] = 1; 23 | for (register int i = n, tat = 0; i; i--) { 24 | tat = (tat + a[i]) % j; 25 | f[i][j] = cnt[tat]; 26 | cnt[tat] = (cnt[tat] + f[i][j + 1]) % mod; 27 | } 28 | } 29 | cout << f[1][1] << endl; 30 | return; 31 | } 32 | 33 | signed main() { 34 | ios::sync_with_stdio(false); 35 | int _ = 1; 36 | // cin >> _; 37 | while (_--) work(); 38 | return 0; 39 | } -------------------------------------------------------------------------------- /QOJ/11429.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 11429.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-10-04 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | void solve(void) { 20 | string s; 21 | cin >> s; 22 | for (size_t i = 1; i < s.size(); i++) { 23 | cout << s[i]; 24 | if (s[i - 1] != s[i]) cout << s[i - 1]; 25 | } 26 | cout << endl; 27 | return; 28 | } 29 | 30 | bool mem2; 31 | 32 | int main() { 33 | ios::sync_with_stdio(false), cin.tie(nullptr); 34 | #ifdef LOCAL 35 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 36 | #endif 37 | 38 | int _ = 1; 39 | while (_--) solve(); 40 | 41 | #ifdef LOCAL 42 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 43 | #endif 44 | return 0; 45 | } -------------------------------------------------------------------------------- /QOJ/6131.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 6131.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-10-18 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define endl '\n' 14 | 15 | #define maxn 1005 16 | 17 | void solve(void) { 18 | int n, k; 19 | cin >> n >> k; 20 | vector ans; 21 | for (int v = 1; v < n && k; v++) { 22 | bool chk = true; 23 | for (int i = 0; i < n && chk; i++) chk &= ((i ^ v) < n); 24 | if (chk) k--, ans.push_back(v); 25 | } 26 | if (k) return cout << "Impossible" << endl, void(); 27 | for (auto i : ans) { 28 | for (int j = 0; j < n; j++) cout << (i ^ j) + 1 << ' '; 29 | cout << endl; 30 | } 31 | return; 32 | } 33 | 34 | int main() { 35 | ios::sync_with_stdio(false), cin.tie(nullptr); 36 | 37 | int _ = 1; 38 | cin >> _; 39 | while (_--) solve(); 40 | 41 | return 0; 42 | } -------------------------------------------------------------------------------- /Codeforces/2122A.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 2122A.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-07-19 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | void solve(void) { 20 | int n, m; 21 | cin >> n >> m; 22 | if (n > m) swap(n, m); 23 | if (n == 1 || (n == 2 && m == 2)) return cout << "NO" << endl, void(); 24 | cout << "YES" << endl; 25 | return; 26 | } 27 | 28 | bool mem2; 29 | 30 | int main() { 31 | ios::sync_with_stdio(false), cin.tie(nullptr); 32 | #ifdef LOCAL 33 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 34 | #endif 35 | 36 | int _ = 1; 37 | cin >> _; 38 | while (_--) solve(); 39 | 40 | #ifdef LOCAL 41 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 42 | #endif 43 | return 0; 44 | } -------------------------------------------------------------------------------- /HDOJ/7445.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 7445.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-07-22 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define endl '\n' 14 | 15 | typedef pair pii; 16 | 17 | void solve(void) { 18 | vector ans; 19 | 20 | int n, n1 = 1; 21 | cin >> n; 22 | for (int i = 1; i * 3 <= n; i++) { 23 | ans.emplace_back(min(i, 3), i + 1); 24 | ans.emplace_back(min(i, 2), i + 2); 25 | ans.emplace_back(min(i, 1), i + 3); 26 | n1 = i + 3; 27 | } 28 | for (int i = 0; i < n % 3; i++) ans.emplace_back(1, ++n1); 29 | sort(ans.begin(), ans.end()); 30 | for (auto [x, y] : ans) cout << x << ' ' << y << endl; 31 | return; 32 | } 33 | 34 | int main() { 35 | ios::sync_with_stdio(false), cin.tie(nullptr); 36 | 37 | int _; 38 | cin >> _; 39 | while (_--) solve(); 40 | return 0; 41 | } -------------------------------------------------------------------------------- /Codeforces/1750A.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 1750A.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2022-11-06 5 | * 6 | * @copyright Copyright (c) 2022 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | #define maxn 15 20 | 21 | int a[maxn]; 22 | 23 | void solve(void) { 24 | int n; 25 | cin >> n; 26 | for (int i = 1; i <= n; i++) cin >> a[i]; 27 | cout << (a[1] == 1 ? "Yes" : "No") << endl; 28 | return; 29 | } 30 | 31 | bool mem2; 32 | 33 | int main() { 34 | ios::sync_with_stdio(false), cin.tie(nullptr); 35 | #ifdef LOCAL 36 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 37 | #endif 38 | 39 | int _ = 1; 40 | cin >> _; 41 | while (_--) solve(); 42 | 43 | #ifdef LOCAL 44 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 45 | #endif 46 | return 0; 47 | } -------------------------------------------------------------------------------- /AtCoder/arc127_a.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Macesuted (i@macesuted.moe) 3 | * @copyright Copyright (c) 2021 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | 9 | #define int long long 10 | 11 | #define maxn 17 12 | 13 | int pow10[maxn]; 14 | 15 | void work(void) { 16 | pow10[0] = 1; 17 | for (register int i = 1; i < maxn; i++) pow10[i] = pow10[i - 1] * 10; 18 | int n; 19 | cin >> n; 20 | int cnt = 0; 21 | for (register int i = 0; pow10[i] <= n; i++) { 22 | int base = 0; 23 | for (register int j = i; ~j; j--) { 24 | base += pow10[j]; 25 | if (base > n) break; 26 | cnt += min(n - base + 1, pow10[j]); 27 | } 28 | } 29 | cout << cnt << endl; 30 | return; 31 | } 32 | 33 | signed main() { 34 | ios::sync_with_stdio(false); 35 | cout << setiosflags(ios::fixed) << setprecision(11); 36 | int _ = 1; 37 | // cin >> _; 38 | while (_--) work(); 39 | return 0; 40 | } -------------------------------------------------------------------------------- /Codeforces Gym/102428F.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 102428F.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-07-25 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define maxn 5005 14 | #define mod 1000000007 15 | 16 | int64_t f[maxn][maxn], g1[maxn][maxn], g2[maxn][maxn]; 17 | 18 | int main() { 19 | ios::sync_with_stdio(false), cin.tie(nullptr); 20 | 21 | int n, m; 22 | cin >> n >> m, m -= n; 23 | 24 | f[m][n] = 1; 25 | for (int i = 1; i <= n; i++) g1[m][i] = 1, g2[m][i] = n; 26 | 27 | for (int i = m - 1; ~i; i--) { 28 | for (int j = 1; j <= n && i + j <= m; j++) { 29 | f[i][j] = (g2[i + j][j] + (mod - j + 1) * g1[i + j][j]) % mod; 30 | } 31 | for (int j = m; j; j--) g1[i][j] = (g1[i][j + 1] + f[i][j]) % mod, g2[i][j] = (g2[i][j + 1] + f[i][j] * j) % mod; 32 | } 33 | 34 | cout << g1[0][1] << endl; 35 | 36 | return 0; 37 | } -------------------------------------------------------------------------------- /Codeforces/1616B.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 1616B.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2022-01-02 5 | * 6 | * @copyright Copyright (c) 2022 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | bool mem1; 14 | 15 | void solve(void) { 16 | int n; 17 | cin >> n; 18 | string s; 19 | cin >> s; 20 | int p = 0; 21 | while (p + 1 < (int)s.size() && (s[p] > s[p + 1] || (s[p] == s[p + 1] && s[p] != s[0]))) p++; 22 | for (int i = 0; i <= p; i++) cout << s[i]; 23 | for (int i = p; ~i; i--) cout << s[i]; 24 | cout << endl; 25 | return; 26 | } 27 | 28 | bool mem2; 29 | 30 | int main() { 31 | #ifdef LOCAL 32 | cerr << "Memory: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 33 | #endif 34 | 35 | int _ = 1; 36 | cin >> _; 37 | while (_--) solve(); 38 | 39 | #ifdef LOCAL 40 | cerr << "Time: " << clock() * 1000. / CLOCKS_PER_SEC << "ms" << endl; 41 | #endif 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /Nowcoder/108306F.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 108306F.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-08-12 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define endl '\n' 14 | 15 | using pii = pair; 16 | 17 | pii s1, s2, t1, t2; 18 | 19 | void solve(void) { 20 | cin >> s1.first >> s1.second; 21 | cin >> s2.first >> s2.second; 22 | cin >> t1.first >> t1.second; 23 | cin >> t2.first >> t2.second; 24 | if (((s1.first + s1.second) & 1) != ((t1.first + t1.second) & 1)) swap(t1, t2); 25 | 26 | auto dist = [&](pii x, pii y) -> int64_t { return max(abs(x.first - y.first), abs(x.second - y.second)); }; 27 | 28 | cout << dist(s1, t1) + dist(s2, t2) << endl; 29 | 30 | return; 31 | } 32 | 33 | int main() { 34 | ios::sync_with_stdio(false), cin.tie(nullptr); 35 | 36 | int _ = 1; 37 | cin >> _; 38 | while (_--) solve(); 39 | 40 | return 0; 41 | } -------------------------------------------------------------------------------- /Codeforces Gym/103860G.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 103860G.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-03-27 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | int64_t a[21]; 14 | int64_t f[1 << 21]; 15 | 16 | int sg(int l, int r, int p) { 17 | if (l > r) return 0; 18 | if (r % p == 1 && (r - 1) / p >= l) return sg(l, (r - 1) / p - 1, p); 19 | return r - l + 1 - ((r - 1) / p >= l ? (r - 1) / p - l + 1 : 0); 20 | } 21 | 22 | void solve(void) { 23 | int n, p; 24 | cin >> n >> p; 25 | uint32_t sgSum = 0; 26 | for (int i = 1, l, r; i <= n; i++) { 27 | cin >> l >> r; 28 | sgSum ^= sg(l, r, p); 29 | } 30 | cout << (sgSum ? "First" : "Second") << endl; 31 | return; 32 | } 33 | 34 | int main() { 35 | ios::sync_with_stdio(false), cin.tie(nullptr); 36 | 37 | int _ = 1; 38 | cin >> _; 39 | while (_--) solve(); 40 | 41 | return 0; 42 | } -------------------------------------------------------------------------------- /Codeforces/1459B.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 1459B.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-01-05 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | #define maxn 1005 20 | 21 | void solve(void) { 22 | int n; 23 | cin >> n; 24 | 25 | if (n & 1) 26 | cout << 2 * (n / 2 + 1) * (n / 2 + 2) << endl; 27 | else 28 | cout << (n / 2 + 1) * (n / 2 + 1) << endl; 29 | 30 | return; 31 | } 32 | 33 | bool mem2; 34 | 35 | int main() { 36 | ios::sync_with_stdio(false), cin.tie(nullptr); 37 | #ifdef LOCAL 38 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 39 | #endif 40 | 41 | int _ = 1; 42 | while (_--) solve(); 43 | 44 | #ifdef LOCAL 45 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 46 | #endif 47 | return 0; 48 | } -------------------------------------------------------------------------------- /Misc/Tsinghua University Bootcamp in Summer 2024/Tsinghua Bootcamp. Finals/K.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file K.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-08-26 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define endl '\n' 14 | 15 | int st[10]; 16 | int64_t ans[10][10]; 17 | 18 | void solve(void) { 19 | for (int i = 1; i <= 9; i++) 20 | for (int j = 0; j <= 9; j++) ans[i][j] = -1; 21 | for (int64_t v = 1; v <= 1e4; v++) { 22 | int64_t tl = 0, val = v * v; 23 | while (val) st[tl++] = val % 10, val /= 10; 24 | if (ans[st[tl - 1]][st[0]] == -1) ans[st[tl - 1]][st[0]] = v * v; 25 | } 26 | int a, b; 27 | cin >> a >> b; 28 | cout << ans[a][b] << endl; 29 | return; 30 | } 31 | 32 | int main() { 33 | ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); 34 | 35 | int _ = 1; 36 | while (_--) solve(); 37 | 38 | return 0; 39 | } -------------------------------------------------------------------------------- /Codeforces Gym/535265A.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 535265A.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-07-16 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define maxn 5005 14 | 15 | int mod; 16 | 17 | int C[maxn][maxn]; 18 | 19 | int64_t qpow(int64_t a, int64_t x) { 20 | int64_t ans = 1; 21 | while (x) { 22 | if (x & 1) ans = ans * a % mod; 23 | a = a * a % mod, x >>= 1; 24 | } 25 | return ans; 26 | } 27 | 28 | int main() { 29 | int n, m; 30 | cin >> n >> m >> mod; 31 | 32 | for (int i = 0; i <= n; i++) { 33 | C[i][0] = C[i][i] = 1; 34 | for (int j = 1; j < i; j++) C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod; 35 | } 36 | 37 | int64_t ans = 0; 38 | for (int t = 1; t <= n; t++) ans = (ans + qpow(qpow(2, t) - 1, m - 1) * qpow(2, (n - t) * (m - 1)) % mod * C[n][t]) % mod; 39 | cout << ans << endl; 40 | 41 | return 0; 42 | } -------------------------------------------------------------------------------- /Codeforces/1603A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | bool mem1; 5 | 6 | #define maxn 100005 7 | 8 | long long gcd(long long x, long long y) { return y == 0 ? x : gcd(y, x % y); } 9 | 10 | int a[maxn]; 11 | 12 | bool solve(void) { 13 | int n; 14 | cin >> n; 15 | for (int i = 1; i <= n; i++) cin >> a[i]; 16 | long long lcm = 1; 17 | for (int i = 1; i <= n && lcm <= 1e9; i++) { 18 | lcm = lcm / gcd(lcm, (i + 1)) * (i + 1); 19 | if (a[i] % lcm == 0) return false; 20 | } 21 | return true; 22 | } 23 | 24 | bool mem2; 25 | 26 | int main() { 27 | clock_t t1 = clock(); 28 | cerr << "Memory: " << abs(&mem1 - &mem2) / 1024.0 / 1024.0 << "MB" << endl; 29 | ios::sync_with_stdio(false); 30 | 31 | int _ = 1; 32 | cin >> _; 33 | while (_--) cout << (solve() ? "YES" : "NO") << endl; 34 | 35 | clock_t t2 = clock(); 36 | cerr << "Time: " << (t2 - t1) * 1000.0 / CLOCKS_PER_SEC << "ms" << endl; 37 | return 0; 38 | } -------------------------------------------------------------------------------- /Codeforces/1998A.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 1998A.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-08-10 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | void solve(void) { 20 | int x, y, n; 21 | cin >> x >> y >> n; 22 | if (n & 1) cout << x << ' ' << y << endl, n--; 23 | for (int i = 1; i * 2 <= n; i++) cout << x << ' ' << y + i << endl << x << ' ' << y - i << endl; 24 | return; 25 | } 26 | 27 | bool mem2; 28 | 29 | int main() { 30 | ios::sync_with_stdio(false), cin.tie(nullptr); 31 | #ifdef LOCAL 32 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 33 | #endif 34 | 35 | int _ = 1; 36 | cin >> _; 37 | while (_--) solve(); 38 | 39 | #ifdef LOCAL 40 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 41 | #endif 42 | return 0; 43 | } -------------------------------------------------------------------------------- /HDOJ/6708.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 6708.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-07-18 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define maxn 1050 14 | 15 | bool s[maxn][maxn]; 16 | 17 | void solve(int xl, int xr, int yl, int yr, bool rev = false) { 18 | if (xl == xr && yl == yr) return s[xl][yl] = rev, void(); 19 | int xm = (xl + xr) / 2, ym = (yl + yr) / 2; 20 | solve(xl, xm, yl, ym, rev), solve(xl, xm, ym + 1, yr, rev); 21 | solve(xm + 1, xr, yl, ym, !rev), solve(xm + 1, xr, ym + 1, yr, rev); 22 | return; 23 | } 24 | 25 | int main() { 26 | int _; 27 | cin >> _; 28 | while (_--) { 29 | int k; 30 | cin >> k; 31 | solve(1, 1 << k, 1, 1 << k); 32 | for (int i = 1; i <= (1 << k); i++) { 33 | for (int j = 1; j <= (1 << k); j++) cout << "CP"[s[i][j]]; 34 | cout << endl; 35 | } 36 | } 37 | return 0; 38 | } -------------------------------------------------------------------------------- /Nowcoder/108330D.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 108330D.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-07-22 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define endl '\n' 14 | 15 | #define maxn 200005 16 | 17 | int f[maxn]; 18 | 19 | void solve(void) { 20 | int n, a; 21 | cin >> n >> a; 22 | string s; 23 | cin >> s, s = ' ' + s; 24 | f[0] = 0; 25 | for (int i = 1; i <= n; i++) f[i] = (f[i - 1] + (s[i] == '1')); 26 | for (int i = 1; i <= n; i++) { 27 | if (i + a - 1 <= n && f[i + a - 1] - f[i - 1] == a) return cout << n << endl, void(); 28 | if (i + a <= n && f[i + a] - f[i - 1] == 0) return cout << n << endl, void(); 29 | } 30 | cout << f[n] << endl; 31 | return; 32 | } 33 | 34 | int main() { 35 | ios::sync_with_stdio(false), cin.tie(nullptr); 36 | 37 | int _ = 1; 38 | cin >> _; 39 | while (_--) solve(); 40 | 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /Codeforces Gym/105586E.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 105586E.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-01-04 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | void solve(void) { 20 | int n; 21 | cin >> n; 22 | cout << !((n - 1) & 2) << endl; 23 | for (int i = 1; i <= n; i++) { 24 | for (int j = 1; j <= n; j++) cout << (i + j) % n + 1 << ' '; 25 | cout << endl; 26 | } 27 | return; 28 | } 29 | 30 | bool mem2; 31 | 32 | int main() { 33 | ios::sync_with_stdio(false), cin.tie(nullptr); 34 | #ifdef LOCAL 35 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 36 | #endif 37 | 38 | int _ = 1; 39 | while (_--) solve(); 40 | 41 | #ifdef LOCAL 42 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 43 | #endif 44 | return 0; 45 | } -------------------------------------------------------------------------------- /Nowcoder/108302E.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 108302E.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-07-29 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define endl '\n' 14 | 15 | #define maxn 100005 16 | 17 | int a[maxn], ppcnt[maxn]; 18 | 19 | void solve(void) { 20 | int64_t n; 21 | cin >> n; 22 | 23 | for (int i = 1; i <= n; i++) cin >> a[i], ppcnt[i] = 0; 24 | 25 | int64_t ans = 0; 26 | for (int t = 0; t < 30; t++) { 27 | int64_t cnt[2][2] = {{0, 0}, {0, 0}}; 28 | for (int i = 1; i <= n; i++) cnt[a[i] >> t & 1][ppcnt[i] & 1]++, ppcnt[i] += a[i] >> t & 1; 29 | ans += (cnt[0][0] * cnt[1][0] + cnt[0][1] * cnt[1][1]) << t; 30 | } 31 | 32 | cout << ans << endl; 33 | 34 | return; 35 | } 36 | 37 | int main() { 38 | ios::sync_with_stdio(false), cin.tie(nullptr); 39 | 40 | int _ = 1; 41 | while (_--) solve(); 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /QOJ/969.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 969.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-09-21 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define endl '\n' 14 | 15 | #define maxn 1000005 16 | #define mod (int128_t)1'000'000'000'000'000'031 17 | 18 | using int128_t = __int128_t; 19 | 20 | int128_t qpow(int128_t a, int128_t x) { 21 | int128_t ans = 1; 22 | while (x) { 23 | if (x & 1) ans = ans * a % mod; 24 | a = a * a % mod, x >>= 1; 25 | } 26 | return ans; 27 | } 28 | 29 | int64_t ans[maxn]; 30 | 31 | void solve(void) { 32 | ans[1000000] = 300; 33 | for (int i = 999999; i >= 0; i--) ans[i] = qpow(42, ans[i + 1]); 34 | int n; 35 | cin >> n; 36 | cout << ans[n] << endl; 37 | return; 38 | } 39 | 40 | int main() { 41 | ios::sync_with_stdio(false), cin.tie(nullptr); 42 | 43 | int _ = 1; 44 | while (_--) solve(); 45 | 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /Nowcoder/108298G.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 108298G.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-07-15 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define endl '\n' 14 | 15 | void solve(void) { 16 | int n, q; 17 | cin >> n >> q; 18 | string s; 19 | cin >> s, s = ' ' + s; 20 | while (q--) { 21 | string t; 22 | int a; 23 | cin >> t >> a, t = ' ' + t; 24 | int64_t ans = 0; 25 | int cur = 0; 26 | for (int i = 1; i < (int)t.size(); i++) 27 | if (s[i + a - 1] == t[i]) 28 | cur++; 29 | else 30 | ans += (int64_t)cur * (cur + 1) / 2, cur = 0; 31 | cout << ans + (int64_t)cur * (cur + 1) / 2 << endl; 32 | } 33 | return; 34 | } 35 | 36 | int main() { 37 | ios::sync_with_stdio(false), cin.tie(nullptr); 38 | 39 | int _ = 1; 40 | while (_--) solve(); 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /QOJ/141-Alice.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 141-Alice.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2023-03-06 5 | * 6 | * @copyright Copyright (c) 2023 7 | * 8 | */ 9 | 10 | #include "Alice.h" 11 | #include 12 | using namespace std; 13 | 14 | vector Alice(int n, int m, vector U, vector V, vector c) { 15 | vector> graph; 16 | vector deg; 17 | graph.resize(n), deg.resize(n); 18 | for (int i = 0; i < m; i++) graph[U[i]].push_back(V[i]), graph[V[i]].push_back(U[i]), deg[U[i]]++, deg[V[i]]++; 19 | queue que; 20 | for (int i = 0; i < n; i++) 21 | if (deg[i] < 8) que.push(i); 22 | while (!que.empty()) { 23 | int p = que.front(); 24 | que.pop(); 25 | for (auto i : graph[p]) 26 | if (--deg[i] == 7) que.push(i); 27 | } 28 | vector ans; 29 | for (int i = 0; i < n; i++) 30 | if (deg[i] >= 8) ans.push_back(c[i] & 1), ans.push_back(c[i] >> 1 & 1); 31 | return ans; 32 | } -------------------------------------------------------------------------------- /Codeforces Gym/102465B.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 102465B.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-07-23 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define maxn 100005 14 | 15 | int l[maxn], r[maxn]; 16 | multiset Sl, Sr; 17 | 18 | int main() { 19 | ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); 20 | 21 | int n; 22 | cin >> n; 23 | for (int i = 1; i <= n; i++) cin >> l[i] >> r[i]; 24 | 25 | int ans = 1; 26 | for (int i = 1, j = 0; i <= n; i++) { 27 | if (j < i) j++, Sl.insert(l[j]), Sr.insert(r[j]); 28 | int len = r[i] - l[i] + 1; 29 | while (j < n && j - i + 1 < len && min(*Sr.begin(), r[j + 1]) - max(*Sl.rbegin(), l[j + 1]) + 1 > j - i + 1) 30 | j++, Sl.insert(l[j]), Sr.insert(r[j]), ans = max(ans, j - i + 1); 31 | Sl.erase(Sl.find(l[i])), Sr.erase(Sr.find(r[i])); 32 | } 33 | cout << ans << endl; 34 | return 0; 35 | } -------------------------------------------------------------------------------- /Codeforces/1632A.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 1632A.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2022-01-30 5 | * 6 | * @copyright Copyright (c) 2022 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define MP make_pair 14 | #define MT make_tuple 15 | 16 | bool mem1; 17 | 18 | void solve(void) { 19 | int n; 20 | string s; 21 | cin >> n >> s; 22 | int cnt[2] = {0, 0}; 23 | for (auto i : s) cnt[i - '0']++; 24 | if (cnt[0] >= 2 || cnt[1] >= 2) 25 | cout << "NO" << endl; 26 | else 27 | cout << "YES" << endl; 28 | return; 29 | } 30 | 31 | bool mem2; 32 | 33 | int main() { 34 | ios::sync_with_stdio(false); 35 | #ifdef LOCAL 36 | cerr << "Memory: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 37 | #endif 38 | 39 | int _ = 1; 40 | cin >> _; 41 | while (_--) solve(); 42 | 43 | #ifdef LOCAL 44 | cerr << "Time: " << clock() * 1000. / CLOCKS_PER_SEC << "ms" << endl; 45 | #endif 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /Codeforces/1998B.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 1998B.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-08-10 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | #define maxn 200005 20 | 21 | int a[maxn]; 22 | 23 | void solve(void) { 24 | int n; 25 | cin >> n; 26 | for (int i = 1; i <= n; i++) cin >> a[i]; 27 | for (int i = 1; i <= n; i++) cout << a[i] % n + 1 << ' '; 28 | cout << endl; 29 | return; 30 | } 31 | 32 | bool mem2; 33 | 34 | int main() { 35 | ios::sync_with_stdio(false), cin.tie(nullptr); 36 | #ifdef LOCAL 37 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 38 | #endif 39 | 40 | int _ = 1; 41 | cin >> _; 42 | while (_--) solve(); 43 | 44 | #ifdef LOCAL 45 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 46 | #endif 47 | return 0; 48 | } -------------------------------------------------------------------------------- /Codeforces/1352C.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 1352C.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2022-01-25 5 | * 6 | * @copyright Copyright (c) 2022 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define MP make_pair 14 | #define MT make_tuple 15 | 16 | bool mem1; 17 | 18 | void solve(void) { 19 | int n, k; 20 | cin >> k >> n; 21 | if (k == 1) return cout << n << endl, void(); 22 | int t = n / (k - 1), x = n % (k - 1); 23 | if (x == 0) 24 | cout << t * k - 1 << endl; 25 | else 26 | cout << t * k + x << endl; 27 | return; 28 | } 29 | 30 | bool mem2; 31 | 32 | int main() { 33 | ios::sync_with_stdio(false); 34 | #ifdef LOCAL 35 | cerr << "Memory: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 36 | #endif 37 | 38 | int _ = 1; 39 | cin >> _; 40 | while (_--) solve(); 41 | 42 | #ifdef LOCAL 43 | cerr << "Time: " << clock() * 1000. / CLOCKS_PER_SEC << "ms" << endl; 44 | #endif 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /Codeforces/1573B.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Macesuted (i@macesuted.moe) 3 | * @copyright Copyright (c) 2021 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | 9 | #define int long long 10 | 11 | #define maxn 200005 12 | 13 | int a[maxn], b[maxn], pos[2][maxn]; 14 | 15 | void work(void) { 16 | int n; 17 | cin >> n; 18 | for (register int i = 1; i <= n; i++) cin >> a[i], pos[0][a[i] = (a[i] + 1) / 2] = i; 19 | for (register int i = 1; i <= n; i++) cin >> b[i], pos[1][b[i] = b[i] / 2] = i; 20 | for (register int i = 2; i <= n; i++) pos[0][i] = min(pos[0][i], pos[0][i - 1]); 21 | for (register int i = n - 1; i; i--) pos[1][i] = min(pos[1][i], pos[1][i + 1]); 22 | int answer = 2 * n; 23 | for (register int i = 1; i <= n; i++) answer = min(answer, pos[0][i] + pos[1][i] - 2); 24 | cout << answer << endl; 25 | return; 26 | } 27 | 28 | signed main() { 29 | ios::sync_with_stdio(false); 30 | int _ = 1; 31 | cin >> _; 32 | while (_--) work(); 33 | return 0; 34 | } -------------------------------------------------------------------------------- /Codeforces/1632B.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 1632B.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2022-01-30 5 | * 6 | * @copyright Copyright (c) 2022 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define MP make_pair 14 | #define MT make_tuple 15 | 16 | bool mem1; 17 | 18 | void solve(void) { 19 | int n; 20 | cin >> n; 21 | int b = 1; 22 | while ((1 << b) <= (n - 1)) b++; 23 | b--; 24 | for (int i = (1 << b) - 1; ~i; i--) cout << i << ' '; 25 | for (int i = (1 << b); i < n; i++) cout << i << ' '; 26 | cout << endl; 27 | return; 28 | } 29 | 30 | bool mem2; 31 | 32 | int main() { 33 | ios::sync_with_stdio(false); 34 | #ifdef LOCAL 35 | cerr << "Memory: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 36 | #endif 37 | 38 | int _ = 1; 39 | cin >> _; 40 | while (_--) solve(); 41 | 42 | #ifdef LOCAL 43 | cerr << "Time: " << clock() * 1000. / CLOCKS_PER_SEC << "ms" << endl; 44 | #endif 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /Misc/Tsinghua University Bootcamp 2025/Tsinghua Bootcamp 2025, Day 4/D.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file D.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-08-08 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define endl '\n' 14 | 15 | #define maxn 500005 16 | 17 | int a[maxn], b[maxn]; 18 | 19 | void solve(void) { 20 | int n, m; 21 | cin >> n >> m; 22 | for (int i = 1; i <= n; i++) cin >> a[i]; 23 | sort(a + 1, a + n + 1); 24 | for (int i = 1; i <= m; i++) cin >> b[i]; 25 | 26 | int64_t ans = 0; 27 | for (int i = n, lstp = m + 1; i; i--) { 28 | lstp = min(lstp - 1, int(upper_bound(b + 1, b + m + 1, a[i]) - b - 1)); 29 | ans += max(0, lstp); 30 | } 31 | 32 | cout << ans << endl; 33 | 34 | return; 35 | } 36 | 37 | int main() { 38 | ios::sync_with_stdio(false), cin.tie(nullptr); 39 | 40 | int _ = 1; 41 | cin >> _; 42 | while (_--) solve(); 43 | 44 | return 0; 45 | } -------------------------------------------------------------------------------- /Misc/Tsinghua University Bootcamp in Summer 2024/Tsinghua Bootcamp 2024. Qualification Round/A.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file A.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-07-21 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | bool mem1; 14 | 15 | void solve(void) { 16 | int64_t S = ((int64_t)1 << 32) - 1; 17 | 18 | cout << "? " << 0 << endl; 19 | int64_t s1, s2; 20 | cin >> s1; 21 | cout << "? " << S << endl; 22 | cin >> s2; 23 | cout << "! " << s1 + s2 - 2 * S << endl; 24 | return; 25 | } 26 | 27 | bool mem2; 28 | 29 | int main() { 30 | ios::sync_with_stdio(false), cin.tie(nullptr); 31 | #ifdef LOCAL 32 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 33 | #endif 34 | 35 | int _ = 1; 36 | while (_--) solve(); 37 | 38 | #ifdef LOCAL 39 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 40 | #endif 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /AtCoder/arc148_a.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file arc148_a.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2022-09-11 5 | * 6 | * @copyright Copyright (c) 2022 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | #define maxn 200005 20 | 21 | int a[maxn]; 22 | 23 | void solve(void) { 24 | int n, v = 0; 25 | cin >> n; 26 | for (int i = 1; i <= n; i++) cin >> a[i]; 27 | for (int i = 2; i <= n; i++) v = __gcd(v, abs(a[i] - a[1])); 28 | cout << 1 + (v == 1) << endl; 29 | return; 30 | } 31 | 32 | bool mem2; 33 | 34 | int main() { 35 | ios::sync_with_stdio(false), cin.tie(nullptr); 36 | #ifdef LOCAL 37 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 38 | #endif 39 | 40 | int _ = 1; 41 | while (_--) solve(); 42 | 43 | #ifdef LOCAL 44 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 45 | #endif 46 | return 0; 47 | } -------------------------------------------------------------------------------- /Codeforces/1605B.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 1605B.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2021-12-31 5 | * 6 | * @copyright Copyright (c) 2021 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | bool mem1; 14 | 15 | const int prime[22] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79}; 16 | 17 | void solve(void) { 18 | int n; 19 | cin >> n; 20 | n--; 21 | for (int i = 0; i < 22; i++) 22 | if (n % prime[i] != 0) { 23 | cout << prime[i] << ' ' << n - prime[i] << ' ' << 1 << endl; 24 | return; 25 | } 26 | return; 27 | } 28 | 29 | bool mem2; 30 | 31 | int main() { 32 | #ifdef LOCAL 33 | cerr << "Memory: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 34 | #endif 35 | 36 | int _ = 1; 37 | cin >> _; 38 | while (_--) solve(); 39 | 40 | #ifdef LOCAL 41 | cerr << "Time: " << clock() * 1000. / CLOCKS_PER_SEC << "ms" << endl; 42 | #endif 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /AtCoder/arc120_d.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Macesuted (i@macesuted.moe) 3 | * @copyright Copyright (c) 2021 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | 9 | #define maxn 400005 10 | 11 | typedef pair pii; 12 | 13 | int a[maxn]; 14 | pii b[maxn]; 15 | bool vis[maxn]; 16 | 17 | stack S; 18 | 19 | string answer; 20 | 21 | int main() { 22 | ios::sync_with_stdio(false); 23 | int n; 24 | cin >> n; 25 | n <<= 1; 26 | for (register int i = 1; i <= n; i++) cin >> a[i]; 27 | for (register int i = 1; i <= n; i++) b[i] = (pii){a[i], i}; 28 | sort(b + 1, b + n + 1, greater()); 29 | for (register int i = 1; i * 2 <= n; i++) vis[b[i].second] = true; 30 | answer.resize(n); 31 | for (register int i = 1; i <= n; i++) 32 | if (S.empty() || vis[i] == S.top().second) 33 | S.push((pii){i, vis[i]}); 34 | else 35 | answer[S.top().first - 1] = '(', answer[i - 1] = ')', S.pop(); 36 | cout << answer << endl; 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /Codeforces Gym/104772K.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 104772K.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-07-02 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | void solve(void) { 20 | int64_t n; 21 | cin >> n; 22 | for (int i = 1;; i++) { 23 | int64_t m = n + i, bcnt = 0; 24 | while (m) bcnt += (m & 1), m >>= 1; 25 | if (bcnt <= i) return cout << i - 1 << endl, void(); 26 | } 27 | return; 28 | } 29 | 30 | bool mem2; 31 | 32 | int main() { 33 | ios::sync_with_stdio(false), cin.tie(nullptr); 34 | #ifdef LOCAL 35 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 36 | #endif 37 | 38 | int _ = 1; 39 | cin >> _; 40 | while (_--) solve(); 41 | 42 | #ifdef LOCAL 43 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 44 | #endif 45 | return 0; 46 | } -------------------------------------------------------------------------------- /Codeforces/1749B.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 1749B.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2022-10-20 5 | * 6 | * @copyright Copyright (c) 2022 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | void solve(void) { 20 | int n, maxv = 0; 21 | int64_t sum = 0; 22 | cin >> n; 23 | for (int i = 1, v; i <= n; i++) cin >> v, sum += v; 24 | for (int i = 1, v; i <= n; i++) cin >> v, maxv = max(maxv, v), sum += v; 25 | cout << sum - maxv << endl; 26 | return; 27 | } 28 | 29 | bool mem2; 30 | 31 | int main() { 32 | ios::sync_with_stdio(false), cin.tie(nullptr); 33 | #ifdef LOCAL 34 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 35 | #endif 36 | 37 | int _ = 1; 38 | cin >> _; 39 | while (_--) solve(); 40 | 41 | #ifdef LOCAL 42 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 43 | #endif 44 | return 0; 45 | } -------------------------------------------------------------------------------- /Misc/Tsinghua University Bootcamp 2025/Tsinghua Bootcamp 2025, Qualification Round/A.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file A.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-06-29 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | void solve(void) { 20 | string s; 21 | cin >> s; 22 | int n = s.size() - 1, ans = 0; 23 | for (int i = 0; i <= n; i++) 24 | if ((i & (n - i)) == 0) ans ^= s[i] - '0'; 25 | cout << ans << endl; 26 | return; 27 | } 28 | 29 | bool mem2; 30 | 31 | int main() { 32 | ios::sync_with_stdio(false), cin.tie(nullptr); 33 | #ifdef LOCAL 34 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 35 | #endif 36 | 37 | int _ = 1; 38 | while (_--) solve(); 39 | 40 | #ifdef LOCAL 41 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 42 | #endif 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /Codeforces Gym/105586N.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 105586N.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-01-04 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | typedef pair pis; 20 | 21 | void solve(void) { 22 | int n; 23 | cin >> n; 24 | vector v(n); 25 | for (int i = 0; i < n; i++) cin >> v[i].second >> v[i].first; 26 | sort(v.begin(), v.end(), greater()); 27 | cout << v.front().second << endl; 28 | return; 29 | } 30 | 31 | bool mem2; 32 | 33 | int main() { 34 | ios::sync_with_stdio(false), cin.tie(nullptr); 35 | #ifdef LOCAL 36 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 37 | #endif 38 | 39 | int _ = 1; 40 | while (_--) solve(); 41 | 42 | #ifdef LOCAL 43 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 44 | #endif 45 | return 0; 46 | } -------------------------------------------------------------------------------- /Codeforces/1629B.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 1629B.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2022-01-22 5 | * 6 | * @copyright Copyright (c) 2022 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define MP make_pair 14 | #define MT make_tuple 15 | 16 | bool mem1; 17 | 18 | void solve(void) { 19 | int l, r, k; 20 | cin >> l >> r >> k; 21 | if (l == 1 && r == 1) return cout << "NO" << endl, void(); 22 | if (l == r) return cout << "YES" << endl, void(); 23 | int cnt = r / 2 - (l - 1) / 2; 24 | cout << (r - l + 1 - cnt <= k ? "YES" : "NO") << endl; 25 | return; 26 | } 27 | 28 | bool mem2; 29 | 30 | int main() { 31 | ios::sync_with_stdio(false); 32 | #ifdef LOCAL 33 | cerr << "Memory: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 34 | #endif 35 | 36 | int _ = 1; 37 | cin >> _; 38 | while (_--) solve(); 39 | 40 | #ifdef LOCAL 41 | cerr << "Time: " << clock() * 1000. / CLOCKS_PER_SEC << "ms" << endl; 42 | #endif 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /Nowcoder/81600B.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 81600B.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-07-30 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define endl '\n' 14 | 15 | bool solve(void) { 16 | int64_t n, m, a, b; 17 | cin >> n >> m >> a >> b, a = !a, b = !b; 18 | if (n > m) swap(n, m); 19 | 20 | if (n == 1 && m == 2) return true; 21 | if (n % 2 == 1 && m % 2 == 1) return false; 22 | 23 | if (a == 1 && b == 1) return false; 24 | if (a == 0 && b == 0) return true; 25 | if (a == 1) { 26 | if (n == 1) return false; 27 | return true; 28 | } 29 | if (b == 1) { 30 | if (n == 1) return true; 31 | return false; 32 | } 33 | return false; 34 | } 35 | 36 | int main() { 37 | ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); 38 | 39 | int _ = 1; 40 | cin >> _; 41 | while (_--) cout << (solve() ? "Yes" : "No") << endl; 42 | 43 | return 0; 44 | } -------------------------------------------------------------------------------- /QOJ/5471.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 5471.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-11-04 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | int query(int64_t v) { 14 | cout << "query " << v << endl; 15 | int ret; 16 | cin >> ret; 17 | return ret; 18 | } 19 | 20 | void solve(void) { 21 | int s = query(0); 22 | int64_t ans = 0, pw10 = 1; 23 | for (int t = 0; t < 18; t++, pw10 *= 10) { 24 | int l = 1, r = 9, x = 0; 25 | while (l <= r) { 26 | int m = (l + r) / 2; 27 | if (query(m * pw10) == s + m) 28 | x = m, l = m + 1; 29 | else 30 | r = m - 1; 31 | } 32 | ans += (9 - x) * pw10; 33 | } 34 | 35 | cout << "answer " << ans << endl; 36 | 37 | return; 38 | } 39 | 40 | int main() { 41 | ios::sync_with_stdio(false), cin.tie(nullptr); 42 | 43 | int _ = 1; 44 | while (_--) solve(); 45 | 46 | return 0; 47 | } -------------------------------------------------------------------------------- /UOJ/235.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 235.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2022-12-03 5 | * 6 | * @copyright Copyright (c) 2022 7 | * 8 | */ 9 | 10 | #include "molecules.h" 11 | #include 12 | using namespace std; 13 | 14 | typedef pair pii; 15 | 16 | vector a; 17 | 18 | vector find_subset(int l, int r, vector w) { 19 | int n = w.size(); 20 | for (int i = 0; i < n; i++) a.emplace_back(w[i], i); 21 | sort(a.begin(), a.end()); 22 | int64_t suml = 0, sumr = 0; 23 | for (int i = 1; i <= n; i++) { 24 | suml += a[i - 1].first, sumr += a[n - i].first; 25 | vector ans; 26 | if (suml <= r && l <= sumr) { 27 | for (int j = i - 1, k = n - 1, sum = suml; ~j; j--) { 28 | while ((int64_t)sum + a[k].first - a[j].first > r) k--; 29 | ans.push_back(a[k].second), sum += a[k].first - a[j].first, k--; 30 | } 31 | return ans; 32 | } 33 | } 34 | return vector{}; 35 | } 36 | -------------------------------------------------------------------------------- /Codeforces/1625B.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 1625B.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2022-01-21 5 | * 6 | * @copyright Copyright (c) 2022 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | bool mem1; 14 | 15 | int a[150005]; 16 | map> rec; 17 | 18 | void solve(void) { 19 | int n; 20 | cin >> n; 21 | for (int i = 1; i <= n; i++) cin >> a[i], rec[a[i]].push_back(i); 22 | int ans = -1; 23 | for (auto i : rec) 24 | for (auto j = i.second.begin(); j + 1 != i.second.end(); j++) ans = max(ans, *j + (n - *(j + 1))); 25 | cout << ans << endl; 26 | rec.clear(); 27 | return; 28 | } 29 | 30 | bool mem2; 31 | 32 | int main() { 33 | #ifdef LOCAL 34 | cerr << "Memory: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 35 | #endif 36 | 37 | int _ = 1; 38 | cin >> _; 39 | while (_--) solve(); 40 | 41 | #ifdef LOCAL 42 | cerr << "Time: " << clock() * 1000. / CLOCKS_PER_SEC << "ms" << endl; 43 | #endif 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /FDUOJ/FDUPC_2025/FDUPC25P-B.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file FDUPC25P-B.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-11-27 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | void solve(void) { 20 | string s, t; 21 | cin >> s; 22 | for (size_t i = 0; i < s.size(); i++) { 23 | t.push_back(s[i]); 24 | if (i >= 10 && s.substr(i - 10, 11) == "TuLingJiang") t.push_back('~'); 25 | } 26 | 27 | cout << t << endl; 28 | 29 | return; 30 | } 31 | 32 | bool mem2; 33 | 34 | int main() { 35 | ios::sync_with_stdio(false), cin.tie(nullptr); 36 | #ifdef LOCAL 37 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 38 | #endif 39 | 40 | int _ = 1; 41 | while (_--) solve(); 42 | 43 | #ifdef LOCAL 44 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 45 | #endif 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /tools/windows/comp.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int System(string cmd) { return system(cmd.c_str()); } 5 | 6 | int main(int argc, char* argv[]) { 7 | assert(argc == 2); 8 | string name = argv[1]; 9 | System("g++ " + name + "-gen.cpp -o " + name + "-gen -Ofast"); 10 | System("g++ " + name + ".cpp -o " + name + " -O2"); 11 | System("g++ " + name + "-force.cpp -o " + name + "-force -Ofast"); 12 | for (int i = 1;; i++) { 13 | System(name + "-gen > " + name + ".in"); 14 | cout << "#########################" << endl; 15 | cout << "Test #" << i << endl; 16 | cout << "Solution:" << endl; 17 | System(name); 18 | cout << "Force:" << endl; 19 | System(name + "-force < " + name + ".in > " + name + ".ans"); 20 | if (System("check " + name + ".in " + name + ".out " + name + ".ans")) { 21 | cout << "Wrong Answer!" << endl; 22 | return 0; 23 | } 24 | cout << "Accepted!" << endl; 25 | } 26 | return 0; 27 | } -------------------------------------------------------------------------------- /Codeforces/1583B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #define int long long 5 | 6 | bool mem1; 7 | 8 | #define maxn 100005 9 | 10 | typedef pair pii; 11 | 12 | bool vis[maxn]; 13 | 14 | void solve(void) { 15 | int n, m; 16 | cin >> n >> m; 17 | for (int i = 1; i <= n; i++) vis[i] = false; 18 | for (int i = 1; i <= m; i++) { 19 | int a, b, c; 20 | cin >> a >> b >> c; 21 | vis[b] = true; 22 | } 23 | for (int i = 1; i <= n; i++) 24 | if (!vis[i]) { 25 | for (int j = 1; j <= n; j++) 26 | if (i != j) cout << i << ' ' << j << endl; 27 | return; 28 | } 29 | return; 30 | } 31 | 32 | bool mem2; 33 | 34 | signed main() { 35 | cerr << "Memory: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 36 | ios::sync_with_stdio(false); 37 | 38 | int _ = 1; 39 | cin >> _; 40 | while (_--) solve(); 41 | 42 | cerr << "Time: " << clock() * 1000. / CLOCKS_PER_SEC << "ms" << endl; 43 | return 0; 44 | } -------------------------------------------------------------------------------- /Codeforces/1987C.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 1987C.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-06-30 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | #define maxn 100005 20 | 21 | int a[maxn]; 22 | 23 | void solve(void) { 24 | int n; 25 | cin >> n; 26 | for (int i = 1; i <= n; i++) cin >> a[i]; 27 | for (int i = n - 1; i; i--) { 28 | a[i] = max(a[i], a[i + 1] + 1); 29 | } 30 | cout << a[1] << endl; 31 | return; 32 | } 33 | 34 | bool mem2; 35 | 36 | int main() { 37 | ios::sync_with_stdio(false), cin.tie(nullptr); 38 | #ifdef LOCAL 39 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 40 | #endif 41 | 42 | int _ = 1; 43 | cin >> _; 44 | while (_--) solve(); 45 | 46 | #ifdef LOCAL 47 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 48 | #endif 49 | return 0; 50 | } -------------------------------------------------------------------------------- /FDUOJ/FDUPC_2025/FDUPC25P-D.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file FDUPC25P-D.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-11-27 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | bool mem1; 14 | 15 | int query(int op) { 16 | cout << "? " << op << endl; 17 | int t; 18 | cin >> t; 19 | return t; 20 | } 21 | 22 | void solve(void) { 23 | int x = 1; 24 | while (query(0)) x++; 25 | int n = 1; 26 | while (query(1)) n++; 27 | for (int i = n; i > x; i--) query(0); 28 | cout << "! " << n << ' ' << x << endl; 29 | return; 30 | } 31 | 32 | bool mem2; 33 | 34 | int main() { 35 | ios::sync_with_stdio(false), cin.tie(nullptr); 36 | #ifdef LOCAL 37 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 38 | #endif 39 | 40 | int _ = 1; 41 | while (_--) solve(); 42 | 43 | #ifdef LOCAL 44 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 45 | #endif 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /Codeforces/1566C.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Macesuted (i@macesuted.moe) 3 | * @copyright Copyright (c) 2021 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | 9 | #define int long long 10 | 11 | #define maxn 100005 12 | 13 | bool use[maxn]; 14 | 15 | string a, b; 16 | 17 | void work(void) { 18 | int n; 19 | cin >> n >> a >> b; 20 | a = ' ' + a, b = ' ' + b; 21 | int answer = 0; 22 | for (register int i = 1; i <= n; i++) use[i] = false; 23 | for (register int i = 1; i <= n; i++) 24 | if (a[i] != b[i]) answer += 2, use[i] = true; 25 | for (register int i = 1; i < n; i++) { 26 | if (use[i] || use[i + 1]) continue; 27 | if (a[i] != a[i + 1]) use[i] = use[i + 1] = true, answer += 2; 28 | } 29 | for (register int i = 1; i <= n; i++) 30 | if (!use[i] && a[i] == '0') answer++; 31 | cout << answer << endl; 32 | return; 33 | } 34 | 35 | signed main() { 36 | ios::sync_with_stdio(false); 37 | int _ = 1; 38 | cin >> _; 39 | while (_--) work(); 40 | return 0; 41 | } -------------------------------------------------------------------------------- /Codeforces/1729A.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 1729A.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2022-09-12 5 | * 6 | * @copyright Copyright (c) 2022 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | void solve(void) { 20 | int a, b, c, v; 21 | cin >> a >> b >> c, v = min(a, abs(b - c) + c); 22 | if (v == a && v != abs(b - c) + c) cout << 1 << endl; 23 | if (v != a && v == abs(b - c) + c) cout << 2 << endl; 24 | if (v == a && v == abs(b - c) + c) cout << 3 << endl; 25 | return; 26 | } 27 | 28 | bool mem2; 29 | 30 | int main() { 31 | ios::sync_with_stdio(false), cin.tie(nullptr); 32 | #ifdef LOCAL 33 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 34 | #endif 35 | 36 | int _ = 1; 37 | cin >> _; 38 | while (_--) solve(); 39 | 40 | #ifdef LOCAL 41 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 42 | #endif 43 | return 0; 44 | } -------------------------------------------------------------------------------- /Codeforces/2042A.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 2042A.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-12-02 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | void solve(void) { 20 | int n, k; 21 | cin >> n >> k; 22 | vector a; 23 | for (int i = 1, v; i <= n; i++) cin >> v, a.push_back(v); 24 | sort(a.begin(), a.end()); 25 | while (!a.empty() && a.back() <= k) k -= a.back(), a.pop_back(); 26 | cout << k << endl; 27 | return; 28 | } 29 | 30 | bool mem2; 31 | 32 | int main() { 33 | ios::sync_with_stdio(false), cin.tie(nullptr); 34 | #ifdef LOCAL 35 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 36 | #endif 37 | 38 | int _ = 1; 39 | cin >> _; 40 | while (_--) solve(); 41 | 42 | #ifdef LOCAL 43 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 44 | #endif 45 | return 0; 46 | } -------------------------------------------------------------------------------- /AtCoder/abc210_d.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Macesuted (i@macesuted.moe) 3 | * @copyright Copyright (c) 2021 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | 9 | #define int long long 10 | 11 | int a[1005][1005], f[1005][1005]; 12 | 13 | signed main() { 14 | ios::sync_with_stdio(false); 15 | int n, m, c; 16 | cin >> n >> m >> c; 17 | for (register int i = 1; i <= n; i++) 18 | for (register int j = 1; j <= m; j++) cin >> a[i][j]; 19 | int answer = 0x3f3f3f3f3f3f3f3f; 20 | for (register int i = 1; i <= n; i++) { 21 | for (register int j = 1; j <= m; j++) { 22 | f[i][j] = 0x3f3f3f3f3f3f3f3f; 23 | if (i > 1) f[i][j] = min(f[i][j], f[i - 1][j] + c); 24 | if (j > 1) f[i][j] = min(f[i][j], f[i][j - 1] + c); 25 | answer = min(answer, f[i][j] + a[i][j]); 26 | f[i][j] = min(f[i][j], a[i][j]); 27 | } 28 | for (register int j = m - 1; j; j--) f[i][j] = min(f[i][j], f[i][j + 1] + c); 29 | } 30 | cout << answer << endl; 31 | return 0; 32 | } -------------------------------------------------------------------------------- /QOJ/9328.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 9328.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-10-31 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define endl '\n' 14 | 15 | bool solve(void) { 16 | int n; 17 | string s; 18 | cin >> n >> s; 19 | 20 | vector> cnt(2, vector(26, 0)); 21 | for (int i = 0; i < n; i++) cnt[i & 1][s[i] - 'a']++; 22 | 23 | if (n & 1) { 24 | int cc[2] = {0, 0}; 25 | for (int t = 0; t < 2; t++) 26 | for (int i = 0; i < 26; i++) cc[t] += cnt[t][i] & 1; 27 | int x = n >> 1 & 1; 28 | return cc[!x] == 0 && cc[x] == 1; 29 | } 30 | 31 | for (int i = 0; i < 26; i++) 32 | if (cnt[0][i] != cnt[1][i]) return false; 33 | return true; 34 | } 35 | 36 | int main() { 37 | ios::sync_with_stdio(false), cin.tie(nullptr); 38 | 39 | int _ = 1; 40 | cin >> _; 41 | while (_--) cout << (solve() ? "YES" : "NO") << endl; 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /Codeforces Gym/104772D.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 104772D.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-07-02 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | int gcd(int x, int y) { return x ? gcd(y % x, x) : y; } 20 | 21 | void solve(void) { 22 | int n; 23 | cin >> n; 24 | int sum = 0, tn = n; 25 | while (tn) sum += tn % 10, tn /= 10; 26 | int lcm = sum / gcd(sum, n) * n; 27 | for (int i = lcm / sum; i; i--) cout << n; 28 | cout << endl; 29 | return; 30 | } 31 | 32 | bool mem2; 33 | 34 | int main() { 35 | ios::sync_with_stdio(false), cin.tie(nullptr); 36 | #ifdef LOCAL 37 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 38 | #endif 39 | 40 | int _ = 1; 41 | while (_--) solve(); 42 | 43 | #ifdef LOCAL 44 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 45 | #endif 46 | return 0; 47 | } -------------------------------------------------------------------------------- /Codeforces Gym/105586A.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 105586A.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-01-04 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | void solve(void) { 20 | int n; 21 | cin >> n; 22 | vector a; 23 | for (int i = 1; i <= n; i++) { 24 | string s; 25 | cin >> s; 26 | a.push_back(s); 27 | if (s == "Tomori") a.push_back("Haruhikage"); 28 | } 29 | for (auto i : a) cout << i << endl; 30 | return; 31 | } 32 | 33 | bool mem2; 34 | 35 | int main() { 36 | ios::sync_with_stdio(false), cin.tie(nullptr); 37 | #ifdef LOCAL 38 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 39 | #endif 40 | 41 | int _ = 1; 42 | while (_--) solve(); 43 | 44 | #ifdef LOCAL 45 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 46 | #endif 47 | return 0; 48 | } -------------------------------------------------------------------------------- /Codeforces/1616A.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 1616A.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2022-01-02 5 | * 6 | * @copyright Copyright (c) 2022 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | bool mem1; 14 | 15 | #define maxn 105 16 | 17 | int a[maxn * 2]; 18 | 19 | void solve(void) { 20 | int n; 21 | cin >> n; 22 | memset(a, 0, sizeof(a)); 23 | for (int i = 1; i <= n; i++) { 24 | int t; 25 | cin >> t; 26 | a[t + maxn]++; 27 | } 28 | int ans = min(a[0 + maxn], 1); 29 | for (int i = 1; i <= 100; i++) ans += min(a[i + maxn] + a[-i + maxn], 2); 30 | cout << ans << endl; 31 | return; 32 | } 33 | 34 | bool mem2; 35 | 36 | int main() { 37 | #ifdef LOCAL 38 | cerr << "Memory: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 39 | #endif 40 | 41 | int _ = 1; 42 | cin >> _; 43 | while (_--) solve(); 44 | 45 | #ifdef LOCAL 46 | cerr << "Time: " << clock() * 1000. / CLOCKS_PER_SEC << "ms" << endl; 47 | #endif 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /Codeforces/1634A.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 1634A.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2022-02-17 5 | * 6 | * @copyright Copyright (c) 2022 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define MP make_pair 14 | #define MT make_tuple 15 | 16 | bool mem1; 17 | 18 | void solve(void) { 19 | int n, k; 20 | string s; 21 | cin >> n >> k >> s; 22 | s = " " + s; 23 | if (k == 0) return cout << 1 << endl, void(); 24 | bool check = true; 25 | for (int i = 1; i <= n; i++) 26 | if (s[i] != s[n - i + 1]) check = false; 27 | cout << 2 - int(check) << endl; 28 | return; 29 | } 30 | 31 | bool mem2; 32 | 33 | int main() { 34 | ios::sync_with_stdio(false); 35 | #ifdef LOCAL 36 | cerr << "Memory: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 37 | #endif 38 | 39 | int _ = 1; 40 | cin >> _; 41 | while (_--) solve(); 42 | 43 | #ifdef LOCAL 44 | cerr << "Time: " << clock() * 1000. / CLOCKS_PER_SEC << "ms" << endl; 45 | #endif 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /tools/linux/comp.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int System(string cmd) { return system(cmd.c_str()); } 5 | 6 | int main(int argc, char* argv[]) { 7 | assert(argc == 2); 8 | string name = argv[1]; 9 | System("g++ " + name + "-gen.cpp -o " + name + "-gen -Ofast"); 10 | System("g++ " + name + ".cpp -o " + name + " -O2"); 11 | System("g++ " + name + "-force.cpp -o " + name + "-force -Ofast"); 12 | for (int i = 1;; i++) { 13 | System("./" + name + "-gen > " + name + ".in"); 14 | cout << "#########################" << endl; 15 | cout << "Test #" << i << endl; 16 | cout << "Solution:" << endl; 17 | System("time -p ./" + name); 18 | cout << "Force:" << endl; 19 | System("time -p ./" + name + "-force < " + name + ".in > " + name + ".ans"); 20 | if (System("check " + name + ".out " + name + ".ans")) { 21 | cout << "Wrong Answer!" << endl; 22 | return 0; 23 | } 24 | cout << "Accepted!" << endl; 25 | } 26 | return 0; 27 | } -------------------------------------------------------------------------------- /Codeforces Gym/102428I.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 102428I.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-07-25 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define maxn 2005 14 | #define mod 1000000007 15 | 16 | vector graph[maxn]; 17 | 18 | int f[maxn]; 19 | int n, m; 20 | 21 | int64_t dfs(int p) { 22 | if (p > m) return f[p] = 1; 23 | f[p] = 0; 24 | for (auto i : graph[p]) 25 | if (f[i]) 26 | f[p] = (f[p] + f[i]) % mod; 27 | else 28 | f[p] = (f[p] + dfs(i)) % mod; 29 | return f[p]; 30 | } 31 | 32 | int main() { 33 | ios::sync_with_stdio(false), cin.tie(nullptr); 34 | 35 | cin >> n >> m; 36 | 37 | for (int i = 1, s, x; i <= m; i++) { 38 | cin >> s; 39 | while (s--) cin >> x, graph[i].push_back(x); 40 | } 41 | 42 | cout << dfs(1) << ' '; 43 | 44 | int tot = 0; 45 | for (int i = m + 1; i <= n; i++) tot += f[i]; 46 | 47 | cout << tot << endl; 48 | 49 | return 0; 50 | } -------------------------------------------------------------------------------- /Codeforces/1622A.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 1622A.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2022-01-30 5 | * 6 | * @copyright Copyright (c) 2022 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define MP make_pair 14 | #define MT make_tuple 15 | 16 | bool mem1; 17 | 18 | void solve(void) { 19 | int a, b, c; 20 | cin >> a >> b >> c; 21 | if (a > b) swap(a, b); 22 | if (a > c) swap(a, c); 23 | if (b > c) swap(b, c); 24 | if (c == a + b || (b == c && a % 2 == 0) || (a == b && c % 2 == 0)) 25 | cout << "YES" << endl; 26 | else 27 | cout << "NO" << endl; 28 | return; 29 | } 30 | 31 | bool mem2; 32 | 33 | int main() { 34 | ios::sync_with_stdio(false); 35 | #ifdef LOCAL 36 | cerr << "Memory: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 37 | #endif 38 | 39 | int _ = 1; 40 | cin >> _; 41 | while (_--) solve(); 42 | 43 | #ifdef LOCAL 44 | cerr << "Time: " << clock() * 1000. / CLOCKS_PER_SEC << "ms" << endl; 45 | #endif 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /HDOJ/7468.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 7468.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-07-26 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define maxn 100005 14 | 15 | int a[maxn]; 16 | 17 | void solve(void) { 18 | int n, l, d; 19 | cin >> n >> l >> d; 20 | for (int i = 1; i <= n; i++) cin >> a[i]; 21 | sort(a + 2, a + n + 1); 22 | if (a[1] >= l) { 23 | if (a[4] < l) { 24 | int p = 4; 25 | while (p < n && a[p + 1] < l) p++; 26 | if (a[1] - a[2] > d) return cout << "Yes" << endl, void(); 27 | } 28 | } else { 29 | if (a[3] < l) { 30 | if (max(a[1], a[n]) - min(a[1], a[2]) > d) return cout << "Yes" << endl, void(); 31 | } 32 | } 33 | cout << "No" << endl; 34 | return; 35 | } 36 | 37 | int main() { 38 | ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); 39 | 40 | int _; 41 | cin >> _; 42 | while (_--) solve(); 43 | 44 | return 0; 45 | } -------------------------------------------------------------------------------- /Nowcoder/81603K.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 81603K.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-08-08 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define maxn 500005 14 | 15 | bool f[maxn]; 16 | 17 | void solve(void) { 18 | string s; 19 | cin >> s; 20 | int n = s.size(); 21 | s = ' ' + s; 22 | for (int i = 0; i <= n; i++) f[i] = false; 23 | f[0] = true; 24 | for (int i = 1; i < n; i++) { 25 | if (!f[i - 1]) continue; 26 | if (i + 2 <= n && s[i] == 'a' && s[i + 1] == 'v' && s[i + 2] == 'a') f[i + 2] = true; 27 | if (i + 4 <= n && s[i] == 'a' && s[i + 1] == 'v' && s[i + 2] == 'a' && s[i + 3] == 'v' && s[i + 4] == 'a') 28 | f[i + 4] = true; 29 | } 30 | cout << (f[n] ? "Yes" : "No") << endl; 31 | return; 32 | } 33 | 34 | int main() { 35 | ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); 36 | 37 | int _; 38 | cin >> _; 39 | while (_--) solve(); 40 | 41 | return 0; 42 | } -------------------------------------------------------------------------------- /QOJ/7757.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 7757.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-11-07 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define endl '\n' 14 | 15 | void solve(void) { 16 | int n; 17 | cin >> n; 18 | 19 | vector a(n + 1), pos(n + 1); 20 | 21 | for (int i = 1; i <= n; i++) cin >> a[i]; 22 | for (int i = 1, x; i <= n; i++) cin >> x, pos[x] = i; 23 | for (int i = 1; i <= n; i++) a[i] = pos[a[i]]; 24 | 25 | string ans; 26 | for (int i = 1; i < n; i++) { 27 | for (int j = 1; j < n; j++) 28 | if (a[j] > a[j + 1]) 29 | ans.push_back('2'), swap(a[j], a[j + 1]); 30 | else 31 | ans.push_back('1'); 32 | ans.push_back('1'); 33 | } 34 | cout << ans << endl; 35 | return; 36 | } 37 | 38 | int main() { 39 | ios::sync_with_stdio(false), cin.tie(nullptr); 40 | 41 | int _ = 1; 42 | cin >> _; 43 | while (_--) solve(); 44 | 45 | return 0; 46 | } -------------------------------------------------------------------------------- /Codeforces/1625A.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 1625A.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2022-01-21 5 | * 6 | * @copyright Copyright (c) 2022 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | bool mem1; 14 | 15 | int cnt[33]; 16 | 17 | void solve(void) { 18 | int n, l; 19 | cin >> n >> l; 20 | memset(cnt, 0, sizeof(cnt)); 21 | for (int i = 1; i <= n; i++) { 22 | int t; 23 | cin >> t; 24 | for (int j = 0; j < l; j++, t >>= 1) cnt[j] += (t & 1); 25 | } 26 | int ans = 0; 27 | for (int i = l - 1; ~i; i--) ans = (ans << 1) + ((cnt[i] > n - cnt[i]) ? 1 : 0); 28 | cout << ans << endl; 29 | return; 30 | } 31 | 32 | bool mem2; 33 | 34 | int main() { 35 | #ifdef LOCAL 36 | cerr << "Memory: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 37 | #endif 38 | 39 | int _ = 1; 40 | cin >> _; 41 | while (_--) solve(); 42 | 43 | #ifdef LOCAL 44 | cerr << "Time: " << clock() * 1000. / CLOCKS_PER_SEC << "ms" << endl; 45 | #endif 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /Codeforces/2180A.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 2180A.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-12-19 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | #define maxn 5005 20 | 21 | bool vis[maxn]; 22 | 23 | void solve(void) { 24 | int l, a, b; 25 | cin >> l >> a >> b; 26 | for (int i = 0; i < l; i++) vis[i] = false; 27 | int ans = 0; 28 | while (!vis[a]) ans = max(ans, a), vis[a] = true, a = (a + b) % l; 29 | cout << ans << endl; 30 | return; 31 | } 32 | 33 | bool mem2; 34 | 35 | int main() { 36 | ios::sync_with_stdio(false), cin.tie(nullptr); 37 | #ifdef LOCAL 38 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 39 | #endif 40 | 41 | int _ = 1; 42 | cin >> _; 43 | while (_--) solve(); 44 | 45 | #ifdef LOCAL 46 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 47 | #endif 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /Codeforces/1704B.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 1704B.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2022-07-31 5 | * 6 | * @copyright Copyright (c) 2022 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | void solve(void) { 20 | int n, x, ans = 0, lef = INT_MAX, rig = INT_MIN; 21 | cin >> n >> x; 22 | for (int i = 1, a; i <= n; i++) { 23 | cin >> a; 24 | lef = min(lef, a), rig = max(rig, a); 25 | if (rig - lef > 2 * x) lef = rig = a, ans++; 26 | } 27 | cout << ans << endl; 28 | return; 29 | } 30 | 31 | bool mem2; 32 | 33 | int main() { 34 | ios::sync_with_stdio(false), cin.tie(nullptr); 35 | #ifdef LOCAL 36 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 37 | #endif 38 | 39 | int _ = 1; 40 | cin >> _; 41 | while (_--) solve(); 42 | 43 | #ifdef LOCAL 44 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 45 | #endif 46 | return 0; 47 | } -------------------------------------------------------------------------------- /Codeforces/2053A.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 2053A.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-12-28 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | void solve(void) { 20 | vector a; 21 | int n; 22 | cin >> n; 23 | for (int i = 0, v; i < n; i++) cin >> v, a.push_back(v); 24 | for (int i = 0; i < n - 1; i++) 25 | if (min(a[i], a[i + 1]) * 2 > max(a[i], a[i + 1])) return cout << "YES" << endl, void(); 26 | cout << "NO" << endl; 27 | return; 28 | } 29 | 30 | bool mem2; 31 | 32 | int main() { 33 | ios::sync_with_stdio(false), cin.tie(nullptr); 34 | #ifdef LOCAL 35 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 36 | #endif 37 | 38 | int _ = 1; 39 | cin >> _; 40 | while (_--) solve(); 41 | 42 | #ifdef LOCAL 43 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 44 | #endif 45 | return 0; 46 | } -------------------------------------------------------------------------------- /Codeforces/2180B.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 2180B.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-12-19 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | #define maxn 1005 20 | 21 | string a[maxn]; 22 | 23 | void solve(void) { 24 | int n; 25 | cin >> n; 26 | for (int i = 1; i <= n; i++) cin >> a[i]; 27 | 28 | string ans = ""; 29 | for (int i = 1; i <= n; i++) ans = min(ans + a[i], a[i] + ans); 30 | 31 | cout << ans << endl; 32 | 33 | return; 34 | } 35 | 36 | bool mem2; 37 | 38 | int main() { 39 | ios::sync_with_stdio(false), cin.tie(nullptr); 40 | #ifdef LOCAL 41 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 42 | #endif 43 | 44 | int _ = 1; 45 | cin >> _; 46 | while (_--) solve(); 47 | 48 | #ifdef LOCAL 49 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 50 | #endif 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /HDOJ/7533.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 7533.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-08-19 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define endl '\n' 14 | 15 | int64_t read() { 16 | int64_t res = 0; 17 | char ch = getchar(); 18 | while (ch < '0' || ch > '9') ch = getchar(); 19 | while (ch >= '0' && ch <= '9') { 20 | res = res * 10 + ch - '0'; 21 | ch = getchar(); 22 | } 23 | return res; 24 | } 25 | 26 | void solve(void) { 27 | bool a[2] = {false, false}; 28 | int64_t k = read(), x = read(), y = read(); 29 | if (x > y) swap(x, y); 30 | int64_t n = (k - 1) / y + 1; 31 | int t = n & 1; 32 | a[!t] = true; 33 | if (n * x < k) a[t] = true; 34 | for (int i = 0; i < 2; i++) cout << (a[i] ? "Yes" : "No") << endl; 35 | return; 36 | } 37 | 38 | int main() { 39 | ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); 40 | 41 | int _ = read(); 42 | while (_--) solve(); 43 | 44 | return 0; 45 | } -------------------------------------------------------------------------------- /Misc/Tsinghua University Bootcamp in Summer 2024/Tsinghua Bootcamp 2024. Day 3/D.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file D.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-08-22 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | bool mem1; 14 | 15 | #define maxn 100005 16 | 17 | int64_t l[maxn], r[maxn]; 18 | 19 | bool mem2; 20 | 21 | void solve(void) { 22 | int n; 23 | int64_t sum, suml = 0, sumr = 0; 24 | cin >> n >> sum; 25 | for (int i = 1; i <= n; i++) cin >> l[i] >> r[i], suml += l[i], sumr += r[i]; 26 | for (int i = 1; i <= n; i++) { 27 | suml -= l[i], sumr -= r[i]; 28 | int64_t vl = max(l[i], sum - sumr), vr = min(r[i], sum - suml); 29 | cout << max((int64_t)0, vr - vl + 1) << ' '; 30 | suml += l[i], sumr += r[i]; 31 | } 32 | cout << endl; 33 | return; 34 | } 35 | 36 | int main() { 37 | ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); 38 | 39 | int _ = 1; 40 | while (_--) solve(); 41 | 42 | return 0; 43 | } -------------------------------------------------------------------------------- /QOJ/6128.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 6128.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-10-18 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define endl '\n' 14 | 15 | #define maxn 1000005 16 | 17 | int a[maxn]; 18 | 19 | void solve(void) { 20 | int n; 21 | cin >> n; 22 | string s, t; 23 | cin >> s >> t; 24 | for (int i = 1; i <= n; i++) a[i] = (s[i - 1] ^ t[i - 1]); 25 | a[n + 1] = 0; 26 | for (int i = n + 1; i; i--) a[i] ^= a[i - 1]; 27 | int cnt = 0; 28 | for (int i = 1; i <= n + 1; i++) cnt += a[i]; 29 | if (cnt == 0) 30 | cout << (int64_t)n * (n + 1) / 2 << endl; 31 | else if (cnt == 2) 32 | cout << 2 * (n - 1) << endl; 33 | else if (cnt == 4) 34 | cout << 6 << endl; 35 | else 36 | cout << 0 << endl; 37 | return; 38 | } 39 | 40 | int main() { 41 | ios::sync_with_stdio(false), cin.tie(nullptr); 42 | 43 | int _ = 1; 44 | cin >> _; 45 | while (_--) solve(); 46 | 47 | return 0; 48 | } -------------------------------------------------------------------------------- /QOJ/9136.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 9136.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-09-03 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define endl '\n' 14 | void solve(void) { 15 | int n = 4, k = 2048; 16 | cout << 25 << endl; 17 | cout << "$0 = $1 * " << fixed << 1. / k << endl; 18 | for (int i = 1; i <= n; i++) cout << "$" << i << " = $0 * $" << i - 1 << endl; 19 | for (int i = 1; i <= n; i++) { 20 | double frac = 1; 21 | for (int j = 1; j <= i + 1; j++) frac /= j; 22 | cout << "$" << i << " = $" << i << " * " << fixed << frac << endl; 23 | } 24 | cout << "$0 = $0 + 1" << endl; 25 | for (int i = 1; i <= n; i++) cout << "$0 = $0 + $" << i << endl; 26 | for (int i = 2; i <= k; i *= 2) cout << "$0 = $0 * $0" << endl; 27 | return; 28 | } 29 | 30 | int main() { 31 | ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); 32 | 33 | cout << setprecision(15); 34 | solve(); 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /AtCoder/arc127_b.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Macesuted (i@macesuted.moe) 3 | * @copyright Copyright (c) 2021 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | 9 | #define int long long 10 | 11 | #define maxn 1000005 12 | #define maxl 20 13 | 14 | int a[maxn][maxl]; 15 | 16 | void work(void) { 17 | int n, l; 18 | cin >> n >> l; 19 | for (register int i = 0; i < n; i++) { 20 | for (register int j = l - 1, S = i; j; j--) { 21 | int k = S % 3; 22 | S /= 3; 23 | a[i][j] = (k + 2) % 3; 24 | a[i + n][j] = (k + 1) % 3; 25 | a[i + n + n][j] = (k + 0) % 3; 26 | } 27 | } 28 | for (register int i = 0; i < 3 * n; i++) { 29 | cout << i / n; 30 | for (register int j = 1; j < l; j++) cout << a[i][j]; 31 | cout << endl; 32 | } 33 | return; 34 | } 35 | 36 | signed main() { 37 | ios::sync_with_stdio(false); 38 | cout << setiosflags(ios::fixed) << setprecision(11); 39 | int _ = 1; 40 | // cin >> _; 41 | while (_--) work(); 42 | return 0; 43 | } -------------------------------------------------------------------------------- /Codeforces/1801A.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 1801A.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2023-03-09 5 | * 6 | * @copyright Copyright (c) 2023 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | void solve(void) { 20 | int n, m; 21 | cin >> n >> m; 22 | cout << n * m << endl; 23 | int b = 1; 24 | while (b < m) b <<= 1; 25 | for (int i = 1; i <= n; i++) { 26 | int c = (i - 1) * b; 27 | for (int j = 1; j <= m; j++) cout << c++ << ' '; 28 | cout << endl; 29 | } 30 | return; 31 | } 32 | 33 | bool mem2; 34 | 35 | int main() { 36 | ios::sync_with_stdio(false), cin.tie(nullptr); 37 | #ifdef LOCAL 38 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 39 | #endif 40 | 41 | int _ = 1; 42 | cin >> _; 43 | while (_--) solve(); 44 | 45 | #ifdef LOCAL 46 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 47 | #endif 48 | return 0; 49 | } -------------------------------------------------------------------------------- /Codeforces Gym/101808F.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 101808F.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-07-21 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | #define mod 7901 20 | #define maxn 1005 21 | 22 | int cnt[maxn]; 23 | 24 | void solve(void) { 25 | int n; 26 | cin >> n; 27 | int64_t ans = 1; 28 | for (int i = 1; i < maxn; i++) cnt[i] = 0; 29 | for (int i = 1, v; i <= n; i++) cin >> v, ans = ans * ++cnt[v] % mod; 30 | cout << ans << endl; 31 | return; 32 | } 33 | 34 | bool mem2; 35 | 36 | int main() { 37 | ios::sync_with_stdio(false), cin.tie(nullptr); 38 | #ifdef LOCAL 39 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 40 | #endif 41 | 42 | int _ = 1; 43 | cin >> _; 44 | while (_--) solve(); 45 | 46 | #ifdef LOCAL 47 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 48 | #endif 49 | return 0; 50 | } -------------------------------------------------------------------------------- /Codeforces/1593B.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Macesuted (i@macesuted.moe) 3 | * @copyright Copyright (c) 2021 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | 9 | #define int long long 10 | 11 | #define maxn 1000005 12 | 13 | void work(void) { 14 | string s; 15 | cin >> s; 16 | int answer = 0x3f3f3f3f; 17 | for (int i = 0; i < (int)s.size(); i++) { 18 | if (s[i] != '2' && s[i] != '7') continue; 19 | for (int j = i + 1; j < (int)s.size(); j++) 20 | if (s[j] == '5') answer = min(answer, (int)s.size() - i - 2); 21 | } 22 | for (int i = 0; i < (int)s.size(); i++) { 23 | if (s[i] != '0' && s[i] != '5') continue; 24 | for (int j = i + 1; j < (int)s.size(); j++) 25 | if (s[j] == '0') answer = min(answer, (int)s.size() - i - 2); 26 | } 27 | cout << answer << endl; 28 | return; 29 | } 30 | 31 | signed main() { 32 | ios::sync_with_stdio(false); 33 | cout << setiosflags(ios::fixed) << setprecision(11); 34 | int _ = 1; 35 | cin >> _; 36 | while (_--) work(); 37 | return 0; 38 | } -------------------------------------------------------------------------------- /Nowcoder/247577.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 247577.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2023-01-06 5 | * 6 | * @copyright Copyright (c) 2023 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | set S; 20 | 21 | void solve(void) { 22 | int n, k; 23 | cin >> n >> k; 24 | for (int i = 0; i <= n; i++) S.insert(i); 25 | while (k--) { 26 | int op, x; 27 | cin >> op >> x; 28 | if (op == 1) 29 | S.erase(x); 30 | else 31 | cout << *--S.find(x) << endl; 32 | } 33 | return; 34 | } 35 | 36 | bool mem2; 37 | 38 | int main() { 39 | ios::sync_with_stdio(false), cin.tie(nullptr); 40 | #ifdef LOCAL 41 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 42 | #endif 43 | 44 | int _ = 1; 45 | while (_--) solve(); 46 | 47 | #ifdef LOCAL 48 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 49 | #endif 50 | return 0; 51 | } -------------------------------------------------------------------------------- /Codeforces/1352A.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 1352A.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2022-01-25 5 | * 6 | * @copyright Copyright (c) 2022 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define MP make_pair 14 | #define MT make_tuple 15 | 16 | bool mem1; 17 | 18 | void solve(void) { 19 | string s; 20 | cin >> s; 21 | vector ans; 22 | for (int i = s.size() - 1, base = 1; ~i; i--, base *= 10) { 23 | if (s[i] == '0') continue; 24 | ans.push_back((s[i] - '0') * base); 25 | } 26 | cout << ans.size() << endl; 27 | for (auto i : ans) cout << i << ' '; 28 | cout << endl; 29 | return; 30 | } 31 | 32 | bool mem2; 33 | 34 | int main() { 35 | ios::sync_with_stdio(false); 36 | #ifdef LOCAL 37 | cerr << "Memory: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 38 | #endif 39 | 40 | int _ = 1; 41 | cin >> _; 42 | while (_--) solve(); 43 | 44 | #ifdef LOCAL 45 | cerr << "Time: " << clock() * 1000. / CLOCKS_PER_SEC << "ms" << endl; 46 | #endif 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /HDOJ/6182.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 6182.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-07-28 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | using int128_t = __int128_t; 20 | 21 | int128_t qpow(int128_t a, int128_t b) { 22 | int128_t ans = 1; 23 | while (b) b--, ans *= a; 24 | return ans; 25 | } 26 | 27 | void solve(void) { 28 | int64_t n; 29 | while (cin >> n) { 30 | int x = 1; 31 | while (qpow(x + 1, x + 1) <= n) x++; 32 | cout << x << endl; 33 | } 34 | return; 35 | } 36 | 37 | bool mem2; 38 | 39 | int main() { 40 | ios::sync_with_stdio(false), cin.tie(nullptr); 41 | #ifdef LOCAL 42 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 43 | #endif 44 | 45 | int _ = 1; 46 | while (_--) solve(); 47 | 48 | #ifdef LOCAL 49 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 50 | #endif 51 | return 0; 52 | } -------------------------------------------------------------------------------- /QOJ/10117.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 10117.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-03-13 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | int cnt0[10], cnt1[10]; 14 | 15 | void solve(void) { 16 | int64_t n; 17 | cin >> n; 18 | 19 | memset(cnt0, 0, sizeof(cnt0)); 20 | 21 | int64_t d = 1; 22 | while (d <= n / 10) d *= 10; 23 | 24 | for (int64_t i = d; i; i /= 10) cnt0[n / i % 10]++; 25 | 26 | int ans = 0; 27 | for (int i = 2; n / i >= d; i++) { 28 | if (n % i) continue; 29 | memset(cnt1, 0, sizeof(cnt1)); 30 | for (int64_t j = d; j; j /= 10) cnt1[n / i / j % 10]++; 31 | bool chk = true; 32 | for (int j = 0; j < 10; j++) chk &= (cnt0[j] == cnt1[j]); 33 | ans += chk; 34 | } 35 | 36 | cout << ans << endl; 37 | 38 | return; 39 | } 40 | 41 | int main() { 42 | ios::sync_with_stdio(false), cin.tie(nullptr); 43 | 44 | int _ = 1; 45 | cin >> _; 46 | while (_--) solve(); 47 | 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /QOJ/14724.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 14724.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-11-05 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define endl '\n' 14 | 15 | using pii = pair; 16 | 17 | void solve(void) { 18 | int n, q; 19 | cin >> n >> q; 20 | 21 | vector a; 22 | for (int i = 1, l, r; i <= q; i++) cin >> l >> r, a.emplace_back(l, r); 23 | 24 | sort(a.begin(), a.end(), [&](const pii& a, const pii& b) -> bool { return a.second < b.second; }); 25 | 26 | set S; 27 | S.insert(n + 1); 28 | for (int i = 0; i < q; i++) { 29 | if (*S.lower_bound(a[i].first) <= a[i].second) continue; 30 | S.insert(a[i].second); 31 | } 32 | 33 | int ans = 1; 34 | while ((1 << ans) - 1 < S.size() - 1) ans++; 35 | 36 | cout << ans << endl; 37 | 38 | return; 39 | } 40 | 41 | int main() { 42 | ios::sync_with_stdio(false), cin.tie(nullptr); 43 | 44 | int _ = 1; 45 | cin >> _; 46 | while (_--) solve(); 47 | 48 | return 0; 49 | } -------------------------------------------------------------------------------- /Online Judge/10104.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Macesuted (i@macesuted.moe) 3 | * @copyright Copyright (c) 2021 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | 9 | long long exgcd(long long a, long long b, long long &x, long long &y) { 10 | if (b == 0) return x = 1, y = 0, a; 11 | long long g = exgcd(b, a % b, x, y); 12 | return tie(x, y) = make_tuple(y, x - a / b * y), g; 13 | } 14 | long long getSolution(long long a, long long b, long long &x, long long &y) { 15 | long long g = exgcd(abs(a), abs(b), x, y); 16 | if (a < 0) x = -x; 17 | if (b < 0) y = -y; 18 | return g; 19 | } 20 | 21 | struct Ans { 22 | long long x, y; 23 | inline bool operator<(const Ans &oth) const { 24 | return abs(x) + abs(y) < abs(oth.x) + abs(oth.y) || (abs(x) + abs(y) == abs(oth.x) + abs(oth.y) && x <= y); 25 | } 26 | }; 27 | 28 | int main() { 29 | ios::sync_with_stdio(false); 30 | long long x, y; 31 | while (cin >> x >> y) { 32 | long long a, b, g = getSolution(x, y, a, b); 33 | cout << a << ' ' << b << ' ' << g << endl; 34 | } 35 | return 0; 36 | } -------------------------------------------------------------------------------- /AtCoder/agc061_a.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file agc061_a.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2023-02-17 5 | * 6 | * @copyright Copyright (c) 2023 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | int64_t solve(int64_t n, int64_t k) { 20 | if (n & 1) { 21 | int64_t p = (k ? (solve(n - 1, k - 1) + 1) : 0); 22 | return p == n - 1 ? p : solve(n - 1, p); 23 | } 24 | return k ^ (((n - 1) & k) == k); 25 | } 26 | 27 | void solve(void) { 28 | int64_t n, k; 29 | cin >> n >> k; 30 | cout << solve(n, k - 1) + 1 << endl; 31 | return; 32 | } 33 | 34 | bool mem2; 35 | 36 | int main() { 37 | ios::sync_with_stdio(false), cin.tie(nullptr); 38 | #ifdef LOCAL 39 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 40 | #endif 41 | 42 | int _ = 1; 43 | cin >> _; 44 | while (_--) solve(); 45 | 46 | #ifdef LOCAL 47 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 48 | #endif 49 | return 0; 50 | } -------------------------------------------------------------------------------- /Codeforces/1718A1.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 1718A1.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2022-09-08 5 | * 6 | * @copyright Copyright (c) 2022 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | #define maxn 100005 20 | 21 | set S; 22 | 23 | void solve(void) { 24 | int n; 25 | cin >> n, S.insert(0); 26 | int ans = n; 27 | for (int i = 1, s = 0, a; i <= n; i++) { 28 | cin >> a, s ^= a; 29 | if (S.count(s)) ans--, S.clear(); 30 | S.insert(s); 31 | } 32 | cout << ans << endl; 33 | S.clear(); 34 | return; 35 | } 36 | 37 | bool mem2; 38 | 39 | int main() { 40 | ios::sync_with_stdio(false), cin.tie(nullptr); 41 | #ifdef LOCAL 42 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 43 | #endif 44 | 45 | int _ = 1; 46 | cin >> _; 47 | while (_--) solve(); 48 | 49 | #ifdef LOCAL 50 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 51 | #endif 52 | return 0; 53 | } -------------------------------------------------------------------------------- /Codeforces/1718A2.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 1718A2.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2022-09-08 5 | * 6 | * @copyright Copyright (c) 2022 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | #define maxn 100005 20 | 21 | set S; 22 | 23 | void solve(void) { 24 | int n; 25 | cin >> n, S.insert(0); 26 | int ans = n; 27 | for (int i = 1, s = 0, a; i <= n; i++) { 28 | cin >> a, s ^= a; 29 | if (S.count(s)) ans--, S.clear(); 30 | S.insert(s); 31 | } 32 | cout << ans << endl; 33 | S.clear(); 34 | return; 35 | } 36 | 37 | bool mem2; 38 | 39 | int main() { 40 | ios::sync_with_stdio(false), cin.tie(nullptr); 41 | #ifdef LOCAL 42 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 43 | #endif 44 | 45 | int _ = 1; 46 | cin >> _; 47 | while (_--) solve(); 48 | 49 | #ifdef LOCAL 50 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 51 | #endif 52 | return 0; 53 | } -------------------------------------------------------------------------------- /LibreOJ/6875.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 6875.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2023-03-05 5 | * 6 | * @copyright Copyright (c) 2023 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | #define maxn 100005 20 | 21 | int a[maxn]; 22 | int64_t pre[maxn]; 23 | 24 | void solve(void) { 25 | int n; 26 | cin >> n; 27 | for (int i = 1; i <= n; i++) cin >> a[i]; 28 | int64_t ans = 0; 29 | for (int i = n, p = 0; i; i--) { 30 | while (p < a[i]) p++, pre[p] = pre[p - 1] + i; 31 | ans += pre[a[i]]; 32 | } 33 | cout << ans << endl; 34 | return; 35 | } 36 | 37 | bool mem2; 38 | 39 | int main() { 40 | ios::sync_with_stdio(false), cin.tie(nullptr); 41 | #ifdef LOCAL 42 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 43 | #endif 44 | 45 | int _ = 1; 46 | while (_--) solve(); 47 | 48 | #ifdef LOCAL 49 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 50 | #endif 51 | return 0; 52 | } -------------------------------------------------------------------------------- /Misc/Tsinghua University Bootcamp 2025/Tsinghua Bootcamp 2025, Day 5/L.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file L.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-08-09 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define endl '\n' 14 | #define maxn 400005 15 | 16 | int a[maxn], b[maxn]; 17 | int64_t f[maxn]; 18 | 19 | int main() { 20 | ios::sync_with_stdio(0), cin.tie(0); 21 | 22 | int n; 23 | cin >> n; 24 | 25 | for (int i = 1; i <= n; i++) cin >> a[i]; 26 | for (int i = 1; i <= n; i++) cin >> b[i], b[i] = (b[i] ? ~0 : 0); 27 | 28 | memset(f, 0xc0, sizeof f); 29 | 30 | f[0] = 0; 31 | for (int i = 1; i <= n; i++) 32 | for (int v = a[i], j = min(i - 1., max(10000., 0.135 * (i - 1))), ed = max(0., min(i - 10000., 0.09 * (i - 1))); 33 | j >= ed; j--) 34 | f[j + 1] = max(f[j + 1], f[j]), f[j] += b[i - j] & v; 35 | 36 | int pos = 0; 37 | for (int i = 0; i <= n; i++) 38 | if (f[i] > f[pos]) pos = i; 39 | 40 | cout << f[pos] << endl; 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /QOJ/9521.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 9521.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-10-26 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define endl '\n' 14 | 15 | char c[15]; 16 | int w[15], d[15]; 17 | 18 | void solve(void) { 19 | int n; 20 | cin >> n; 21 | for (int i = 1; i <= n; i++) { 22 | cin >> c[i] >> d[i]; 23 | if (c[i] == 'N') 24 | w[i] = 0; 25 | else if (c[i] == 'E') 26 | w[i] = 1; 27 | else if (c[i] == 'S') 28 | w[i] = 2; 29 | else 30 | w[i] = 3; 31 | } 32 | cout << 2 * n - 1 << ' ' << c[1] << endl; 33 | cout << "Z " << d[1] << endl; 34 | for (int i = 2; i <= n; i++) { 35 | cout << "LR"[w[i] == (w[i - 1] + 1) % 4] << endl; 36 | cout << "Z " << d[i] << endl; 37 | } 38 | return; 39 | } 40 | 41 | int main() { 42 | ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); 43 | 44 | int _ = 1; 45 | cin >> _; 46 | while (_--) solve(); 47 | 48 | return 0; 49 | } -------------------------------------------------------------------------------- /AtCoder/arc120_b.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Macesuted (i@macesuted.moe) 3 | * @copyright Copyright (c) 2021 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | 9 | #define maxn 505 10 | #define mod 998244353 11 | 12 | string a[maxn]; 13 | 14 | int main() { 15 | ios::sync_with_stdio(false); 16 | int n, m; 17 | cin >> n >> m; 18 | for (register int i = 1; i <= n; i++) cin >> a[i], a[i] = ' ' + a[i]; 19 | long long answer = 1; 20 | for (register int t = 2; t <= n + m; t++) { 21 | bool visB = false, visR = false, visW = false; 22 | for (register int i = 1; i < t; i++) { 23 | register int j = t - i; 24 | if (!(1 <= i && i <= n && 1 <= j && j <= m)) continue; 25 | if (a[i][j] == 'B') visB = true; 26 | if (a[i][j] == 'R') visR = true; 27 | if (a[i][j] == '.') visW = true; 28 | } 29 | if (visB && visR) { 30 | cout << 0 << endl; 31 | return 0; 32 | } 33 | if (!visB && !visR) answer = answer * 2 % mod; 34 | } 35 | cout << answer << endl; 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /Codeforces Gym/104772G.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file G.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-07-02 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | #define maxn 555 20 | 21 | int f[maxn][maxn]; 22 | 23 | void solve(void) { 24 | int n, p, mod; 25 | cin >> n >> p >> mod; 26 | f[0][p] = 1; 27 | for (int i = 1; i <= n - p; i++) 28 | for (int j = 0; j + i <= n - p; j++) 29 | for (int k = 0; k < 512; k++) f[j + i][k ^ i] = (f[j + i][k ^ i] + f[j][k]) % mod; 30 | cout << f[n - p][0] << endl; 31 | return; 32 | } 33 | 34 | bool mem2; 35 | 36 | int main() { 37 | ios::sync_with_stdio(false), cin.tie(nullptr); 38 | #ifdef LOCAL 39 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 40 | #endif 41 | 42 | int _ = 1; 43 | while (_--) solve(); 44 | 45 | #ifdef LOCAL 46 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 47 | #endif 48 | return 0; 49 | } -------------------------------------------------------------------------------- /Codeforces Gym/102465D.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 102465D.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-07-23 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define maxn 100005 14 | 15 | vector a[maxn]; 16 | int xu[maxn], xd[maxn]; 17 | 18 | int main() { 19 | ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); 20 | 21 | int n, m, q, su = 0, sd = 0; 22 | cin >> n >> m >> q; 23 | int64_t cur = n - 1, ans = INT64_MAX; 24 | for (int i = 1, x, y; i <= q; i++) cin >> x >> y, a[y].push_back(x); 25 | 26 | for (int y = m - 1; ~y; y--) 27 | for (auto x : a[y]) { 28 | if (!xu[x]) cur += y * 2, su++; 29 | xu[x]++; 30 | } 31 | 32 | for (int y = 0; y < m; y++) { 33 | ans = min(ans, cur); 34 | for (auto x : a[y]) { 35 | xu[x]--; 36 | if (!xu[x]) su--; 37 | if (!xd[x]) sd++; 38 | xd[x]++; 39 | } 40 | cur += 2 * (sd - su); 41 | } 42 | 43 | cout << ans << endl; 44 | 45 | return 0; 46 | } -------------------------------------------------------------------------------- /Codeforces/1579E1.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Macesuted (i@macesuted.moe) 3 | * @copyright Copyright (c) 2021 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | 9 | #define int long long 10 | 11 | #define maxn 200005 12 | 13 | typedef pair pii; 14 | 15 | int a[maxn], p[maxn]; 16 | 17 | deque front, back; 18 | 19 | void work(void) { 20 | int n; 21 | cin >> n; 22 | for (register int i = 1; i <= n; i++) cin >> a[i], p[a[i]] = i; 23 | front.clear(), back.clear(); 24 | int tail = n; 25 | for (register int i = 1; i <= n; i++) { 26 | int t = p[i]; 27 | if (t > tail) continue; 28 | for (register int j = tail; j > t; j--) back.push_front(a[j]); 29 | front.push_back(i); 30 | tail = t - 1; 31 | } 32 | for (auto i : front) cout << i << ' '; 33 | for (auto i : back) cout << i << ' '; 34 | cout << endl; 35 | return; 36 | } 37 | 38 | signed main() { 39 | ios::sync_with_stdio(false); 40 | cout << setiosflags(ios::fixed) << setprecision(11); 41 | int _ = 1; 42 | cin >> _; 43 | while (_--) work(); 44 | return 0; 45 | } -------------------------------------------------------------------------------- /Codeforces/2042B.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 2042B.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-12-02 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | void solve(void) { 20 | int n; 21 | cin >> n; 22 | map cnt; 23 | for (int i = 1, v; i <= n; i++) cin >> v, cnt[v]++; 24 | 25 | int cnt1 = 0, ans = 0; 26 | for (auto [v, c] : cnt) 27 | if (c == 1) 28 | cnt1++; 29 | else 30 | ans++; 31 | 32 | cout << ans + (cnt1 + 1) / 2 * 2 << endl; 33 | 34 | return; 35 | } 36 | 37 | bool mem2; 38 | 39 | int main() { 40 | ios::sync_with_stdio(false), cin.tie(nullptr); 41 | #ifdef LOCAL 42 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 43 | #endif 44 | 45 | int _ = 1; 46 | cin >> _; 47 | while (_--) solve(); 48 | 49 | #ifdef LOCAL 50 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 51 | #endif 52 | return 0; 53 | } -------------------------------------------------------------------------------- /Nowcoder/108298L.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 108298L.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-07-15 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define endl '\n' 14 | 15 | #define maxn 200005 16 | 17 | int64_t a[maxn]; 18 | 19 | void solve(void) { 20 | int n, q; 21 | cin >> n >> q; 22 | 23 | int lim = n / 2, aft = n; 24 | int64_t pos = 0; 25 | 26 | map rec; 27 | for (int i = 1; i <= n; i++) cin >> a[i], rec[a[i]]++; 28 | 29 | while (q--) { 30 | int p, v; 31 | cin >> p >> v; 32 | if (a[p] <= pos && a[p] + v > pos) aft++; 33 | rec[a[p]]--; 34 | a[p] += v; 35 | rec[a[p]]++; 36 | while (aft - rec.upper_bound(pos)->second >= lim) pos = rec.upper_bound(pos)->first, aft -= rec[pos]; 37 | cout << n - aft << endl; 38 | } 39 | 40 | return; 41 | } 42 | 43 | int main() { 44 | ios::sync_with_stdio(false), cin.tie(nullptr); 45 | 46 | int _ = 1; 47 | cin >> _; 48 | while (_--) solve(); 49 | 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /Codeforces Gym/101808I.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 101808I.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-07-21 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | #define maxn 105 20 | 21 | int a[maxn]; 22 | 23 | void solve(void) { 24 | int n, mv = INT_MAX, sum = 0; 25 | cin >> n; 26 | for (int i = 1; i <= n; i++) cin >> a[i], sum += a[i], mv = min(mv, a[i]); 27 | if (n & 1) return cout << ((sum & 1) ? "Yalalov" : "Shin") << endl, void(); 28 | cout << ((sum & 1) || (mv & 1) ? "Yalalov" : "Shin") << endl; 29 | return; 30 | } 31 | 32 | bool mem2; 33 | 34 | int main() { 35 | ios::sync_with_stdio(false), cin.tie(nullptr); 36 | #ifdef LOCAL 37 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 38 | #endif 39 | 40 | int _ = 1; 41 | cin >> _; 42 | while (_--) solve(); 43 | 44 | #ifdef LOCAL 45 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 46 | #endif 47 | return 0; 48 | } -------------------------------------------------------------------------------- /Codeforces/2104B.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 2104B.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-04-28 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | #define maxn 200005 20 | 21 | int a[maxn], mv[maxn]; 22 | 23 | void solve(void) { 24 | int n; 25 | cin >> n; 26 | for (int i = 1; i <= n; i++) cin >> a[i], mv[i] = max(mv[i - 1], a[i]); 27 | int64_t sum = 0; 28 | for (int i = n; i; i--) { 29 | sum += a[i]; 30 | cout << sum + max(0, mv[i - 1] - a[i]) << ' '; 31 | } 32 | cout << endl; 33 | return; 34 | } 35 | 36 | bool mem2; 37 | 38 | int main() { 39 | ios::sync_with_stdio(false), cin.tie(nullptr); 40 | #ifdef LOCAL 41 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 42 | #endif 43 | 44 | int _ = 1; 45 | cin >> _; 46 | while (_--) solve(); 47 | 48 | #ifdef LOCAL 49 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 50 | #endif 51 | return 0; 52 | } -------------------------------------------------------------------------------- /HDOJ/7451.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 7451.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2024-07-22 5 | * 6 | * @copyright Copyright (c) 2024 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define endl '\n' 14 | 15 | int main() { 16 | ios::sync_with_stdio(false), cin.tie(nullptr); 17 | 18 | int _; 19 | cin >> _; 20 | while (_--) { 21 | string s; 22 | cin >> s; 23 | int n = s.size(); 24 | s = ' ' + s; 25 | 26 | vector pos; 27 | 28 | for (int i = 1; i <= n; i++) 29 | if (s[i] == '/') pos.push_back(i); 30 | for (int i = 1; i < pos[0] - 1; i++) cout << s[i]; 31 | cout << endl; 32 | for (int i = 1; i + 1 < (int)pos.size(); i++) { 33 | string t; 34 | for (int j = pos[i] + 1; j < pos[i + 1]; j++) t.push_back(s[j]); 35 | int cnt = 0; 36 | for (int j = 1; j + 1 < (int)t.size(); j++) 37 | if (t[j] == '=') cnt++; 38 | if (i != 1 && cnt != 1) continue; 39 | cout << t << endl; 40 | } 41 | } 42 | return 0; 43 | } -------------------------------------------------------------------------------- /Codeforces/1623A.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 1623A.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2022-01-29 5 | * 6 | * @copyright Copyright (c) 2022 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define MP make_pair 14 | #define MT make_tuple 15 | 16 | bool mem1; 17 | 18 | void solve(void) { 19 | int n, m, rb, cb, rd, cd; 20 | cin >> n >> m >> rb >> cb >> rd >> cd; 21 | int ans = 0x3f3f3f3f; 22 | if (rb <= rd) 23 | ans = min(ans, rd - rb); 24 | else 25 | ans = min(ans, n + (n - rd) - rb); 26 | if (cb <= cd) 27 | ans = min(ans, cd - cb); 28 | else 29 | ans = min(ans, m + (m - cd) - cb); 30 | cout << ans << endl; 31 | return; 32 | } 33 | 34 | bool mem2; 35 | 36 | int main() { 37 | ios::sync_with_stdio(false); 38 | #ifdef LOCAL 39 | cerr << "Memory: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 40 | #endif 41 | 42 | int _ = 1; 43 | cin >> _; 44 | while (_--) solve(); 45 | 46 | #ifdef LOCAL 47 | cerr << "Time: " << clock() * 1000. / CLOCKS_PER_SEC << "ms" << endl; 48 | #endif 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /Codeforces Gym/105481J.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * @file 105481J.cpp 3 | * @author Macesuted (i@macesuted.moe) 4 | * @date 2025-01-06 5 | * 6 | * @copyright Copyright (c) 2025 7 | * 8 | */ 9 | 10 | #include 11 | using namespace std; 12 | 13 | #ifndef LOCAL 14 | #define endl '\n' 15 | #endif 16 | 17 | bool mem1; 18 | 19 | #define maxn 1005 20 | 21 | int x[maxn], y[maxn]; 22 | 23 | void solve(void) { 24 | int n, A, B, C, D; 25 | cin >> n >> A >> B >> C; 26 | for (int i = 1; i <= n; i++) cin >> x[i] >> y[i]; 27 | cin >> D; 28 | int ans = 0; 29 | for (int i = 1; i <= n; i++) 30 | if (x[i] + y[i] < C) x[i] += D, x[i] = min(x[i], A), ans += (x[i] + y[i] >= C); 31 | cout << ans << endl; 32 | return; 33 | } 34 | 35 | bool mem2; 36 | 37 | int main() { 38 | ios::sync_with_stdio(false), cin.tie(nullptr); 39 | #ifdef LOCAL 40 | cerr << "Memory Cost: " << abs(&mem1 - &mem2) / 1024. / 1024. << "MB" << endl; 41 | #endif 42 | 43 | int _ = 1; 44 | while (_--) solve(); 45 | 46 | #ifdef LOCAL 47 | cerr << "Time Cost: " << clock() * 1000. / CLOCKS_PER_SEC << "MS" << endl; 48 | #endif 49 | return 0; 50 | } --------------------------------------------------------------------------------