Skip to content

Instantly share code, notes, and snippets.

@FujiHaruka FujiHaruka/a.go
Last active Feb 18, 2017

Embed
What would you like to do?
AtCoder Contest 053 by go lang
package main
import (
"fmt"
)
func main() {
var a int
var answer string
fmt.Scan(&a)
if a < 1200 {
answer = "ABC"
} else {
answer = "ARC"
}
fmt.Println(answer)
}
package main
import (
"fmt"
"strings"
)
func main() {
var s string
fmt.Scan(&s)
var aIndex = strings.Index(s, "A")
var zIndex = strings.LastIndex(s, "Z")
var answer = zIndex - aIndex + 1
fmt.Println(answer)
}
package main
import (
"fmt"
)
func main() {
var n int
fmt.Scan(&n)
var quotient = n / 11
var remainder = n % 11
var c int
switch {
case remainder == 0:
c = 0
case remainder <= 6:
c = 1
case remainder > 6:
c = 2
}
var answer = quotient*2 + c
fmt.Println(answer)
}
package main
import (
"fmt"
)
func main() {
var n int
fmt.Scan(&n)
a := make([]int, n)
for i := range a {
fmt.Scan(&a[i])
}
counter := make(map[int]int)
for _, v := range a {
counter[v]++
}
evenCount := 0
for _, v := range counter {
if v%2 == 0 {
evenCount++
}
}
answer := len(counter)
if evenCount%2 == 1 {
answer--
}
fmt.Println(answer)
}
package main
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
)
var sc = bufio.NewScanner(os.Stdin)
// Binary indexed tree
type BITree struct {
bit []int
M int
}
func newBITree(m int) *BITree {
b := new(BITree)
b.M = m
b.bit = make([]int, m + 1)
return b
}
func (b BITree) sum(i int) int {
if (i <= 0) {
return 0
}
return b.bit[i] + b.sum(i - (-i & i))
}
func (b BITree) add(i int, x int) {
if (i > b.M) {
return
}
b.bit[i] += x
b.add(i + (-i & i), x)
}
type Section struct {
start int
end int
}
func main() {
N, M, l, r := scan()
// 区間[l,r]を長さによって分類する
sectionsGroup := make([][]Section, M + 1)
for i := 0; i <= M; i++ {
sectionsGroup[i] = make([]Section, 0)
}
for n := 0; n < N; n++ {
length := r[n] - l[n] + 1
section := Section{
start: l[n],
end: r[n],
}
sectionsGroup[length] = append(sectionsGroup[length], section)
}
// 必ず通る区間たち
base := N
// Binary indexed tree
bit := newBITree(M+2)
answers := make([]int, M + 1)
// BIT使って頑張る
for d := 1; d <= M; d++ {
sections := sectionsGroup[d - 1]
for _, section := range sections {
start := section.start
end := section.end
bit.add(start, 1)
bit.add(end + 1, -1)
}
base -= len(sections)
answers[d] = base
for pos := 0; pos <= M; pos += d {
answers[d] += bit.sum(pos)
}
}
for d := 1; d <= M; d++ {
fmt.Println(answers[d])
}
}
func scan() (int, int, []int, []int) {
var N, M int
sc.Scan()
nm := strings.Split(sc.Text(), " ")
N, _ = strconv.Atoi(nm[0])
M, _ = strconv.Atoi(nm[1])
l := make([]int, N)
r := make([]int, N)
for i := 0; i < N; i++ {
sc.Scan()
lr := strings.Split(sc.Text(), " ")
l[i], _ = strconv.Atoi(lr[0])
r[i], _ = strconv.Atoi(lr[1])
}
return N, M, l, r
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.