-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path010.swift
More file actions
32 lines (28 loc) · 686 Bytes
/
010.swift
File metadata and controls
32 lines (28 loc) · 686 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
func readInt() -> Int {
Int(readLine()!)!
}
func readIntArray() -> [Int] {
readLine()!.split(separator: " ").map { Int(String($0))! }
}
let n = readInt()
var class1Sum = [Int](repeating: 0, count: n + 1)
var class2Sum = [Int](repeating: 0, count: n + 1)
for i in 1...n {
let cp = readIntArray()
let c = cp[0]
let p = cp[1]
if c == 1 {
class1Sum[i] = class1Sum[i - 1] + p
class2Sum[i] = class2Sum[i - 1]
} else if c == 2 {
class1Sum[i] = class1Sum[i - 1]
class2Sum[i] = class2Sum[i - 1] + p
}
}
let q = readInt()
for _ in 0..<q {
let lr = readIntArray()
let l = lr[0]
let r = lr[1]
print("\(class1Sum[r] - class1Sum[l - 1]) \(class2Sum[r] - class2Sum[l - 1])")
}