This file contains 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
import Data.List.Split | |
import qualified Data.Vector as V | |
rmqBuild :: [Int] -> (Int, V.Vector Int) | |
rmqBuild xs = | |
let l = length xs | |
n = until (\ x -> x >= l) (*2) 1 | |
inf = maxBound :: Int | |
f ys = map minimum $ chunksOf 2 ys | |
in (n ,V.fromList $ concat $ |
This file contains 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
import qualified Data.Vector as V | |
import qualified Data.List as L | |
accSum :: Num t => [t] -> [t] | |
accSum xs = aux xs 0 | |
where aux [] a = [] | |
aux (x:xs') a = (a + x) : aux xs' (a + x) | |
lowerBound :: (Num a, Ord a) => V.Vector a -> a -> Int |
This file contains 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
import Text.Parsec | |
import Text.Parsec.Expr | |
import Text.Parsec.Combinator | |
import Data.Functor | |
data Exp = Num Int | |
| Add Exp Exp | |
| Sub Exp Exp | |
| Mul Exp Exp | |
| Div Exp Exp |
This file contains 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
{-# LANGUAGE ExistentialQuantification #-} | |
module DFA ( | |
DFA, | |
runDFA, | |
scanDFA, | |
isAccepting, | |
) where | |
import Data.Set (Set) |
This file contains 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
import System.IO | |
import Control.Monad | |
import Text.ParserCombinators.Parsec | |
import Text.ParserCombinators.Parsec.Expr | |
import Text.ParserCombinators.Parsec.Language | |
import qualified Text.ParserCombinators.Parsec.Token as Token | |
data BExpr = BoolConst Bool | |
| Not BExpr |
This file contains 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
from __future__ import division | |
class BinaryIndexTree: | |
def __init__(self, n): | |
self.sz = n | |
self.vals = [0] * (n + 1) | |
def update(self, idx, delta): | |
"add c to the value at index idx" |
This file contains 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
import Control.Applicative | |
import Control.Monad | |
import qualified Data.ByteString.Char8 as BS | |
import Data.List | |
import Data.Maybe | |
import qualified Data.Vector as V | |
data SegTree a = | |
Node { | |
val :: a |
This file contains 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
from __future__ import division | |
from collections import defaultdict, deque | |
from heapq import heappush, heappop | |
from sys import stdin | |
class UnionFindSet: | |
def __init__(self, nodes): | |
self.fa = {} | |
for n in nodes: | |
self.fa[n] = n |
This file contains 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
module Decorator | |
def initialize(decorated) | |
@decorated = decorated | |
end | |
def method_missing(method, *args) | |
args.empty? ? @decorated.send(method) : @decorated.send(method, args) | |
end | |
end |
This file contains 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
class Solution(object): | |
def addTwoNumbers(self, l1, l2): | |
ll1 = self.list2naive(l1) | |
ll2 = self.list2naive(l2) | |
a = 0 if ll1 == [] else int(''.join(map(str, ll1))[::-1]) | |
b = 0 if ll2 == [] else int(''.join(map(str, ll2))[::-1]) | |
res = a + b | |
return self.naive2list(map(int, list(str(res)[::-1]))) | |
def list2naive(self, l): |