/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 15ms 3.109 MiB
#2 Accepted 15ms 3.168 MiB
#3 Accepted 15ms 3.047 MiB
#4 Accepted 14ms 2.902 MiB
#5 Accepted 15ms 3.148 MiB
#6 Accepted 14ms 3.109 MiB
#7 Accepted 15ms 3.133 MiB
#8 Accepted 15ms 3.141 MiB
#9 Wrong Answer 15ms 3.129 MiB
#10 Accepted 17ms 3.102 MiB
#11 Accepted 21ms 3.066 MiB
#12 Accepted 14ms 3.074 MiB
#13 Accepted 14ms 2.902 MiB
#14 Wrong Answer 15ms 3.035 MiB

Code

import bisect

def countGreaterRight(arr):
    n = len(arr)
    res = [0] * n
    os = []
    for i in range(n - 1, -1, -1):
        pos = bisect.bisect_right(os, arr[i])
        res[i] = len(os) - pos  # strictly greater
        bisect.insort(os, arr[i])
    return res

def countSmallerLeft(arr):
    n = len(arr)
    res = [0] * n
    os = []
    for i in range(n):
        pos = bisect.bisect_left(os, arr[i] + 1)
        res[i] = pos  # strictly smaller
        bisect.insort(os, arr[i])
    return res

def main():
    n = int(input())
    v = list(map(int, input().split()))
    assert all(x < n for x in v)

    greaterRight = countGreaterRight(v)
    smallerLeft = countSmallerLeft(v)

    specialCount = 0
    for i in range(n):
        if greaterRight[i] >= v[i] or smallerLeft[i] >= v[i]:
            specialCount += 1

    print(specialCount)

if __name__ == "__main__":
    main()

Information

Submit By
Type
Submission
Problem
P1184 The Curious Kid and the Number Game
Language
Python 3 (Python 3.12.3)
Submit At
2025-03-23 21:26:06
Judged At
2025-03-23 21:26:06
Judged By
Score
12
Total Time
21ms
Peak Memory
3.168 MiB