File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change 1+ import Control.Applicative
2+ import Control.Monad
3+ import Data.Array
4+ import Data.Maybe
5+
6+ import qualified Data.ByteString.Char8 as B
7+
8+ int = fst . fromJust . B. readInt
9+
10+ readInt :: IO Int
11+ readInt = int <$> B. getLine
12+
13+ readIntPair :: IO [Int ]
14+ readIntPair = parseLine <$> B. getLine
15+ where
16+ parseLine = (map int) . B. words
17+
18+ getAnswer prefixSums (from: to: _) = (prefixSums ! to) - (prefixSums ! (from - 1 ))
19+
20+ doMain = do
21+ n <- readInt
22+ numbers <- replicateM n readInt
23+ let prefixSums = listArray (0 , n) (scanl (+) 0 numbers)
24+ m <- readInt
25+ queries <- replicateM m readIntPair
26+ mapM_ (print . getAnswer prefixSums) queries
27+
28+ main = doMain
Original file line number Diff line number Diff line change 1+ 1330 : 1330.hs
2+ ghc -v0 -O 1330.hs
You can’t perform that action at this time.
0 commit comments