Skip to content

Instantly share code, notes, and snippets.

#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <mutex>
#include <thread>
#include <chrono>
using namespace std;
using namespace std::chrono_literals;
@shininglion
shininglion / lazy_argument.cpp
Created August 25, 2018 06:16
lazy evaluation for function arguments
#include <iostream>
#include <type_traits>
#define LAZY_ARG(e) [&]() { return e; }
using namespace std;
// Implementation that requires C++17 support.
template <typename ... Args>
void print_17(Args&& ... args)
{
@shininglion
shininglion / constexpr_if.cpp
Last active August 9, 2018 14:52
compile-time if can have code not able to be compiled with regular if
// Example from: C++17-The Complete Guide, by Nicolai M. Josuttis
// Chapter 10. Compile-Time if
// http://www.cppstd17.com/
#include <string>
#include <iostream>
template <typename T>
std::string toString_constexpr_if(T x)
{
@shininglion
shininglion / prvalue.cpp
Last active June 26, 2018 02:46
prvalue sucks
/*
* =====================================================================================
*
* Filename: prvalue.cpp
*
* Description: test prvalue
*
* Version: 1.0
* Created: 2018/06/26 (yyyy/mm/dd)
* Revision: none
@shininglion
shininglion / quick_select.cpp
Created May 6, 2018 06:25
Implementation and simple test of "Quick Select" with different strategies to chossing pivot
/*
* ===========================================================================================
*
* Filename: quick_select.cpp
*
* Description: Find the kth element from a unsorted sequence with quick select algorithm.
*
* Version: 1.0
* Created: 2018/05/04 (yyyy/mm/dd)
* Revision: none
@shininglion
shininglion / find_median.cpp
Last active May 4, 2018 12:54
Apply the algorithm "Median of Median" to find the median from an unsorted sequence in linear time
/*
* =====================================================================================
*
* Filename: find_median.cpp
*
* Description: Find the median from an unsorted data
*
* Version: 1.0
* Created: 2018/05/04 (yyyy/mm/dd)
* Revision: none
@shininglion
shininglion / codeforces-946B.c
Created March 19, 2018 14:48
Accepted implementation of codeforces 946B: Weird Substraction Process
/*
* =====================================================================================
*
* Filename: 946B.cpp
*
* Description: codeforces 946B: Weird Substraction Process
*
* Version: 1.0
* Created: 2018/03/19 (yyyy/mm/dd)
* Revision: none
@shininglion
shininglion / codeforces-166C.cpp
Created March 19, 2018 06:17
Accepted answer of codeforces 166C: Median
/*
* =====================================================================================
*
* Filename: 166C.cpp
*
* Description: codeforces 166C: Median
*
* Version: 1.0
* Created: 2018/03/19 (yyyy/mm/dd)
* Revision: none
/*
* =====================================================================================
*
* Filename: Heavy_Light_Decomposition.cpp
*
* Description: Implementation of heavy light decomposition
*
* Version: 1.0
* Created: 2018/03/18 (yyyy/mm/dd)
* Revision: none
@shininglion
shininglion / LCA.cpp
Last active February 24, 2018 04:04
Find the lowest common ancestor (LCA) of two nodes in a tree
/*
* =====================================================================================
*
* Filename: LCA.cpp
*
* Description: Find the lowest common ancestor (LCA) of two nodes in a tree
*
* Version: 1.0
* Created: 2018/02/24 (yyyy/mm/dd)
* Revision: none