Skip to content

Instantly share code, notes, and snippets.

@tanitanin
tanitanin / union_find.h
Created October 7, 2014 02:01
Union-Find Tree
#pragma once
#include <list>
template<class T>
class union_find {
public:
struct node {
node *parent = nullptr;
T data;
@tanitanin
tanitanin / BIT.h
Created October 7, 2014 03:13
Binary Indexed Tree
#pragma once
#include <vector>
template<class T>
class BIT {
public:
explicit BIT(size_t N=1) : _bit(N) {}
void add(size_t i, T val) {
while (i < _bit.size()){
@tanitanin
tanitanin / segtree.h
Created October 7, 2014 04:18
Segment Tree for Range Minimum Query
#include <vector>
#include <algorithm>
#include <limits>
template<class T>
class segtree {
public:
explicit segtree(size_t N=1, T init=std::numeric_limits<T>::max())
: _init(init), _N(N), _tree(4*N,init) {}
@tanitanin
tanitanin / debug.h
Created November 6, 2014 13:33
Console output switching by debug option (-g)
#pragma once
#include <iostream>
#ifdef DEBUG
#define debug std::cout
#else
#define debug true ? : std::cout
#endif
@tanitanin
tanitanin / options.h
Last active August 29, 2015 14:08
Command line options parser
#pragma once
#include <string>
#include <functional>
#include <vector>
#include <map>
class options {
public:
@tanitanin
tanitanin / gcd_lcm.h
Last active August 29, 2015 14:08
GCD & LCM
#pragma once
template<class T> T gcd(T a, T b) {
T c;
while ( a != 0 ) { c = a; a = b%a; b = c; }
return b;
}
template<class T> T lcm(T a, T b) {
return a / gcd(a,b) * b;
@tanitanin
tanitanin / bst.h
Last active August 29, 2015 14:08
Binary Search Tree
#pragma once
#include <list>
template<class T>
class BST {
public:
struct Node {
T value;
Node *lhs, *rhs, *parent;
@tanitanin
tanitanin / segtree_add_sum.h
Created December 19, 2014 16:35
Segment Tree for range add and range sum
#pragma once
#include <vector>
#include <algorithm>
template<class T>
class segtree {
public:
struct node { T all; T part; };
explicit segtree(size_t N=1, T init=0)
@tanitanin
tanitanin / starrysky.h
Created December 19, 2014 17:06
Segment Tree for range add and minimum query
#pragma once
#include <vector>
#include <algorithm>
#include <limits>
template<class T>
class starrysky {
public:
struct node { T add; T min; };
@tanitanin
tanitanin / install.sh
Created February 14, 2015 17:03
Install script for scala version manager
#!/usr/bin/env bash
do_svm_install() {
svm_path=$HOME/.svm
if [[ ! -d "$svm_path" ]]; then
echo "Making directory $svm_path"
mkdir -p $svm_path
fi
if [[ ! -e "$svm_path/bin/.git" ]]; then