版本比较
一个 OIer 的编译命令 & 配置文件
正文
增加 18 行删除 19 行
5 行未改动67891010111213131415161726 行未改动44454647484849505152535456555657585960616264656364656669706768697071727374753 行未改动798081828483848586876 行未改动9495969799100101102989910410010110210310410510610710810911059 行未改动17017117217317517617717817417518017617717817918018118218318418518639 行未改动5 行未改动
```bash line-numbers
cpl() { g++ "./$1.cpp" -o "./$1" -O2 -std=gnu++14 -static -Wall -Wextra -Wshadow -Wno-unused-result -Wno-sign-compare -Wl,-z,stack-size=1000000000 -fsanitize=undefined,bounds -DLOCAL && echo -e "\e[32mCompiled ./$1.cpp\e[0m" g++ "./$1.cpp" -o "./$1" -O2 -std=gnu++14 -static -Wall -Wextra -Wshadow -Wno-unused-result -Wno-sign-compare -Wl,-z,stack-size=1000000000 -fsanitize=undefined,bounds -DLOCAL && echo "Compiled ./$1.cpp"}run() { cpl "$1" && echo -e "\e[36mRunning ./$1\n---------------begin---------------\e[0m" && local TIMEFORMAT=$'\e[33m\n----------------end----------------\nTime: %3Rs\e[0m' && time "./$1" cpl "$1" && echo -e "Running ./$1\n--------------------------------" && time "./$1"}```
2. 可在控制台内运行如下命令以重新加载 `~/.bashrc` 中的命令:26 行未改动 if (-not (Test-Path $cppFile)) { Write-Error "Error: $cppFile not found"; return } Write-Host "Compiling $cppFile" -ForegroundColor Green $swCompile = [System.Diagnostics.Stopwatch]::StartNew() g++ "$cppFile" -o "$exeFile" -O2 -std=gnu++14 -static -Wall -Wextra -Wshadow -Wno-unused-result -Wno-sign-compare "-Wl,--stack=1000000000" -DLOCAL # 神秘 Windows 没法加 "-fsanitize=undefined,bounds" $swCompile.Stop() if ($LASTEXITCODE -eq 0) { Write-Host "Compile Time: $($swCompile.Elapsed.TotalSeconds.ToString('0.000')) s" -ForegroundColor Yellow Write-Host "Compile Time: $($swCompile.Elapsed.TotalSeconds.ToString('0.000')) s" }}
function run { param([string]$name) cpl $name if ($LASTEXITCODE -eq 0 -and (Test-Path ".\$name.exe")) { Write-Host "Running .\$name.exe" -ForegroundColor Green Write-Host "---------------begin---------------" -ForegroundColor Cyan Write-Host "--------------------------------" $swRun = [System.Diagnostics.Stopwatch]::StartNew() & ".\$name.exe" $swRun.Stop() Write-Host "`n----------------end----------------" -ForegroundColor Yellow Write-Host "Run Time: $($swRun.Elapsed.TotalSeconds.ToString('0.000')) s" -ForegroundColor Yellow Write-Host "`n--------------------------------" Write-Host "Run Time: $($swRun.Elapsed.TotalSeconds.ToString('0.000')) s" }}
```
3. 可在(VSCode 中的)Powershell 内运行如下命令以重新加载 PowerShell 配置文件:
3 行未改动
4. 在部分特殊情况下,可以使用丐版命令来编译运行(将 `$name` 的值替换为程序实际路径并去掉 `.cpp` 即可):
```bash line-numbers$name = ".\"; Write-Host "Compiling $name.cpp" -ForegroundColor Green; $swCompile = [System.Diagnostics.Stopwatch]::StartNew(); g++ "$name.cpp" -o "$name.exe" -O2 -std=gnu++14 -static -Wall -Wextra -Wshadow -Wno-unused-result "-Wl,--stack=1000000000" -DLOCAL; $swCompile.Stop(); Write-Host "Compile Time: $($swCompile.Elapsed.TotalSeconds.ToString('0.000')) s" -ForegroundColor Yellow; Write-Host "Running $name.exe" -ForegroundColor Green; Write-Host "---------------begin---------------" -ForegroundColor Cyan; $swRun = [System.Diagnostics.Stopwatch]::StartNew(); & "$name.exe"; $swRun.Stop(); Write-Host "`n----------------end----------------" -ForegroundColor Yellow; Write-Host "Run Time: $($swRun.Elapsed.TotalSeconds.ToString('0.000')) s" -ForegroundColor Yellow$name = ".\"; $swCompile = [System.Diagnostics.Stopwatch]::StartNew(); g++ "$name.cpp" -o "$name.exe" -O2 -std=gnu++14 -static -Wall -Wextra -Wshadow -Wno-unused-result -Wno-sign-compare "-Wl,--stack=1000000000" -DLOCAL; $swCompile.Stop(); if ($LASTEXITCODE -eq 0) { echo "Compile Time: $($swCompile.Elapsed.TotalSeconds.ToString('0.000')) s" ; echo --------------------------------; $swRun = [System.Diagnostics.Stopwatch]::StartNew(); & "$name.exe"; $swRun.Stop(); echo `n--------------------------------; echo "Run Time: $($swRun.Elapsed.TotalSeconds.ToString('0.000')) s" }```
## 配置文件
6 行未改动 "body": [ "#include <bits/stdc++.h>", "using namespace std;", "#define int long long", "#define eb emplace_back", "#define fi first", "#define se second", "#define all(a) (a).begin(), (a).end()", "#define i128 __int128", "using ull = unsigned long long;", "using i128 = __int128;", "using ld = long double;", "using pii = pair<int, int>;", "using p3i = pair<int, pii>;", "#define eb emplace_back", "#define fi first", "#define se second", "#define all(a) (a).begin(), (a).end()", "const int inf = 0x3f3f3f3f, Inf = 0x3f3f3f3f3f3f3f3f;", "template<typename T, typename U> void chkmin(T &x, U y) { x > y && (x = y); }", "template<typename T, typename U> void chkmax(T &x, U y) { x < y && (x = y); }", "",59 行未改动```cpp line-numbers#include <bits/stdc++.h>using namespace std;#define int long long#define eb emplace_back#define fi first#define se second#define all(a) (a).begin(), (a).end()#define i128 __int128using ull = unsigned long long;using i128 = __int128;using ld = long double;using pii = pair<int, int>;using p3i = pair<int, pii>;#define eb emplace_back#define fi first#define se second#define all(a) (a).begin(), (a).end()const int inf = 0x3f3f3f3f, Inf = 0x3f3f3f3f3f3f3f3f;template<typename T, typename U> void chkmin(T &x, U y) { x > y && (x = y); }template<typename T, typename U> void chkmax(T &x, U y) { x < y && (x = y); }
39 行未改动