Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "bufio"
- . "fmt"
- "io"
- "os"
- )
- func Solve(_in io.Reader, _out io.Writer) {
- in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
- defer out.Flush()
- var t, n int
- for Fscan(in, &t); t > 0; t-- {
- Fscan(in, &n)
- if n == 1 {
- Fprintln(out, 0)
- continue
- }
- a := make([]int, n)
- // 统计 a[i] 最早出现位置
- mp := map[int]int{}
- cnt := make([]int, n)
- for i := range a {
- Fscan(in, &a[i])
- cnt[i] = len(mp)
- if _, ok := mp[a[i]]; !ok {
- mp[a[i]] = i
- }
- }
- j := n-1
- for ; j >= 0; j-- {
- if j >= 1 && a[j] == a[j-1] {
- continue
- }
- if i, ok := mp[a[j]]; ok && i < j {
- break
- }
- if j >= 1 && a[j] < a[j-1] {
- break
- }
- }
- if j >= 0 {
- Fprintln(out, cnt[j])
- } else {
- Fprintln(out, 0)
- }
- }
- }
- func main() { Solve(os.Stdin, os.Stdout) }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement