跳到正文

个人记录

VSCode 模板

xvl_约 23 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月16日
篇幅
约 23 分钟
获赞
1

版本

  1. v2当前
  2. v1
Matrix
C++
{
	// Place your xvl_ 工作区 snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
	// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
	// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is
	// used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
	// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.
	// Placeholders with the same ids are connected.
	// Example:
	// "Print to console": {
	// 	"scope": "javascript,typescript",
	// 	"prefix": "log",
	// 	"body": [
	// 		"console.log('$1');",
	// 		"$2"
	// 	],
	// 	"description": "Log output to console"
	// }
	"Matrix": {
	"prefix": "Matrix",
	"body": [
		"template <typename T> struct Matrix {",
		"    vector <vector <T>> A;",
		"    int r, c;",
		"    Matrix(int r, int c) : r(r), c(c) { A = vector <vector <T>> (r + 1, vector <T> (c + 1)); }",
		"    friend Matrix operator * (const Matrix&, const Matrix&);",
		"    friend Matrix operator + (const Matrix&, const Matrix&);",
		"    friend Matrix operator - (const Matrix&, const Matrix&);",
		"    friend Matrix operator *= (const Matrix&, const Matrix&);",
		"    friend Matrix operator += (const Matrix&, const Matrix&);",
		"    friend Matrix operator -= (const Matrix&, const Matrix&);",
		"    vector <T>& operator [] (int n) { return A[n]; }",
		"    const vector <T>& operator [] (int n) const { return A[n]; }",
		"    Matrix operator * (const Matrix& y) {",
		"        Matrix x = *this;",
		"        Matrix res(x.r, y.c);",
		"        for (int i = 1; i <= x.r; i++) {",
		"            for (int j = 1; j <= y.c; j++) { ",
		"                for (int k = 1; k <= x.c; k++) res[i][j] = (res[i][j] + x[i][k] % MOD * y[k][j] % MOD) % MOD; ",
		"            } ",
		"        } ",
		"        return res;",
		"    }",
		"    Matrix operator + (const Matrix& y) {",
		"        Matrix x = *this;",
		"        Matrix res(x.r, x.c);",
		"        for (int i = 1; i <= x.r; i++) {",
		"            for (int j = 1; j <= x.c; j++) res[i][j] = (x[i][j] % MOD + y[i][j] % MOD) % MOD;",
		"        }",
		"        return res;",
		"    }",
		"    Matrix operator - (const Matrix& y) {",
		"        Matrix x = *this;",
		"        Matrix res(x.r, x.c);",
		"        for (int i = 1; i <= x.r; i++) {",
		"            for (int j = 1; j <= x.c; j++) res[i][j] = (x[i][j] % MOD - y[i][j] % MOD + MOD) % MOD;",
		"        }",
		"        return res;",
		"    }",
		"    Matrix operator *= (const Matrix& x) { *this = *this * x; return *this; }",
		"    Matrix operator += (const Matrix& x) { *this = *this + x; return *this; }",
		"    Matrix operator -= (const Matrix& x) { *this = *this - x; return *this; }",
		"    Matrix pow(ll x) const {",
		"        Matrix res(r, r), c(r, r);",
		"        for (int i = 1; i <= r; i++) { res[i][i] = 1; for (int j = 1; j <= r; j++) c[i][j] = (A[i][j] % MOD + MOD) % MOD; }",
		"        for (; x; c *= c, x >>= 1) { if (x & 1) res *= c; } ",
		"        return res;",
		"    }",
		"};"
	],
	"description": "Matrix"
	}
}
Modnum
C++
{
	// Place your xvl_ 工作区 snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
	// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
	// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is
	// used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
	// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.
	// Placeholders with the same ids are connected.
	// Example:
	// "Print to console": {
	// 	"scope": "javascript,typescript",
	// 	"prefix": "log",
	// 	"body": [
	// 		"console.log('$1');",
	// 		"$2"
	// 	],
	// 	"description": "Log output to console"
	// }
	"Modnum": {
	"prefix": "Modnum",
	"body": [
		"template <typename T> struct Modnum {",
		"    T val = 0, P = 1;",
		"    Modnum(T x = 0, T y = 1) : val(x), P(y) { val = (val % P + P) % P; }",
		"    void init(T x, T y) { val = x, P = y; val = (val % P + P) % P; }",
		"    friend Modnum operator ++ (const Modnum&);",
		"    friend Modnum operator ++ (const Modnum&, int);",
		"    friend Modnum operator -- (const Modnum&);",
		"    friend Modnum operator -- (const Modnum&, int);",
		"    friend ostream& operator << (ostream& os, const Modnum& x) { os << x.val; return os; }",
		"    friend istream& operator >> (istream& is, Modnum& x) { is >> x.val; return is; }",
		"    template <typename Type> friend Modnum operator + (const Modnum& x, const Type& y) { return {(x.val + y) % x.P, x.P}; }",
		"    template <typename Type> friend Modnum operator - (const Modnum& x, const Type& y) { return {(x.val - y) % x.P, x.P}; }",
		"    template <typename Type> friend Modnum operator * (const Modnum& x, const Type& y) { return {(x.val * y) % x.P, x.P}; }",
		"    template <typename Type> friend Modnum operator + (const Type& x, const Modnum& y) { return {(y.val + x) % y.P, y.P}; }",
		"    template <typename Type> friend Modnum operator - (const Type& x, const Modnum& y) { return {(y.val - x) % y.P, y.P}; }",
		"    template <typename Type> friend Modnum operator * (const Type& x, const Modnum& y) { return {(y.val * x) % y.P, y.P}; }",
		"    friend Modnum operator + (const Modnum& x, const Modnum& y) { ",
		"        assert(x.P == y.P); ",
		"        return {(x.val + y.val) % x.P, x.P}; ",
		"    }   ",
		"    friend Modnum operator - (const Modnum& x, const Modnum& y) {",
		"        assert(x.P == y.P);",
		"        return {(x.val - y.val + x.P) % x.P, x.P};",
		"    }",
		"    friend Modnum operator * (const Modnum& x, const Modnum& y) {",
		"        assert(x.P == y.P);",
		"        return {x.val * y.val % x.P, x.P};",
		"    }",
		"    friend Modnum operator += (Modnum& x, const Modnum& y) { x = x + y; return x; }",
		"    friend Modnum operator -= (Modnum& x, const Modnum& y) { x = x - y; return x; }",
		"    friend Modnum operator *= (Modnum& x, const Modnum& y) { x = x * y; return x; }",
		"    template <typename Type> friend Modnum operator += (Modnum& x, const Type& y) { x = x + y; return x; }",
		"    template <typename Type> friend Modnum operator -= (Modnum& x, const Type& y) { x = x - y; return x; }",
		"    template <typename Type> friend Modnum operator *= (Modnum& x, const Type& y) { x = x * y; return x; }",
		"    template <typename Type> friend Type operator += (Type& x, const Modnum& y) { x = (x + y).val; return x; }",
		"    template <typename Type> friend Type operator -= (Type& x, const Modnum& y) { x = (x - y).val; return x; }",
		"    template <typename Type> friend Type operator *= (Type& x, const Modnum& y) { x = (x * y).val; return x; }",
		"    Modnum operator ++ () { *this += 1; return *this; }",
		"    Modnum operator ++ (int) { Modnum tmp = *this; *this += 1; return tmp; }",
		"    Modnum operator -- () { *this -= 1; return *this; }",
		"    Modnum operator -- (int) { Modnum tmp = *this; *this -= 1; return tmp; }",
		"};"
	],
	"description": "Modnum"
	}
}
FastIO(不支持浮点数输出)
C++
{
	// Place your xvl_ 工作区 snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
	// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
	// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is
	// used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
	// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.
	// Placeholders with the same ids are connected.
	// Example:
	// "Print to console": {
	// 	"scope": "javascript,typescript",
	// 	"prefix": "log",
	// 	"body": [
	// 		"console.log('$1');",
	// 		"$2"
	// 	],
	// 	"description": "Log output to console"
	// }
	"FastIO": {
	"prefix": "FastIO",
	"body": [
		"namespace FastIO {",
		"    #define LOCAL",
		"    #ifndef LOCAL",
		"        #define getchar getchar_unlocked",
		"        #define putchar putchar_unlocked",
		"    #else",
		"        #define getchar _getchar_nolock",
		"        #define putchar _putchar_nolock",
		"    #endif",
		"    struct IOReader {",
		"        template <typename T> inline IOReader& operator >> (T& x) { x = 0; int f = 1, c = getchar(); for (; !isdigit(c); c = getchar()) { if (c == 45) f = -1; } for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48); x *= f; return *this; }",
		"        inline IOReader& operator >> (bool& x) { bool f = 0; int c = getchar(); for (; !isdigit(c); c = getchar()); for (; isdigit(c); c = getchar()) f |= (c != 48); return x = f, *this; }",
		"        inline IOReader& operator >> (std :: string& x) { x.clear(); int c = getchar(); for (; isspace(c) and c != EOF; c = getchar()); for (; !isspace(c) and c != EOF; c = getchar()) x += c; return *this; }",
		"        inline IOReader& operator >> (char* x) { int c = getchar(); for (; isspace(c) and c != EOF; c = getchar()); for (; !isspace(c) and c != EOF; c = getchar()) *(x++) = c; *x = '\\0'; return *this; }",
		"        inline IOReader& operator >> (char& x) { for (x = getchar(); isspace(x); x = getchar()); return *this; }",
		"        inline IOReader& operator >> (float& x) { x = 0; bool f = 0; int c = getchar(); for (; !isdigit(c) and c != '.'; c = getchar()) { if (c == 45) f ^= 1; } for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); if (c == '.') { c = getchar(); float tmp = 0.1; for (; isdigit(c); c = getchar()) { x += tmp * (c ^ 48); tmp *= 0.1; } } if (f) x = -x; return *this; }",
		"        inline IOReader& operator >> (double& x) { x = 0; bool f = 0; int c = getchar(); for (; !isdigit(c) and c != '.'; c = getchar()) { if (c == 45) f ^= 1; } for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); if (c == '.') { c = getchar(); double tmp = 0.1; for (; isdigit(c); c = getchar()) { x += tmp * (c ^ 48); tmp *= 0.1; } } if (f) x = -x; return *this; }",
		"        inline IOReader& operator >> (long double& x) { x = 0; bool f = 0; int c = getchar(); for (; !isdigit(c) and c != '.'; c = getchar()) { if (c == 45) f ^= 1; } for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); if (c == '.') { c = getchar(); long double tmp = 0.1; for (; isdigit(c); c = getchar()) { x += tmp * (c ^ 48); tmp *= 0.1; } } if (f) x = -x; return *this; }",
		"    } iocin;",
		"    struct IOWriter {",
		"        template <typename T> inline IOWriter& operator << (T x) { static short tmp[50]; short tot = 0; if (x == 0) return putchar(48), *this; if (x < 0) { for (putchar(45); x; x /= 10) tmp[++tot] = -(x % 10) | 48; } else { for (; x; x /= 10) tmp[++tot] = x % 10 | 48; } for (int i = tot; i >= 1; i--) putchar(tmp[i]); return *this; }",
		"        template <typename T> inline IOWriter& operator << (T* x) { while (*x) putchar(*(x++)); return *this; }",
		"        inline IOWriter& operator << (const char x) { putchar(x); return *this; }",
		"        inline IOWriter& operator << (const std :: string x) { for (int i = 0, len = x.size(); i < len; i++) putchar(x[i]); return *this; }",
		"        inline IOWriter& operator << (const bool x) { putchar(x ? 49 : 48); return *this; }",
		"    } iocout;",
		"    #define cin iocin",
		"    #define cout iocout",
		"    #ifndef LOCAL",
		"        #undef getchar",
		"        #undef putchar",
		"    #endif",
		"}"
	],
	"description": "FastIO"
	}
}
原文