提出 #16635944
ソースコード 拡げる
package main
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
)
var sc = bufio.NewScanner(os.Stdin)
func Scan() string {
sc.Scan()
return sc.Text()
}
func rScan() []rune {
return []rune(Scan())
}
func iScan() int {
n, _ := strconv.Atoi(Scan())
return n
}
func fScan() float64 {
n, _ := strconv.ParseFloat(Scan(), 64)
return n
}
func stringToInt(s string) int {
n, _ := strconv.Atoi(s)
return n
}
func SScan(n int) []string {
a := make([]string, n)
for i := 0; i < n; i++ {
a[i] = Scan()
}
return a
}
func iSScan(n int) []int {
a := make([]int, n)
for i := 0; i < n; i++ {
a[i] = iScan()
}
return a
}
func abs(x int) int {
if x < 0 {
x = -x
}
return x
}
func mod(x, d int) int {
x %= d
if x < 0 {
x += d
}
return x
}
func larger(a, b int) int {
if a < b {
return b
} else {
return a
}
}
func smaller(a, b int) int {
if a > b {
return b
} else {
return a
}
}
func max(a []int) int {
x := a[0]
for i := 0; i < len(a); i++ {
if x < a[i] {
x = a[i]
}
}
return x
}
func min(a []int) int {
x := a[0]
for i := 0; i < len(a); i++ {
if x > a[i] {
x = a[i]
}
}
return x
}
func sum(a []int) int {
x := 0
for _, v := range a {
x += v
}
return x
}
func fSum(a []float64) float64 {
x := 0.
for _, v := range a {
x += v
}
return x
}
func bPrint(f bool, x string, y string) {
if f {
fmt.Println(x)
} else {
fmt.Println(y)
}
}
func iSSPrint(x []int) {
fmt.Println(strings.Trim(fmt.Sprint(x), "[]"))
}
var lp1 int = 1000000007
var lp2 int = 998244353
func main() {
buf := make([]byte, 0)
sc.Buffer(buf, lp1)
sc.Split(bufio.ScanWords)
n, q := iScan(), iScan()
b := newBIT(n)
a := iSScan(n)
for i, v := range a {
b.add(i, v)
}
for i := 0; i < q; i++ {
t, l, r := iScan(), iScan(), iScan()
if t == 0 {
b.add(l, r)
} else {
fmt.Println(b.rangeSum(l, r))
}
}
}
type BIT struct {
v []int
}
func newBIT(n int) *BIT {
b := new(BIT)
b.v = make([]int, n)
return b
}
func (b BIT) sum(a int) int {
ret := 0
for i := a + 1; i > 0; i -= i & -i {
ret += b.v[i-1]
}
return ret
}
func (b BIT) rangeSum(x, y int) int {
if y == 0 {
return 0
}
y--
if x == 0 {
return b.sum(y)
} else {
return b.sum(y) - b.sum(x-1)
}
}
func (b BIT) add(a, w int) {
n := len(b.v)
for i := a + 1; i <= n; i += i & -i {
b.v[i-1] += w
}
}
提出情報
ジャッジ結果
| セット名 |
Sample |
All |
| 得点 / 配点 |
0 / 0 |
100 / 100 |
| 結果 |
|
|
| セット名 |
テストケース |
| Sample |
example_00 |
| All |
example_00, max_random_00, max_random_01, max_random_02, max_random_03, max_random_04, random_00, random_01, random_02, random_03, random_04, small_00, small_01, small_02, small_03, small_04, small_05, small_06, small_07, small_08, small_09 |
| ケース名 |
結果 |
実行時間 |
メモリ |
| example_00 |
AC |
3 ms |
1772 KiB |
| max_random_00 |
AC |
620 ms |
20904 KiB |
| max_random_01 |
AC |
625 ms |
20884 KiB |
| max_random_02 |
AC |
619 ms |
20892 KiB |
| max_random_03 |
AC |
620 ms |
20848 KiB |
| max_random_04 |
AC |
617 ms |
20888 KiB |
| random_00 |
AC |
502 ms |
15824 KiB |
| random_01 |
AC |
528 ms |
17980 KiB |
| random_02 |
AC |
411 ms |
7960 KiB |
| random_03 |
AC |
99 ms |
13048 KiB |
| random_04 |
AC |
155 ms |
9864 KiB |
| small_00 |
AC |
4 ms |
1776 KiB |
| small_01 |
AC |
3 ms |
1776 KiB |
| small_02 |
AC |
5 ms |
1760 KiB |
| small_03 |
AC |
3 ms |
1776 KiB |
| small_04 |
AC |
4 ms |
1760 KiB |
| small_05 |
AC |
3 ms |
1780 KiB |
| small_06 |
AC |
4 ms |
1780 KiB |
| small_07 |
AC |
4 ms |
1768 KiB |
| small_08 |
AC |
4 ms |
1780 KiB |
| small_09 |
AC |
5 ms |
1784 KiB |