Skip to content

Instantly share code, notes, and snippets.

@GoBigorGoHome
GoBigorGoHome / CF-Global-Round-2-F-Niyaz-and-Small-Degrees.cpp
Last active May 26, 2019 06:31
Wang Xiuhan 的代码。我加了点注释。
#include <bits/stdc++.h>
using namespace std;
int main() {
#ifdef wxh010910
freopen("input.txt", "r", stdin);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
@GoBigorGoHome
GoBigorGoHome / 【模板】最小费用最大流.cpp
Last active November 8, 2019 15:47
封装成一个类。连续最短路算法:Dijkstra/SPFA + DFS 多路增广(precondition:初始网络中没有负圈)
class MCMF {
struct arc {
const int to, next, cost;
mutable int cap;
};
const int n_node;
vi head;
vector<arc> e;
mutable vi d;
@GoBigorGoHome
GoBigorGoHome / CF-R561-Div2-D.cpp
Created May 17, 2019 18:46
这是一道跟二进制相关的题目。
const int mod = 1e9+7;
#ifdef LOCAL
//#define _GLIBCXX_DEBUG
// #pragma comment(linker, "/STACK:102400000,102400000") // 在 Windows 上有效
#endif
//#pragma GCC optimize ("Ofast") // Ofast 等效于 -O3 -ffast-math
#include <bits/stdc++.h>
using namespace std;
// Andrew He's modular-arithmetic class
template <int MOD_> struct modnum {
template <typename T>
T inverse(T a, T m) {
T u = 0, v = 1;
while (a != 0) {
T t = m / a;
m -= t * a; swap(a, m);
u -= t * v; swap(u, v);
}
assert(m == 1);
return u;
@GoBigorGoHome
GoBigorGoHome / HDU-6375-正解.cpp
Created May 13, 2019 16:08
时间复杂度O(Q)
const int mod = 1e9+7;
#ifdef LOCAL
//#define _GLIBCXX_DEBUG
// #pragma comment(linker, "/STACK:102400000,102400000") // 在 Windows 上有效
#endif
//#pragma GCC optimize ("Ofast") // Ofast 等效于 -O3 -ffast-math
#include <bits/stdc++.h>
using namespace std;
// Andrew He's modular-arithmetic class
template <int MOD_> struct modnum {
@GoBigorGoHome
GoBigorGoHome / CometOJ-contest3-C.cpp
Created May 11, 2019 02:00
子序列子序列子序列...
const int mod = 1e9+7;
#ifdef LOCAL
//#define _GLIBCXX_DEBUG
// #pragma comment(linker, "/STACK:102400000,102400000") // 在 Windows 上有效
#endif
//#pragma GCC optimize ("Ofast") // Ofast 等效于 -O3 -ffast-math
#include <bits/stdc++.h>
using namespace std;
// Andrew He's modular-arithmetic class
template <int MOD_> struct modnum {
@GoBigorGoHome
GoBigorGoHome / CF-1156-G-Optimizer.cpp
Created May 7, 2019 07:06
CF-1156-G-Optimizer 不做名称替换的写法,草稿(还没写完)
const int mod = 998244353;
#ifdef LOCAL
//#define _GLIBCXX_DEBUG
// #pragma comment(linker, "/STACK:102400000,102400000") // 在 Windows 上有效
#endif
//#pragma GCC optimize ("Ofast") // Ofast 等效于 -O3 -ffast-math
#include <bits/stdc++.h>
using namespace std;
// Andrew He's modular-arithmetic class
template <int MOD_> struct modnum {
@GoBigorGoHome
GoBigorGoHome / 【模板】高斯消元.cpp
Last active April 23, 2019 13:04
F_p 上的高斯消元。
/* a tutorial on Gauss-Jordan elimination: https://cp-algorithms.com/linear_algebra/linear-system-gauss.html
From the article:
Strictly speaking, the method described below should be called "Gauss-Jordan", or Gauss-Jordan elimination,
because it is a variation of the Gauss method, described by Jordan in 1887.
*/
using num = modnum<1000003>;
using mat = vv<num>;
using vec = vector<num>;
// precondition: 系数矩阵不含0,否则需要选主元。
@GoBigorGoHome
GoBigorGoHome / 【模板】mod-arithmetic.cpp
Last active November 8, 2019 14:26
square1001 的模算术模板。已废弃。用 tourist 的模算术模板了。
// source: https://codeforces.com/contest/1151/submission/52969000
#ifndef ___CLASS_MODINT
#define ___CLASS_MODINT
#include <cstdint>
template<std::uint32_t mod>
class modint {
private:
std::uint32_t n;
@GoBigorGoHome
GoBigorGoHome / 【模板】modular-arithmetic.cpp
Last active November 8, 2019 14:27
Andrew He (ecnerwala) 的模算术模板。已废弃。
// source: https://codeforces.com/contest/1151/submission/52973403
template <int MOD_> struct modnum {
static constexpr int MOD = MOD_;
static_assert(MOD_ > 0, "MOD must be positive");
private:
using ll = long long;
int v;