Compile Error
foo.cc:9:33: error: stray '#' in program 9 | res[i] = len(os) - pos # strictly greater | ^ foo.cc:19:23: error: stray '#' in program 19 | res[i] = pos # strictly smaller | ^ foo.cc:1:1: error: 'import' does not name a type 1 | import bisect | ^~~~~~ foo.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
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
- C++17 (G++ 13.2.0)
- Submit At
- 2025-03-23 21:25:40
- Judged At
- 2025-03-23 21:25:40
- Judged By
- Score
- 0
- Total Time
- 0ms
- Peak Memory
- 0 Bytes