Skip to content

Instantly share code, notes, and snippets.

@GoBigorGoHome
GoBigorGoHome / CF-1132G-Greedy-Subsequences.cpp
Last active November 8, 2019 14:27
正解。DFS序 + 线段树。
#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;
#define sq(x) (x)*(x) // square
#define FAST_READ ios::sync_with_stdio(false); cin.tie(nullptr);
int get_next(const char *P, const int *fail, const char ch, int i) {
while (i != -1 && P[i] != ch)
i = fail[i];
return i + 1;
}
void get_fail(const char *P, int *fail, const int len_P) {
fail[0] = -1;
for (int i = 1; i <= len_P; i++) {
fail[i] = get_next(P, fail, P[i - 1], fail[i - 1]);
@GoBigorGoHome
GoBigorGoHome / CPPCIA-notes.md
Last active March 6, 2019 05:40
C++ Concurrency in Action 2e Notes

作者喜欢用这样的句式

The C++14 and C++17 Standards have built upon this baseline to provide further support for writing multithreaded programs in C++, as have the Technical Specifications.

Multitasking operating systems that allow a single desktop computer to run multiple applications at the same time through task switching have been commonplace for many years, as have high-end server machines with multiple processors that enable genuine concurrency.

易混淆的词

@GoBigorGoHome
GoBigorGoHome / c++-notes.md
Last active February 23, 2019 05:13
C++ notes

What "copying an object" actually means.

special member functions

copy constructor, copy assignment operator, and destructor are special member functions.

copy semantics (regarding to resource management)

the rule of three

@GoBigorGoHome
GoBigorGoHome / chap1.md
Last active November 5, 2024 12:52
CS:APP3e notes
   _____   _____              _____   _____  
  / ____| / ____|_     /\    |  __ \ |  __ \ 
 | |     | (___ (_)   /  \   | |__) || |__) |
 | |      \___ \     / /\ \  |  ___/ |  ___/ 
 | |____  ____) |_  / ____ \ | |     | |     
  \_____||_____/(_)/_/    \_\|_|     |_|     
                                             
 
@GoBigorGoHome
GoBigorGoHome / 模板-NTT.cpp
Last active January 16, 2019 06:00
NTT 模板。模数为 998244353 的情形,998244353 的最小原根为 3
using poly = vector<int>;
void bit_reverse_swap(poly &a) {
int n = SZ(a);
for (int i = 1, j = n >> 1, k; i < n - 1; i++) {
if (i < j) swap(a[i], a[j]);
//tricky
for (k = n >> 1; j >= k; j -= k, k >>= 1); //inspect the highest "1"
j += k;
// 这种写法内存消耗大约是上一种写法的两倍,时间消耗二者差不多。
template <typename Arc>
struct SCC {
int n;
using Graph = vector<vector<Arc>>;
Graph &g;
function<int&(Arc &)> get_v;
vector<int> scc_id;
int scc_cnt;
Graph scc_g; // 缩点建图
inline int h_bit(unsigned long long x) {
return sizeof(unsigned long long) * 8 - 1 - __builtin_clzll(x); // or return 63 - __builtin_clzll(x); ??
}
template <typename T, typename Compare = std::less<T>>
struct ST{
size_t n; // 0-indexed
vv<T> a;
// const static Compare comp;
template <typename ptr_t>
ST(ptr_t beg, ptr_t end):n(end-beg){
#include <type_traits>
#include <cstdint>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <numeric>
#include <cassert>
@GoBigorGoHome
GoBigorGoHome / 矩阵乘法类.cpp
Created December 18, 2018 18:40
template code library
using vec = vector<ll>;
using mat = vector<vec>;
mat get_I(int n) {
mat res(n, vec(n));
for (int i = 0; i < n; i++)
res[i][i] = 1;
return res;
}
mat operator*(const mat &a, const mat &b) {