Harumachi Kaze

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

요약
숨겨진 순열 아래에서 add와 cmp 질의만으로 두 배열 누적합을 합친 k번째 값을 찾고, 배열 원소 갱신까지 처리한다.
난이도

어려움10점 중 10점

유형
이분 탐색, 비트 연산, 구현, 수학
정답자
아직 제출이 없습니다

문제

This is an interactive problem.

You are given two arrays aa and bb of length nn, consisting of non-negative integers.

There is a hidden permutation of integers from 00 to 264−12^{64}-1: p(0),p(1),…,p(264−1)p(0), p(1), \ldots, p(2^{64} - 1). You only know that p(0)=0p(0) = 0.

Since pp is a permutation, p−1p^{-1} can also be defined: p−1(x)=yp^{-1}(x) = y when p(y)=xp(y) = x.

Also, you are given an integer BB. A positive integer xx is called cute if and only if the two following conditions hold:

  • The binary representation of xx, when viewed as a string of length BB, is a palindrome.
  • If a bit in the binary representation of xx is 11, this bit must either be in the first 66 bits or in the last 66 bits. For example, if B=14B = 14, the two bits in the center must both be 00.

You have to support queries of two types.

The first type of query is to change an element in one of the arrays.

The second type of query is to answer the following question: if we list 2n2n integers, p(a_1)p(a\_1), p(a_1)+p(a_2)p(a\_1)+p(a\_2), …\ldots, p(a_1)+p(a_2)+…+p(a_n)p(a\_1)+p(a\_2)+\ldots+p(a\_n) and p(b_1)p(b\_1), p(b_1)+p(b_2)p(b\_1)+p(b\_2), …\ldots, p(b_1)+p(b_2)+…+p(b_n)p(b\_1)+p(b\_2)+\ldots+p(b\_n), and sort them into c_1,c_2,…,c_2nc\_1, c\_2, \ldots, c\_{2n}, what would p−1(c_k)p^{-1}(c\_k) be? It is guaranteed that kk is a cute number.

There are two interaction functions for you to call.

  • add(x,y)\mathrm{add}(x, y): returns p−1(p(x)+p(y))p^{-1}(p(x) + p(y)).
  • cmp(x,y)\mathrm{cmp}(x, y): returns p−1(min⁡(p(x),p(y)))p^{-1}(\min(p(x), p(y))).

Please beware that it is invalid to ask add(x,y)\mathrm{add}(x, y) if p(x)+p(y)≥264p(x) + p(y) \geq 2^{64}.

To help you refrain from making invalid calls, it is guaranteed that, at any moment, the following condition holds: max⁡(p(a_1)+p(a_2)+…+p(a_n),p(b_1)+p(b_2)+…+p(b_n))<264\max(p(a\_1)+p(a\_2)+\ldots+p(a\_n), p(b\_1)+p(b\_2)+\ldots+p(b\_n)) < 2^{64}.

입력

You begin the interaction by reading three integers: nn, qq, BB (1≤n≤1.6⋅1041 \leq n \leq 1.6 \cdot 10^4; 1≤q≤2⋅1041 \leq q \leq 2 \cdot 10^4; 1≤B≤161 \leq B \leq 16).

Then, you should read two lines, the first containing the array a_1,a_2,…,a_na\_1, a\_2, \ldots, a\_n (0≤a_i<2640 \leq a\_i < 2^{64}), and the second containing the array b_1,b_2,…,b_nb\_1, b\_2, \ldots, b\_n (0≤b_i<2640 \leq b\_i < 2^{64}).

After that, you should read the contents of the qq queries.

For the next qq lines, the first integer type\mathit{type} indicates the type of query (1≤type≤21 \leq \mathit{type} \leq 2).

  • If type=1\mathit{type} = 1, three integers follow: tt, pos\mathit{pos}, xx (1≤t≤21 \leq t \leq 2; 1≤pos≤n1 \leq pos \leq n; 0≤x<2640 \leq x < 2^{64}).

    • If t=1t = 1, set a_pos=xa\_{\mathit{pos}} = x.
    • If t=2t = 2, set b_pos=xb\_{\mathit{pos}} = x.
  • If type=2\mathit{type} = 2, one integer kk follows (1≤k≤min⁡(2B−1,2⋅n)1 \leq k \leq \min(2^B - 1, 2 \cdot n)). It is guaranteed that kk is a cute number.

It is guaranteed that there is at least 11 and at most 50005000 queries of type 11.

예제1

  1. 예제 1

    입력
    2 3 2
    1 3
    5 7
    2 3
    1 2 2 9
    2 3
    
    4
    
    12
    
    12
    
    14
    
    4
    
    
    
    예상 출력
    
    
    
    
    
    A 1 3
    
    A 5 7
    
    C 4 12
    
    A 5 9
    
    C 4 14
    
    ! 2
    12 4