시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 256 MB 23 3 2 40.000%

문제

길이 N의 배열 A와 정수 M이 있고. 지학이는 다음과 같은 프로그램을 짰다.

for i<-1 to M do 
    for j<-i+1 to N do  
        if A[i]>A[j] then 
            swap(A[i],A[j])

지학이는 이 프로그램에서 swap 함수가 몇번 작동되는지 궁금해서 여러분을 찾았다. 몇번 작동하는가?

입력

입력은 여러 개의 테스트 케이스로 이루어져 있다. 각 테스트 케이스에는 다음과 같은 정보들이 주어진다.

첫번째 줄에 자연수 N, M이 주어진다. (N, M < 105)

두번째 줄에 배열 A의 원소가 주어진다. (-109 ≤ Ai ≤ 109)

출력

각 테스트 케이스마다 교환 횟수를 한 줄에 출력하라.

예제 입력 1

3 3
2 1 3
4 1
3 2 -1 -10

예제 출력 1

1
3

힌트

W3sicHJvYmxlbV9pZCI6IjExMDI3IiwicHJvYmxlbV9sYW5nIjoiMCIsInRpdGxlIjoiXHVhZDUwXHVkNjU4IiwiZGVzY3JpcHRpb24iOiI8cD5cdWFlMzhcdWM3NzQgTlx1Yzc1OCBcdWJjMzBcdWM1ZjQgQVx1YzY0MCBcdWM4MTVcdWMyMTggTVx1Yzc3NCBcdWM3ODhcdWFjZTAuIFx1YzljMFx1ZDU1OVx1Yzc3NFx1YjI5NCBcdWIyZTRcdWM3NGNcdWFjZmMgXHVhYzE5XHVjNzQwIFx1ZDUwNFx1Yjg1Y1x1YWRmOFx1YjdhOFx1Yzc0NCBcdWM5ZjBcdWIyZTQuPFwvcD5cclxuXHJcbjxwcmU+XHJcbmZvciBpJmx0Oy0xIHRvIE0gZG8gXHJcbiAgICBmb3IgaiZsdDstaSsxIHRvIE4gZG8gIFxyXG4gICAgICAgIGlmIEFbaV0mZ3Q7QVtqXSB0aGVuIFxyXG4gICAgICAgICAgICBzd2FwKEFbaV0sQVtqXSlcclxuPFwvcHJlPlxyXG5cclxuPHA+XHVjOWMwXHVkNTU5XHVjNzc0XHViMjk0IFx1Yzc3N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