Skip to content

Instantly share code, notes, and snippets.

View juanplopes's full-sized avatar
🌲
Is that a Segment Tree problem?

Juan Lopes juanplopes

🌲
Is that a Segment Tree problem?
View GitHub Profile
#include <iostream>
#include <vector>
#include <set>
using namespace std;
int T[100];
vector<set<int> > V;
bool test(int C, set<int> &X, set<int> &Y) {
int count = 0;
@juanplopes
juanplopes / download.py
Created October 23, 2016 15:56
Downloads problems, best submissions and leaderboard from IEEExtreme 10 competition
#!/usr/bin/env python2
from collections import defaultdict
import requests, json, zipfile
PREFIX = 'https://ieee.hackerrank.com/rest/contests/ieeextreme10'
USER='PUT USERNAME HERE'
PASS='PUT PASSWORD HERE'
EXT = {'python': 'py'}
@juanplopes
juanplopes / UpdateHeap.java
Created July 28, 2016 20:12
Modifiable binary heap
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
public class UpdateHeap<V> implements Iterable<V> {
private final Comparator<V> comparator;
private final HashMap<V, Entry> map;
private Entry[] heap;
@juanplopes
juanplopes / gist:558a46c06eb52aeff5c64a3861943105
Created April 13, 2016 19:32
Brainfuck interpreter in Pipes
def push(stack, el): stack+(el,);
def pop(stack): (stack:take(len(stack)-1), stack:get(len(stack)-1));
def memset(state, key, value): (state |> @filter({0}!=key)) + ((key, value),);
def memget(state, key): state |> last({1}):if({0}==key)# ?? 0;
def memadd(state, key, value): memset(state, key, memget(state, key)+value);
def findclosing(code, i):
(1, i+1):unfold(fun(count, i):
i >= len(code) or count == 0 ? null,
code:get(i) == '[' ? (i, (count+1, i+1)),
@juanplopes
juanplopes / Main.java
Created February 18, 2016 12:51
Object Pool example
package example;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
public class Main {
public static void main(String... args) throws Exception {
ObjectPool<ExpensiveObject> pool = new ObjectPool<ExpensiveObject>() {
@Override
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
struct Dist {
int node, d;
Dist(int node, int d) : node(node), d(d) { }
};

Remember

This is ok:

for(int i = 1; i <= floor(sqrt(n)); i++) {
    //code
}
100 1073741823
1 1
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
def next_digit(value, base):
return value + str(sum(int(a)*b for a,b in zip(value, base))%11%10)
def make_valid(value, ap2, base):
return next_digit(next_digit(value, base), ap2+base)
def is_valid_cpf(cpf):
return make_valid(cpf[:9], [0], [1,2,3,4,5,6,7,8,9]) == cpf
def is_valid_cnpj(cnpj):
# -*- coding: utf-8 -*-
from __future__ import print_function
import timeit, random, sys
if sys.version_info >= (3, ): xrange=range
def partition(data, begin, end):
value = data[end-1]
pivot = begin