結果

問題 No.2961 Shiny Monster Master
コンテスト
ユーザー ducktail
提出日時 2024-11-17 20:35:06
言語 Haskell
(9.14.1 + ACL)
コンパイル:
ghc -rtsopts -with-rtsopts=-K1G -o a.out -O2 _filename_
実行:
./a.out
結果
AC  
実行時間 1,688 ms / 1,777 ms
+ 211µs
コード長 739 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,959 ms
コンパイル使用メモリ 259,060 KB
実行使用メモリ 20,480 KB
最終ジャッジ日時 2026-09-25 13:15:35
合計ジャッジ時間 44,887 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 77
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.14.1/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking a.out

ソースコード

diff #
raw source code

{-# LANGUAGE OverloadedStrings #-}
import Control.Monad (replicateM)
import Data.Text (Text)
import qualified Data.Text as T
import qualified Data.Text.IO as T
import Data.Text.Read (Reader)
import qualified Data.Text.Read as T

main :: IO ()
main = do
  [rr, _] <- f
  as <- f
  q <- g
  ans <- replicateM q $ do
    [l, r] <- f
    return $ solve rr as l r
  mapM_ print ans
  where
    f = map (readtx T.decimal) <$> T.words <$> T.getLine
    g = readtx T.decimal <$> T.getLine

solve :: Int -> [Int] -> Int -> Int -> Int
solve rr as l r = sum $ map (\a -> f r a - f (l - 1) a) as
  where
    f x a
      | x < a = 0
      | otherwise = (x - a) `div` rr + 1

readtx :: Num a => Reader a -> Text -> a
readtx f = either (const 0) fst . f
0