Submission #66617280
Source Code Expand
package main
import (
"bufio"
"fmt"
"os"
"sort"
"strconv"
"strings"
)
func insertSorted(cards *[]int, x int) {
idx := sort.Search(len(*cards), func(i int) bool {
return (*cards)[i] >= x
})
if idx == len(*cards) || (*cards)[idx] != x {
*cards = append(*cards, 0)
copy((*cards)[idx+1:], (*cards)[idx:])
(*cards)[idx] = x
}
}
func deleteSorted(cards *[]int, x int) {
idx := sort.Search(len(*cards), func(i int) bool {
return (*cards)[i] >= x
})
if idx < len(*cards) && (*cards)[idx] == x {
*cards = append((*cards)[:idx], (*cards)[idx+1:]...)
}
}
func lowerBound(cards []int, x int) int {
idx := sort.Search(len(cards), func(i int) bool {
return cards[i] >= x
})
if idx < len(cards) {
return cards[idx]
}
return -1
}
func main() {
scanner := bufio.NewScanner(os.Stdin)
scanner.Scan()
Q, _ := strconv.Atoi(scanner.Text())
cards := []int{}
output := []string{}
for i := 0; i < Q; i++ {
scanner.Scan()
parts := strings.Split(scanner.Text(), " ")
t, _ := strconv.Atoi(parts[0])
x, _ := strconv.Atoi(parts[1])
switch t {
case 1:
insertSorted(&cards, x)
case 2:
deleteSorted(&cards, x)
case 3:
res := lowerBound(cards, x)
output = append(output, strconv.Itoa(res))
}
}
fmt.Println(strings.Join(output, "\n"))
}
Submission Info
| Submission Time | |
|---|---|
| Task | A55 - Set |
| User | myoshizumi |
| Language | Go (go 1.20.6) |
| Score | 1000 |
| Code Size | 1352 Byte |
| Status | AC |
| Exec Time | 333 ms |
| Memory | 7464 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 1000 / 1000 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | sample_01 |
| All | max_01, random_01, random_02, random_03, random_04, random_05, sample_01 |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| max_01 | AC | 333 ms | 7016 KiB |
| random_01 | AC | 1 ms | 1576 KiB |
| random_02 | AC | 1 ms | 1588 KiB |
| random_03 | AC | 1 ms | 1696 KiB |
| random_04 | AC | 3 ms | 2432 KiB |
| random_05 | AC | 43 ms | 7464 KiB |
| sample_01 | AC | 1 ms | 1628 KiB |