akthrms
@akthrms has joined the channel
: とは何のことですか。: とは何のことですか。import qualified Data.ByteString.Char8 as BS import Data.Maybe import qualified Data.Vector.Unboxed as VU readInt = fst . fromJust . BS.readInt readIntList = map readInt . BS.words getIntList = readIntList <$> BS.getLine prod :: VU.Vector Int -> Integer prod = mod1G7 . VU.product . VU.map fromIntegral mod1G7 :: Integral a => a -> a mod1G7 n = n `mod` (10 ^ 9 + 7) main :: IO () main = do [n, k] <- getIntList as <- getIntList let as' = VU.fromList as print $ prod as'
4 2 1 2 -3 -4
abc/173/E.hs:31:17: error:
• No instance for (VU.Unbox Integer)
arising from a use of 'VU.product'
• In the first argument of '(.)', namely 'VU.product'
In the second argument of '(.)', namely
'VU.product . VU.map fromIntegral'
In the expression: mod1G7 . VU.product . VU.map fromIntegral
|
31 | prod = mod1G7 . VU.product . VU.map fromIntegral
| ^^^^^^^^^^prod :: VU.Vector Int -> Int
• Ambiguous type variable 'a0' arising from a use of 'VU.product'
prevents the constraint '(VU.Unbox a0)' from being solved.
Relevant bindings include
prod :: VU.Vector Int -> a0 (bound at abc/173/E.hs:31:1)
Probable fix: use a type annotation to specify what 'a0' should be.
These potential instances exist:
instance VU.Unbox a => VU.Unbox (Down a)
-- Defined in 'Data.Vector.Unboxed.Base'
instance VU.Unbox () -- Defined in 'Data.Vector.Unboxed.Base'
instance (VU.Unbox a, VU.Unbox b) => VU.Unbox (a, b)
-- Defined in 'Data.Vector.Unboxed.Base'
...plus 10 others
...plus 24 instances involving out-of-scope types
(use -fprint-potential-instances to see them all)
• In the first argument of '(.)', namely 'VU.product'
In the second argument of '(.)', namely
'VU.product . VU.map fromIntegral'
In the expression: mod1G7 . VU.product . VU.map fromIntegral
|
31 | prod = mod1G7 . VU.product . VU.map fromIntegral
| ^^^^^^^^^^Integer も格納できます。私
modを取ると崩れる関係もあるので10^18は64bit Intの範囲なので、絶対値が10^9以下の2つの数の積なら、modを取らずともIntの範囲におさまります。modをとる積を使うのは、最後の最大値を求めるところだけですみそうですね。