Solution to the Flea Circus problem. It uses a range minimum query segment tree to compute the lowest common ancestor between two nodes in the tree, thus the distance from one node in a tree to another can be computed in O(log n)
time, and the tree can be built in O(log(n) n)
time. This allows the entire problem to be solved in O(log(n) n)
time.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<gmpxx.h> | |
#include<gmp.h> | |
#include<vector> | |
#include<string> | |
#include<cstdio> | |
using namespace std; | |
void set_prime(mpz_t rop) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package segment_tree | |
import "fmt" | |
const sizeMultiplier int = 3 | |
type Comparator func(int, int) int | |
type Node struct { | |
set bool |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
BUNDLE_PATH: ./vendor/bundle | |
BUNDLE_DISABLE_SHARED_GEMS: '1' | |
BUNDLE_JOBS: 3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require("fs"); | |
input_lines = fs.readFileSync('/dev/stdin').toString().split('\n').map(function(s) { | |
return s.trim(); | |
}); | |
nums = input_lines[0].split(' ').map(Number) | |
console.log(nums[0] + nums[1]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ps -o rss,command | grep ./omg | grep -v grep | |
488 ./omg | |
$ ps -o rss,command | grep ./omg | grep -v grep | |
10268 ./omg |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/http' | |
require 'uri' | |
require 'json' | |
class ProperHTTP | |
def self.get(uri) | |
handle_response Net::HTTP.get_response(URI.parse(uri)) | |
end | |
def self.post(uri, payload) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ sudo apt-get install maven | |
The following extra packages will be installed: | |
ant ant-optional aspectj bsh fop java-wrappers junit junit4 libaether-java libaopalliance-java libapache-pom-java libasm3-java | |
libaspectj-java libasync-http-client-java libatinject-jsr330-api-java libavalon-framework-java libbatik-java libbsf-java libbsh-java | |
libcdi-api-java libcglib-java libclassworlds-java libcommons-beanutils-java libcommons-cli-java libcommons-codec-java | |
libcommons-collections3-java libcommons-configuration-java libcommons-digester-java libcommons-httpclient-java libcommons-io-java | |
libcommons-jexl2-java libcommons-jxpath-java libcommons-lang-java libcommons-logging-java libcommons-net2-java libcommons-parent-java | |
libcommons-vfs-java libdom4j-java libdoxia-java libeasymock-java libfop-java libganymed-ssh2-java libgeronimo-interceptor-3.0-spec-java | |
libgeronimo-jpa-2.0-spec-java libgeronimo-osgi-support-java libguava-java libguice-java libhamcrest-java libhttpclient-java | |
libhttpcore-java libitext1-ja |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
TOTAL=$(sudo btrfs filesystem show /dev/mapper/lvroot-u | grep -oP '(?<=size )\d+\.\d+') | |
USED=$(sudo btrfs filesystem show /dev/mapper/lvroot-u | grep -oP '(?<=used )\d+\.\d+' | head -n1) | |
ALLOCATED=$(sudo btrfs filesystem show /dev/mapper/lvroot-u | grep -oP '(?<=used )\d+\.\d+' | tail -n1) | |
FREE=$(echo "$TOTAL - $USED" | bc) | |
echo -e -n "system.btrfs.total:$TOTAL|g" > /dev/udp/127.0.0.1/8125 | |
echo -e -n "system.btrfs.used:$USED|g" > /dev/udp/127.0.0.1/8125 | |
echo -e -n "system.btrfs.allocated:$USED|g" > /dev/udp/127.0.0.1/8125 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [[ -z $1 ]]; then | |
echo -e "\x1b[31mMust supply src + dest port" | |
exit 1 | |
fi | |
echo -e "\x1b[32mForwarded port $2 --> $1\x1b[33m" | |
sudo iptables -t nat -I OUTPUT -p tcp -o lo --dport $2 -j REDIRECT --to-ports $1 |