{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ImportQualifiedPost #-}
{-# HLINT ignore "Use lambda-case" #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE LambdaCase #-}
{-# HLINT ignore "Used otherwise as a pattern" #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeApplications #-}
{-# OPTIONS_GHC -Wno-overlapping-patterns #-}
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
module Main where
import Control.Applicative ((<|>))
import Control.Monad
import Control.Monad.ST
import Control.Monad.State (MonadState (get), StateT (StateT, runStateT))
import Data.Array (Array)
import Data.Array.IArray
import Data.Array.IO
import Data.Array.IO.Internals (IOArray (IOArray), IOUArray (IOUArray))
import Data.Array.MArray
import Data.Array.ST ()
import Data.Array.ST.Safe (runSTUArray)
import Data.Array.Unboxed (UArray)
import Data.Bifoldable (Bifoldable (bifold))
import Data.Bifunctor (bimap)
import Data.Bits (xor)
import Data.Bool (bool)
import Data.ByteString.Char8 qualified as BC
import Data.Char (digitToInt, ord)
import Data.Char qualified as C
import Data.Foldable (for_)
import Data.Foldable.Extra (traverse_)
import Data.Function (fix, on)
import Data.Graph.Inductive (deg', neighbors')
import Data.HashSet qualified as HS
import Data.Heap qualified as H
import Data.IORef (modifyIORef', newIORef, readIORef, writeIORef)
import Data.IORef qualified as MV
import Data.IntMap qualified as IM
import Data.IntSet qualified as IS
import Data.Ix
import Data.List
import Data.List.Extra
import Data.Map qualified as M
import Data.Maybe
import Data.Mutable
import Data.Ord
import Data.Ratio ((%))
import Data.STRef (modifySTRef', newSTRef, readSTRef, writeSTRef)
import Data.Sequence (Seq (Empty, (:<|), (:|>)), ViewL ((:<)), ViewR ((:>)), (|>))
import Data.Sequence qualified as Seq
import Data.Set qualified as S
import Data.Vector qualified as V
import Data.Vector.Generic qualified as VG
import Data.Vector.Unboxed qualified as VU
import Data.Vector.Unboxed.Mutable qualified as MV
import Debug.Trace (traceShow)
import GHC.IO (unsafePerformIO)
import System.Environment (lookupEnv)
main :: IO ()
main = do
[n, m] <- getInts
as <- getInts
bs <- getInts
let im = foldl' (\acc a -> IM.insertWith (+) a 1 acc) IM.empty as
im' = foldl' (flip (IM.adjust (\v -> v - 1))) im bs
ans = concat [replicate v k | let lst = IM.toAscList im', (k, v) <- lst, v > 0]
printList ans
{-- lib --}
-- inputs
getInts :: IO [Int]
getInts = unfoldr (BC.readInt . BC.dropWhile C.isSpace) <$> BC.getLine
getInteger :: IO [Integer]
getInteger = unfoldr (BC.readInteger . BC.dropWhile C.isSpace) <$> BC.getLine
-- outputs
printYn :: Bool -> IO ()
printYn f = putStrLn $ bool "No" "Yes" f
printList :: (Show a) => [a] -> IO ()
printList lst = putStrLn $ unwords $ map show lst
-- list
fromListToTuple :: [Int] -> (Int, Int)
fromListToTuple [a, b] = (a, b)
countBy :: (Foldable t) => (e -> Bool) -> t e -> Int
countBy predicate = foldl' (\acc a -> if predicate a then acc + 1 else acc) 0
-- fold
foldFor' :: (Foldable t) => b -> t a -> (b -> a -> b) -> b
foldFor' initial xs f = foldl' f initial xs
foldForM :: (Foldable t, Monad m) => b -> t a -> (b -> a -> m b) -> m b
foldForM initial xs m = foldM m initial xs
foldForM_ :: (Foldable t, Monad m) => b -> t a -> (b -> a -> m b) -> m ()
foldForM_ initial xs m = foldM_ m initial xs
-- Array用のfind
findArrayIndices :: (IArray a e, Ix i) => (e -> Bool) -> a i e -> [i]
findArrayIndices predicate as = [i | (i, e) <- assocs as, predicate e]
-- Array用の(!?)
(!?) :: (IArray a e, Ix i) => a i e -> i -> Maybe e
(!?) arr i =
let b = bounds arr
in if inRange b i
then Just (arr ! i)
else Nothing
instance (Num a, Num b) => Num (a, b) where
(+) :: (Num a, Num b) => (a, b) -> (a, b) -> (a, b)
(a1, b1) + (a2, b2) = (a1 + a2, b1 + b2)
(*) :: (Num a, Num b) => (a, b) -> (a, b) -> (a, b)
(a1, b1) * (a2, b2) = (a1 * a2, b1 * b2)
abs :: (Num a, Num b) => (a, b) -> (a, b)
abs (a1, b1) = (abs a1, abs b1)
signum :: (Num a, Num b) => (a, b) -> (a, b)
signum (a1, b1) = (signum a1, signum b1)
fromInteger :: (Num a, Num b) => Integer -> (a, b)
fromInteger i = (fromInteger i, fromInteger i)
negate :: (Num a, Num b) => (a, b) -> (a, b)
negate (a1, b1) = (negate a1, negate b1)
{-- debug --}
dbg :: (Show a) => a -> ()
dbg _ = ()
fnDbg :: (Show a) => a -> a
fnDbg x = x
app/Main.hs:71:4: warning: [-Wunused-matches]
Defined but not used: ‘n’
|
71 | [n, m] <- getInts
| ^
app/Main.hs:71:7: warning: [-Wunused-matches]
Defined but not used: ‘m’
|
71 | [n, m] <- getInts
| ^
app/Main.hs:98:1: warning: [-Wincomplete-patterns]
Pattern match(es) are non-exhaustive
In an equation for ‘fromListToTuple’:
Patterns of type ‘[Int]’ not matched:
[]
[_]
(_:_:_:_)
|
98 | fromListToTuple [a, b] = (a, b)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
app/Main.hs:125:1: warning: [-Worphans]
Orphan instance: instance (Num a, Num b) => Num (a, b)
Suggested fix:
Move the instance declaration to the module of the class or of the type, or
wrap the type with a newtype and declare the instance on the new type.
|
125 | instance (Num a, Num b) => Num (a, b) where
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...