Skip to content

Instantly share code, notes, and snippets.

@hjroh0315
hjroh0315 / xs32.cpp
Created September 21, 2022 17:45
xorshift32 (usable with std::shuffle and more)
#include<bits/stdc++.h>
using namespace std;
using u32=uint32_t;
struct xorshift32_gen
{
const u32 default_seed = 1;
u32 cur;
using result_type=u32;
xorshift32_gen():cur(default_seed){}
xorshift32_gen(u32 sd):cur(sd){}
@hjroh0315
hjroh0315 / wtf.cpp
Created August 10, 2022 09:28
what the f
struct sizedinput
{
int sz;
template<class T>
operator T()
{
T a(sz);for(auto&k:a)cin>>k;return a;
}
};
@hjroh0315
hjroh0315 / memoize.cpp
Last active June 7, 2022 12:21
@cache in C++
#include<iostream>
#include<functional>
#include<map>
#include<tuple>
using namespace std;
// start class definition
template<class>
struct memoize{};
@hjroh0315
hjroh0315 / mosalg.cpp
Last active May 31, 2022 07:02
Template for Mo's algorithm, uses two (or four if different behaviour on each side) functors for addition and deletion. also two kinds of ordering options are available, one is the classical Mo's algorithm ((n+q)sqrt n time complexity), the other is Hilbert-Mo (n sqrt q time complexity). You can define other ordering options as you wish
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
struct Query
{
size_t idx,s,e;
long long ord;
@hjroh0315
hjroh0315 / cycledecomp.cpp
Last active June 30, 2022 02:43
순열 사이클 분할 w/ 값 압축
#include<iostream>
#include<vector>
#include<map>
#include<functional>
using namespace std;
using ll=long long;
template<class T>
vector<vector<T>> decomp(vector<T> vec)
{
@hjroh0315
hjroh0315 / trie.cpp
Last active May 21, 2022 02:56
직접 만들어 본 트라이 (문제점: 메모리를 주구장창 먹음)
#include<iostream>
#include<vector>
using namespace std;
//트라이 (trie)
struct TrieNode
{
TrieNode* child[256];
int contains[256]={0};
int childcnt=0;
@hjroh0315
hjroh0315 / hashtable.cpp
Created May 14, 2022 02:36
직접 만들어 본 해시테이블
#include<iostream>
#include<iomanip>
#include<utility>
#include<algorithm>
#include<list>
using namespace std;
template<class K, class V, size_t sz>
struct HashTable
{
@hjroh0315
hjroh0315 / fibo_tmp_logn_nomatrix.cpp
Last active May 6, 2022 09:37
Fibonacci in TMP, log N time complexity, without using a matrix. | 피보나치, 로그 시복도, 행렬 없이.
#include<iostream>
#include<type_traits>
using namespace std;
using ll=long long;
template<ll val>
using llconst=integral_constant<ll,val>;
constexpr ll mod=1000000007;
@hjroh0315
hjroh0315 / heap.cpp
Last active April 23, 2022 02:30
힙을 구현하려고 했고, 구현했는데, 고장이네요. 엉엉ㅇㅇㅇ어어어어어어어ㅓㅇㅇㅇㅇㅇ
#include <iostream>
#include <vector>
using namespace std;
template<class T, class Comp=greater<T> >
struct heap{
vector<T> data;
Comp cmp;
heap(){data.push_back({});}
void push(T t){
@hjroh0315
hjroh0315 / circular_buffer.cpp
Last active May 13, 2022 07:42
PS/CP를 위한 원형 큐 클래스. Range-based for를 통해 BFS를 할 수 있습니다. std::queue와 같은 함수 기능을 제공합니다. || Circular buffer class for Problem Solving/Competitive programming. Can be used with a range-based for statement in BFS. Provides the same functionality with std::queue.
#include<exception>
using namespace std;
//////// BEGIN STRUCT DEFINITION ////////
template<class T, size_t sz>
struct circular_buffer
{
struct It
{
circular_buffer<T,sz>&par;