diff --git a/nvim/lua/snippets/init.lua b/nvim/lua/snippets/init.lua index f719aef..b7eeee1 100644 --- a/nvim/lua/snippets/init.lua +++ b/nvim/lua/snippets/init.lua @@ -417,3 +417,16 @@ ls.add_snippets(nil, { }) } }) + +local segtree_persistent = require('snippets.segtree-persistent') +ls.add_snippets(nil, { + cpp = { + snip({ + trig = 'segtree_persistent', + namr = 'segtree_persistent', + dscr = 'Persistent Segment Tree', + },{ + text(lines(segtree_persistent)) + }) + } +}) diff --git a/nvim/lua/snippets/segtree-persistent.lua b/nvim/lua/snippets/segtree-persistent.lua new file mode 100644 index 0000000..13f1844 --- /dev/null +++ b/nvim/lua/snippets/segtree-persistent.lua @@ -0,0 +1,88 @@ +return [=[ +template struct segtree { + using info_type = Addable_Info; + using size_type = size_t; + struct Node { + size_type lson, rson; + info_type info; + }; + vector d; + vector version_root; + size_type _max; + void _copy(size_type& virt) { + int o = virt; + virt = d.size(); + d.emplace_back(); + if (o != 0) d.back() = d[o]; + } + explicit segtree(size_type&& _max) : d(1), _max(_max - 1) { + version_root.emplace_back(0); + } + segtree(const vector& init) : d(1), _max(init.size() - 1) { + version_root.emplace_back(0); + auto dfs = [&] (auto dfs, size_type s, size_type t, size_type p) -> void { + if (s == t) { + d[p].info = init[s]; + return; + } + int m = s + t >> 1; + _copy(d[p].lson), _copy(d[p].rson); + dfs(dfs, s, m, d[p].lson); + dfs(dfs, m + 1, t, d[p].rson); + }; + dfs(dfs, 0, _max, version_root[0]); + } + void _set(size_type s, size_type t, size_type p, size_type x, const info_type& c) { + if (s == t) { + d[p].info = c; + return; + } + size_type m = s + (t - s >> 1); + if (x <= m) { + _copy(d[p].lson); + _set(s, m, d[p].lson, x, c); + } else { + _copy(d[p].rson); + _set(m + 1, t, d[p].rson, x, c); + } + d[p].info = d[d[p].lson].info + d[d[p].rson].info; + } + size_type _clone(size_type version) { + d.emplace_back(d[version_root[version]]); + version_root.emplace_back(d.size() - 1); + return version_root.size() - 1; + } + size_type set(size_type version, size_type loc, const info_type& c) { + size_type new_version = _clone(version); + _set(0, _max, version_root[new_version], loc, c); + return new_version; + } + info_type _range_query(size_type s, size_type t, size_type p, size_type l, size_type r) { + if (l <= s and t <= r) { + return d[p].info; + } + size_type m = s + (t - s >> 1); + info_type ret = {}; + if (l <= m and d[p].lson != 0) { + ret = ret + _range_query(s, m, d[p].lson, l, r); + } + if (r > m and d[p].rson != 0) { + ret = ret + _range_query(m + 1, t, d[p].rson, l, r); + } + return ret; + } + info_type range_query(size_type version, size_type l, size_type r) { + return _range_query(0, _max, version_root[version], l, r); + } + info_type query(size_type version, size_type loc) { + return range_query(version, loc, loc); + } +}; +struct Info { + int val = INF; +}; +Info operator+(const Info& lhs, const Info& rhs) { + return { min(lhs.val, rhs.val) }; +} + +]=] diff --git a/vscode/keybindings.json b/vscode/keybindings.json new file mode 100644 index 0000000..652376e --- /dev/null +++ b/vscode/keybindings.json @@ -0,0 +1,15 @@ +// Place your key bindings in this file to override the defaults +[ + { + "key": "alt+.", + "command": "workbench.action.nextEditor", + }, + { + "key": "alt+,", + "command": "workbench.action.previousEditor", + }, + { + "key": "alt+c", + "command": "workbench.action.closeActiveEditor", + } +] \ No newline at end of file diff --git a/vscode/settings.json b/vscode/settings.json new file mode 100644 index 0000000..006a8a4 --- /dev/null +++ b/vscode/settings.json @@ -0,0 +1,90 @@ +{ + "editor.cursorBlinking": "solid", + "remoteHub.commitDirectlyWarning": "off", + "workbench.colorTheme": "Melange Redux: Dark", + "files.autoSave": "afterDelay", + "terminal.integrated.profiles.windows": { + "PowerShell": { + "source": "PowerShell", + "icon": "terminal-powershell" + }, + "Command Prompt": { + "path": [ + "${env:windir}\\Sysnative\\cmd.exe", + "${env:windir}\\System32\\cmd.exe" + ], + "args": [], + "icon": "terminal-cmd" + }, + "Git Bash": { + "source": "Git Bash" + }, + "Ubuntu-22.04 (WSL)": { + "path": "C:\\WINDOWS\\System32\\wsl.exe", + "args": [ + "-d", + "Ubuntu-22.04" + ] + } + }, + "terminal.integrated.defaultProfile.windows": "Command Prompt", + "git.enableSmartCommit": true, + "git.confirmSync": false, + "git.autofetch": true, + // "http.proxy": "socks5://127.0.0.1:7890", + "editor.accessibilitySupport": "off", + "editor.autoClosingOvertype": "always", + "editor.fontFamily": "'BerkeleyMono Nerd Font', 'FiraCode Nerd Font', Consolas, 'Courier New', monospace", + "editor.wordWrap": "on", + "editor.lineNumbers": "relative", + "terminal.integrated.fontLigatures": true, + "editor.fontLigatures": true, + "vim.normalModeKeyBindings": [ + { + "before": [ "", "o" ], + "commands": [ "workbench.action.files.openFile" ] + }, + { + "before": [ "", "s" ], + "commands": [ "workbench.action.showAllSymbols" ] + }, + { + "before": [ "", "g" ], + "commands": [ "livegrep.search" ] + }, + { + "before": [ "", "c", "c" ], + "commands": [ "codesnap.start" ] + }, + { + "before": [ "", "d" ], + "commands": [ "workbench.panel.markers.view.focus" ] + }, + { + "before": [ "" ], + "after": [ "g", "g", "V", "G" ] + }, + { + "before": [ "", "b" ], + "commands": [ + { + "command": "workbench.action.tasks.runTask", + "args": "test", + } + ], + }, + + ], + "vim.insertModeKeyBindings": [ + { + "before": [ "j", "k" ], + "after": [ "" ] + }, + ], + "editor.minimap.enabled": false, + "vim.useSystemClipboard": true, + "vim.leader": "", + "terminal.integrated.defaultProfile.linux": "zsh", + "vim.highlightedyank.enable": true, + "vim.smartRelativeLine": true +} \ No newline at end of file