結果
問題 | No.489 株に挑戦 |
ユーザー |
![]() |
提出日時 | 2017-08-31 14:31:51 |
言語 | Haskell (9.10.1) |
結果 |
CE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 2,012 bytes |
コンパイル時間 | 1,053 ms |
コンパイル使用メモリ | 172,288 KB |
最終ジャッジ日時 | 2024-11-14 20:14:33 |
合計ジャッジ時間 | 1,788 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/environments/default [1 of 2] Compiling Main ( Main.hs, Main.o ) Main.hs:30:10: error: [GHC-39999] • No instance for ‘Semigroup V’ arising from the superclasses of an instance declaration • In the instance declaration for ‘Monoid V’ | 30 | instance Monoid V where | ^^^^^^^^
ソースコード
importData.MonoidimportqualifiedData.ByteString.CharasBreadInt::BByteString->IntreadInt = maybe undefined fst . B.readIntreadInts::BByteString->IntreadInts = map readInt . B.wordsmain = do[n,d,k] <- map read . words <$> getLinexs <- readInts <$> B.getContentslet (pmax, (i,j)) = kabu n d xsprint (k * pmax)if pmax == 0 then return () else putStrLn (show i ++ " " ++ show j)kabu n d xs = foldl (slide n d seg) (0, (undefined, undefined)) (zip xs [0 .. n-2])whereseg = fromList n (zipWith (\x i -> V x i) xs [0,-1..])slide n d seg acc@(pmax,_) (x,i)| v - x > pmax = (v - x, (i, negate j))| otherwise = accwhere(V v j) = query n seg (succ i + 1) (min (succ i + d) n)data V = V Int Index derivingEqOrdShowinstanceMonoidVwheremempty = V 0 undefinedmappend = maxdata SegTree m =Leaf !m |Node !m !(SegTree m) !(SegTree m)derivingEqShowtype Index = Inttype Size = Intval::Monoidm=>SegTreem->mval (Leaf v) = vval (Node v _ _) = vfromList::Monoidm=>Size->m->SegTreemfromList 1 [x] = Leaf xfromList n xs = Node (val left <> val right) left rightwherem = div n 2(xs1, xs2) = splitAt m xsleft = fromList m xs1right = fromList (n - m) xs2update::Monoidm=>Size->SegTreem->Index->m->m->SegTreemupdate 1 (Leaf v) 1 f = Leaf (f v)update _ (Leaf _) _ _ = error "update: Pattern match failed."update n (Node _ l r) i x| i <= m = Node (val left <> val r) left r| otherwise = Node (val l <> val right) l rightwherem = div n 2left = update m l i xright = update (n - m) r (i - m) xquery::Monoidm=>Size->SegTreem->Index->Index->mquery 1 (Leaf v) 1 1 = vquery _ (Leaf _) _ _ = error "query: Pattern match failed."query n (Node v l r) i j| (i, j) == (1, n) = v| j <= m = query m l i j| i > m = query (n - m) r (i - m) (j - m)| otherwise = query m l i m <> query (n - m) r 1 (j - m)wherem = div n 2