아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

John and the Magic Box

시간 제한12초메모리 제한256 MB

요약
교환법칙과 결합법칙을 만족하는 미지의 연산이 주어질 때, 지정된 k개를 제외한 나머지 원소들의 조합을 q번의 질의마다 구하는 문제입니다.
난이도

보통10점 중 7점

유형
분할 정복, 구현
정답자
아직 제출이 없습니다

문제

This is an interactive problem.

John has an array of nn mysterious integers. He has an access to a magic box that can combine two integers into one. Let x∘yx \circ y be the result of combining two integers, xx and yy, with this magic box. After a lot of experiments, John has noticed that the magic box has the following properties:

  • x∘y=y∘xx \circ y = y \circ x
  • x∘(y∘z)=(x∘y)∘zx \circ (y \circ z) = (x \circ y) \circ z

John has qq cousins, and each of them likes all the integers in his array except some kk of them. John wants to give gifts to all his cousins, so he wants to give each cousin the combination of all his integers except the kk this cousin doesn't like.

John likes his cousins, but his magic box is old and worn off because of his intense experiments. He is willing to use the box at most 4(n+q+q⋅k)4 (n + q + q \cdot k) times. Help him get all the required combinations!

힌트

In each test, the rules for the magic box are fixed and don't depend on your queries. Different rules are used for different tests. It is guaranteed that the magic box satisfies the conditions from the problem statement.

In the sample test, the operation performed by the magic box is assumed to be bitwise OR.

예제1

  1. 예제 1

    입력
    3 3 1
    0 1 0
    
    1
    
    1
    
    
    2
    
    0
    
    
    3
    
    
    예상 출력
    
    
    next
    
    ? 1 0
    
    ! 1
    next
    
    ? 0 0
    
    ! 0
    next
    
    ! 1