Created
January 10, 2017 15:56
-
-
Save YoshiyukiKato/714990a88a6980cff708e6150fc699af to your computer and use it in GitHub Desktop.
template for programming contest
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
import System.IO hiding (char8) | |
import Control.Applicative | |
import Control.Monad | |
import Data.List | |
import Data.Tuple | |
import Data.Tree | |
import Data.Int | |
import Data.Char | |
import Data.Function (on) | |
import Data.Array | |
import Data.Array.Unboxed | |
import Data.Array.IArray | |
import Data.Ix | |
import Data.Maybe | |
import Data.Monoid hiding ((<>)) | |
import qualified Data.ByteString.Char8 as BS | |
import qualified Data.ByteString.Lazy.Char8 as BL | |
import Data.ByteString.Builder | |
import Control.Monad.ST | |
import Data.Array.ST | |
import Data.Array.Unsafe | |
import Data.Vector.Unboxed ((//), (++), (!), (!?)) | |
import qualified Data.Vector.Unboxed as U | |
import Data.IntMap.Strict (IntMap) | |
import qualified Data.IntMap.Strict as IntMap | |
import Data.Sequence ((|>), (<|), (><),ViewR((:>)), ViewL((:<))) | |
import qualified Data.Sequence as S | |
import Debug.Trace | |
-- + -- + -- + -- + -- + -- + -- + -- + -- + -- + -- + -- + -- + -- + -- + -- + -- + -- | |
main :: IO () | |
main = do | |
n <- readInt1 <$> BS.getLine | |
nums <- replicateM n $ readInt1 <$> BS.getLine | |
-- + -- + -- + -- + -- + -- + -- + -- + -- + -- + -- + -- + -- + -- + -- + -- + -- + -- | |
readInt1 :: BS.ByteString -> Int | |
readInt1 = fst . fromJust . BS.readInt | |
readInt2 :: BS.ByteString -> (Int,Int) | |
readInt2 = toTuple . readIntN | |
readInt3 :: BS.ByteString -> (Int,Int,Int) | |
readInt3 = toTriple . readIntN | |
readIntN :: BS.ByteString -> [Int] | |
readIntN = map readInt1 . BS.words | |
toTuple :: [a] -> (a, a) | |
toTuple [x, y] = (x, y) | |
toTriple :: [a] -> (a, a, a) | |
toTriple [x, y, z] =(x, y, z) | |
fromTuple :: (a, a) -> [a] | |
fromTuple (x, y) = [x, y] | |
fromTriple :: (a, a, a) -> [a] | |
fromTriple (x, y, z) = [x, y, z] | |
applyTuple :: (a -> a') -> (b -> b') -> (a, b) -> (a', b') | |
applyTuple f g (x, y) = (f x, g y) | |
applyTriple :: (a -> a') -> (b -> b') -> (c -> c') -> (a, b, c) -> (a', b', c') | |
applyTriple f g h (x, y, z) = (f x, g y, h z) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment