文字列
Data.ByteString.Chan8
#Data.Vector.Unboxed
create, unfoldrN, fusion
Data.Vector.Unboxed.Mutable
new, read, modify, write, freeze, thaw
データ構造
priority queue → Data.Set
グラフの構築やdfs → Data.Graph
再帰
foldl',foldr(早期リターン)
Prelude
IO
a1-an読み込み
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B
main = do
let readInt = fmap (second B.tail) . B.readInt
as <- VU.unfoldrN n readInt <$> B.getLine
ABを読み取り
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B
main = do
let readInt = fmap (second B.tail) . B.readInt
(a,b) <- (\vec -> (vec VU.! 0, vec VU.! 1)) . VU.unfoldrN 2 readInt <$> B.getLine
A1B1A2B2...AnBn
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B
main = do
let readInt = fmap (second B.tail) . B.readInt
abs <-
VU.replicateM n $ (\vec -> (vec VU.! 0, vec VU.! 1)) . VU.unfoldrN 2 readInt <$> B.getLine
IOまとめ
readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
パフォーマンスの目安
実行時間はC++の5倍以内を目指す