/ 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.02 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 3.16 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-11-11 03:08:18
Judged By
Score
0
Total Time
16ms
Peak Memory
3.16 MiB