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

11338번 - XOR Sum 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 256 MB38715313342.903%

문제

You will be given a list of Q (1 <= Q <= 100,000) instructions.

If the instructions is to "insert N", insert N into the list of numbers (there may be duplicates).

If the instruction is to "print" - print the XOR sum of the largest K (1<=K<=Q) elements in the list (or, if the list contains less than K elements, the XOR sum of all elements in the list).

XOR sum of a list of numbers is the result of XOR-ing all of them. XOR can be applied to two integers using the built in ^ operator in most languages (or xor in Haskell).

Note that XOR function has some useful properties, among them that if N^M=X then N=X^M and M=X^N.

입력

First line of the input contains an integer T (1 <= T <= 30) - the number of test cases. Each test case start with a line containing two integers Q and K (1 <= Q,K <= 100,000). Following are Q lines containing one instruction each.

Instructions are in either of the following two forms:

insert N

or

print

N is a non-negative integer less than 2^31.

출력

For each print statement output the sum of (at most) K largest elements in the current list. Note that the list is cleared between test cases.

제한

예제 입력 1

1
5 2
insert 1
insert 2
print
insert 3
print

예제 출력 1

3
1

힌트

출처

Contest > Calgary Collegiate Programming Contest > CCPC 2013 G번

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

출처

대학교 대회

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

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