/ SeriousOJ /

Record Detail

Runtime Error


  
# Status Time Cost Memory Cost
#1 Runtime Error Traceback (most recent call last): File "foo.py", line 28, in <module> ValueError: invalid literal for int() with base 10: '5 3 1 2 4\r\n' 15ms 3.258 MiB
#2 Runtime Error Traceback (most recent call last): File "foo.py", line 28, in <module> ValueError: invalid literal for int() with base 10: '1 2 3 4 5 6 7 8 9 10 \r\n' 16ms 2.93 MiB
#3 Runtime Error Traceback (most recent call last): File "foo.py", line 28, in <module> ValueError: invalid literal for int() with base 10: '1000 999 998 997 996 995 994 993 992 991 990 989 988 987 986 985 984 983 982 981 980 979 978 977 976 975 974 973 972 971 970 969 968 967 966 965 964 963 962 961 960 959 958 957 956 955 954 953 952 95 16ms 3.152 MiB
#4 Runtime Error Traceback (most recent call last): File "foo.py", line 28, in <module> ValueError: invalid literal for int() with base 10: '1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 7 16ms 3.051 MiB
#5 Runtime Error Traceback (most recent call last): File "foo.py", line 28, in <module> ValueError: invalid literal for int() with base 10: '1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 7 20ms 4.742 MiB
#6 Runtime Error Traceback (most recent call last): File "foo.py", line 28, in <module> ValueError: invalid literal for int() with base 10: '1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 7 20ms 4.613 MiB

Code

import sys
from bisect import insort_right, bisect_left

MOD = 1000000007
INF = (10**15) + 5
EPS = 1e-6
N = 200001

def solve():
    n = int(input())
    arr = [(x, i) for i, x in enumerate([int(input()) for _ in range(n)], start=1)]
    arr.sort(key=lambda x: (-x[0], x[1]))  # Sort by value in descending order, then by index

    q = int(input())
    for _ in range(q):
        x = int(input())
        pos = bisect_left(arr, (x, 0))  # Find the insertion point for the new element
        if pos < len(arr):  # Check if we're not inserting at the end
            idx = arr[pos][1]  # Index of the element being replaced
            print(idx)
            del arr[pos]  # Remove the smallest element
            insort_right(arr, (x, idx))  # Insert the new element at the correct position
        else:
            print("No smaller element found")

if __name__ == "__main__":
    sys.stdin.readline()  # Skip the first line of input
    T = int(sys.stdin.readline())
    for _ in range(T):
        solve()

Information

Submit By
Type
Submission
Problem
P1086 KuZ the Position
Language
Python 3 (Python 3.12.3)
Submit At
2024-08-17 15:23:27
Judged At
2024-10-03 13:17:07
Judged By
Score
0
Total Time
20ms
Peak Memory
4.742 MiB