Permutation and Queries
시간 제한10초메모리 제한2048 MB
순열에서 두 원소를 교환할 때마다 모든 쌍 i, j에 대한 |i j| * |p_i p_j|의 최솟값을 갱신해 출력한다.
문제
You are given a permutation of size . Calculate the value
You are also given queries. The -th query consists of two indices and . You should swap the elements at these positions (swap and ), and then recalculate the value . Note that the changes persist between queries: after -th query, there are swaps made.
A permutation of size is a sequence of distinct integers from to .
입력
The first line contains two integers: the permutation size () and the number of queries ().
The second line describes the permutation .
Each of the next lines describes a query. The -th of these lines contains two integers and (; ): the indices of elements you should swap.
출력
Print lines: the value before all queries and after each of the queries.