Circuit 2

시간 제한2초메모리 제한2048 MB

요약
고정된 N개의 AND/OR 슬롯과 2N+1개의 스위치로 이루어진 회로에서 최대 1000번의 질의로 OR 소자가 놓인 슬롯을 모두 찾아낸다.
난이도

어려움10점 중 8점

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

문제

JOI-kun is playing with an electronic circuit set.

The electronic circuit set consists of NN AND components, NN OR components, and one circuit board. The circuit board is composed of 2N+12N + 1 switches and NN component slots, where each component slot can be used by placing either an AND component or an OR component. The circuit board outputs a value of 00 or 11, depending on the placed components and the states of the switches.

Specifications of the Circuit Board

  • Each switch is assigned a number from 00 to 2N2N, and each switch has an ON or OFF state. Each switch outputs a value of 00 or 11 as described below.

  • Each component slot is assigned a number from 00 to N−1N - 1. Each component slot also outputs a value of 00 or 11 as described below.

  • The output of each switch and each component slot is determined in order from the highest-numbered one to the lowest, according to the following rules. If a switch and a component slot share the same number, the component slot’s output is determined first.

    • For j=2N,2N−1,…,Nj = 2N, 2N - 1, \dots , N, the output of switch jj is determined as follows:

      • If switch jj is OFF, it outputs 00.
      • If switch jj is ON, it outputs 11.
    • For j=N−1,N−2,…,0j = N − 1, N − 2, \dots , 0, let the output of component slot jj be xx. The output of switch jj is determined as follows:

      • If switch jj is OFF, it outputs xx.
      • If switch jj is ON, it outputs 1−x1 − x.
    • For i=N−1,N−2,…,0i = N − 1, N − 2, \dots , 0, component slot ii is connected to two switches, U_iU\_i and V_iV\_i, where i<U_i<V_i≤2Ni < U\_i < V\_i ≤ 2N. Let the output of switch U_iU\_i be xx and the output of switch V_iV\_i be yy. The output of component slot ii is determined as follows:

      • If component slot ii has an AND component, it outputs min⁡(x,y)\min(x, y).
      • If component slot ii has an OR component, it outputs max⁡(x,y)\max(x, y).
  • For each j=1,2,…,2Nj = 1, 2, \dots , 2N, there exists exactly one ii (0≤i≤N−10 ≤ i ≤ N − 1) such that U_i=jU\_i = j or V_i=jV\_i = j.

  • The output of the circuit board is equal to the output of switch 00.

For example, when N=3N = 3, U_0=1U\_0 = 1, V_0=2V\_0 = 2, U_1=3U\_1 = 3, V_1=4V\_1 = 4, U_2=5U\_2 = 5, V_2=6V\_2 = 6, and AND components are placed in component slots 00 and 11 while an OR component is placed in component slot 22, the circuit board is represented as shown in the figure below.

Now, JOI-kun attempted to place AND components in all component slots. However, it turned out that up to RR OR components were accidentally mixed in. Since AND and OR components look identical, they must be distinguished using the circuit board. Your task is to identify which component slots contain OR components by asking at most 1,0001\\, 000 queries in the following format:

  • You can instruct JOI-kun on how to set the 2N+12N + 1 switches. JOI-kun will then configure the switches accordingly and report the circuit board’s output to you.

Given the connection structure of the circuit board and the upper bound on the number of OR components, write a program that determines the locations of all OR components using at most 1,0001\\, 000 queries.

제한

  • 1≤N≤8,0001 ≤ N ≤ 8\\, 000.
  • 1≤R≤min⁡(N,120)1 ≤ R ≤ \min(N, 120).
  • i<U_i<V_i≤2Ni < U\_i < V\_i ≤ 2N (0≤i≤N−10 ≤ i ≤ N − 1).
  • For each j=1,2,…,2Nj = 1, 2, \dots , 2N, there exists exactly one ii (0≤i≤N−10 ≤ i ≤ N − 1) such that U_i=jU\_i = j or V_i=jV\_i = j.

예제

이 문제는 공개된 예제가 없습니다.