Skip to content

Commit 6b0b89a

Browse files
author
Den Raskovalov
committed
1330 AC
1 parent a129e0e commit 6b0b89a

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

1330/1330.hs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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

1330/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
1330: 1330.hs
2+
ghc -v0 -O 1330.hs

0 commit comments

Comments
 (0)