Logo
(追記) (追記ここまで)

20345번 - XOR Sort 서브태스크스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 512 MB80111017.857%

문제

You are given an integer S and an array A consisting of N non-negative integers, indexed from 1. You are allowed to perform the following operation on it: choose any index i (1 ≤ i ≤ N), choose one of its neighbors j (1 ≤ j ≤ N, either j = i − 1 or j = i + 1) and replace Ai with (Ai ⊕ Aj) where ⊕ is the bitwise XOR operation.

You can see the definition of XOR at the end of the statement.

Your goal is to transform A into a sorted array:

  • If S = 1 then the final array must be strictly increasing, i.e. Ai < Ai+1 for 1 ≤ i < N
  • If S = 2 then the final array must be non-decreasing, i.e. Ai ≤ Ai+1 for 1 ≤ i < N

Find any sequence of operations that achieves your goal.

You aren’t required to minimize the number of operations as long as their amount doesn’t exceed 40000.

입력

First line contains two integers: N and S

Next line contains N integers: elements of A

출력

First line of output should contain one integer K (0 ≤ K ≤ 40000) - the number of operations.

Next K lines should contain two integers each, describing operations in chronological order: the first integer is an index i of the element which is being replaced and the second one is an index j of another element involved in the operation.

제한

  • 1 ≤ S ≤ 2
  • 2 ≤ N ≤ 1000
  • 0 ≤ Ai < 220

서브태스크

번호배점제한
125

2 ≤ N ≤ 150, S = 1, All elements of A are distinct

235

2 ≤ N ≤ 200, S = 1, All elements of A are distinct

340

2 ≤ N ≤ 1000, S = 2

예제 입력 1

5 1
3 2 8 4 1

예제 출력 1

3
1 2
4 3
5 4

예제 입력 2

5 2
4 4 2 0 1

예제 출력 2

3
3 2
4 3
5 4

힌트

First example output explanation: [3, 2, 8, 4, 1] -> [1, 2, 8, 4, 1] -> [1, 2, 8, 12, 1] -> [1, 2, 8, 12, 13]

Second example output explanation: [4, 4, 2, 0, 1] -> [4, 4, 6, 0, 1] -> [4, 4, 6, 6, 1] -> [4, 4, 6, 6, 7]

When performing XOR operation between a and b bits the result will be 0 if a=b and 1 otherwise.

When performing bitwise XOR operation between integers a and b, XOR results will be carried out for each of the corresponding bits:

  • 75 ⊕ 29 = 10010112 ⊕ 00111012 = 10101102 = 86

In C/C++/Java you can use the "^" operator to perform XOR.

출처

Olympiad > European Junior Olympiad in Informatics > eJOI 2020 D번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /