Skip to content

Instantly share code, notes, and snippets.

@GoBigorGoHome
GoBigorGoHome / perl-rename.md
Last active May 10, 2024 01:04
使用 perl-rename 批量重命名文件

例一

policija.in.1  ->  policija1.in
policija.out.1 ->  policija1.out
perl-rename 's/policija\.($\\w+)\.($\\d+)/policija$2.$1/' *

$a$,$b$。

$a$$b$

@GoBigorGoHome
GoBigorGoHome / use_asan_on_windows.md
Last active July 5, 2024 12:01
Use Asan on Windows with the MSYS2 clang64 toolchain
  1. Install the MSYS2 distribution.

  2. Activate the clang64 environment. For newer versions of MSYS2, it is activated by default. If you have installed an older version, edit MSYS2_ROOT/etc/pacman.conf to activate it.

  3. In the MSYS2 terminal, run pacman -S mingw-w64-clang-x86_64-clang.

  4. Complie AND link your program with -fsanitize=address flag. See https://clang.llvm.org/docs/AddressSanitizer.html#id3 for more information. Note that you have to use the -fsanitize=address flag both when compiling and linking; for example, in CMakeLists.txt, you have to use both target_compile_options(<YOUR_TARGET> PRIVATE -fsanitize=address) and target_link_options(<YOUR_TARGET> PRIVATE -fsanitize=address).

// This file presents some implementations of ndarray function/class.
// Function
// #1
template<typename T> T get_vector() {
return T();
}
template<typename T, int dimension, int... Dimensions> auto get_vector() {

Linux 命令行编辑快捷键

初学者在Linux命令窗口(终端)敲命令时,肯定觉得通过输入一串一串的字符的方式来控制计算是效率很低。 但是Linux命令解释器(Shell)是有很多快捷键的,熟练掌握可以极大的提高操作效率。 下面列出最常用的快捷键,这还不是完全版。

  • 命令行快捷键:
    • 常用:
      • Ctrl L :清屏
  • Ctrl M :等效于回车
using Point = pair<int,int>;
ll cross(const Point& a, const Point& b) {
return 1ll * a.first * b.second - 1ll * a.second * b.first;
}
// 逆时针
// 参考 mnbvmar 的写法:https://codeforces.com/contest/1284/submission/68178688
bool cmp_polar(const Point& a, const Point& b) {
bool aorig = a.second > 0;
bool borig = b.second > 0;
if (aorig != borig) {
class SegSet {
set<pii> s;
public:
// 插入闭区间[l,r]
void insert(int l, int r) {
auto iter = s.upper_bound({r, r});
while (iter != s.begin()) {
// --a,++a 运算符的优先级低于 .,-> 运算符。
if ((--iter)->second < l) {
break;
@GoBigorGoHome
GoBigorGoHome / 【模板】单调队列.cpp
Created January 3, 2020 12:07
简陋的单调队列
template<typename T,typename Compare>
class MonoQueue {
private:
deque<pair<T,int>> que;
Compare cmp;
public:
void push(const T& val, int i) {
while (!que.empty() && !cmp(que.back().first, val)) {
que.pop_back();
}
// 要求T具有<运算符
template <typename T>
void sort_suffix(const T *s, int n, vector<int>& suf, vector<int>& h) {
assert(SZ(suf) >= n && SZ(h) >= n);
vector<int> rank(n);
iota(all(suf), 0);
sort(all(suf), [s](int x, int y) { return s[x] < s[y]; });
rank[suf[0]] = 0;
for (int i = 1; i < n; ++i) {
rank[suf[i]] = rank[suf[i - 1]] + (s[suf[i - 1]] < s[suf[i]]);
@GoBigorGoHome
GoBigorGoHome / ctz_clz.cpp
Created December 11, 2019 03:07 — forked from pps83/ctz_clz.cpp
__builtin_ctz (ctzl, ctzll) and __builtin_clz (clzl, clzll) for Visual Studio
#ifdef _MSC_VER
#include <intrin.h>
static inline int __builtin_ctz(uint32_t x) {
unsigned long ret;
_BitScanForward(&ret, x);
return (int)ret;
}
static inline int __builtin_ctzll(unsigned long long x) {