• + 2 comments

    I have a question First I wrote this code which times out

    # Enter your code here. Read input from STDIN. Print output to STDOUT
    n,queries=map(int,input().strip().split())
    arr=list(map(int,input().strip().split()))
    #print(arr)
    for _ in range(queries):
        q,x,y=map(int,input().strip().split())
        if q==1:
            arr=arr[x-1:y]+arr[:x-1]+arr[y:]
        else:
            arr=arr[:x-1]+arr[y:]+arr[x-1:y]
    
    print(abs(arr[-1]-arr[0]))
    print(*arr)