結果
| 問題 |
No.649 ここでちょっとQK!
|
| コンテスト | |
| ユーザー |
aimy
|
| 提出日時 | 2018-02-10 09:06:04 |
| 言語 | Haskell (9.10.1) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,150 bytes |
| コンパイル時間 | 147 ms |
| コンパイル使用メモリ | 149,760 KB |
| 最終ジャッジ日時 | 2024-11-14 20:20:47 |
| 合計ジャッジ時間 | 1,033 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、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:2:1: error: [GHC-87110]
Could not load module ‘Data.Set’.
It is a member of the hidden package ‘containers-0.6.8’.
Use -v to see a list of the files searched for.
|
2 | import qualified Data.Set as S
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ソースコード
import qualified Data.ByteString.Char8 as B
import qualified Data.Set as S
type Heap = S.Set (Integer,Int)
main = do
[_,k] <- map read . words <$> getLine
qs <- map readIntegers . B.lines <$> B.getContents
let hmax = S.empty
let hmin = S.empty
let (_, _, ans) = foldl (query k) (hmax, hmin, []) (zip qs [0..])
mapM_ print (reverse ans)
query :: Int -> (Heap, Heap, [Integer]) -> ([Integer], Int) -> (Heap, Heap, [Integer])
query k (hmax, hmin, acc) ([1,x],i)
| S.size hmax < k = (S.insert (x,i) hmax, hmin, acc)
| x < xmax = (S.insert (x,i) hmax', S.insert (xmax,j) hmin, acc)
| otherwise = (hmax, S.insert (x,i) hmin, acc)
where
((xmax,j), hmax') = S.deleteFindMax hmax
query k (hmax, hmin, acc) ([2],_)
| S.size hmax < k = (hmax, hmin, (-1):acc)
| S.null hmin = (hmax', hmin, xmax:acc)
| otherwise = (S.insert (xmin,j) hmax', hmin', xmax:acc)
where
((xmax,i), hmax') = S.deleteFindMax hmax
((xmin,j), hmin') = S.deleteFindMin hmin
readInteger :: B.ByteString -> Integer
readInteger = maybe undefined fst . B.readInteger
readIntegers :: B.ByteString -> [Integer]
readIntegers = map readInteger . B.words
aimy