#P6105. Online Set Operations and Maximum Modular Sum
Online Set Operations and Maximum Modular Sum
Online Set Operations and Maximum Modular Sum
You are given a constant \(C\) and need to maintain a set \(S\) supporting \(n\) operations. There are two types of operations:
- Operation 1: Given an integer \(x\), insert \(x\) into \(S\). It is guaranteed that \(x\) does not exist in \(S\) before insertion.
- Operation 2: Given an integer \(x\), delete \(x\) from \(S\). It is guaranteed that \(x\) exists in \(S\) prior to deletion.
After each operation, output the value
\[
\max_{\substack{i, j \in S\\ i \ne j}} \Bigl( (i+j) \bmod C \Bigr)
\]
which is the maximum value of \((i+j) \bmod C\) over all pairs of distinct elements \(i, j \in S\). If the set \(S\) has fewer than two elements, output EE
instead.
This problem is online: every given \(x\) in an operation is modified on the fly. Specifically, let last be the answer of the previous operation. For each operation, the effective parameter \(x'\) is computed as
\[
x' = x \oplus \text{last},
\]
where \(\oplus\) denotes bitwise XOR. If there is no previous answer or the previous output was EE
, then consider \(\text{last} = 0\).
inputFormat
The first line contains two integers \(n\) and \(C\) -- the number of operations and the constant \(C\), respectively.
Each of the next \(n\) lines contains two integers \(op\) and \(x\). If \(op = 1\), then perform an insertion; if \(op = 2\), perform a deletion. Note: the parameter \(x\) provided in the input must be XORed with the previous answer (or 0 if none or if the previous output was EE
) to obtain the effective value for the operation.
outputFormat
After each operation, output the maximum value of \((i+j) \bmod C\) over all pairs of distinct elements from \(S\). If \(S\) contains fewer than two elements, output EE
.
sample
5 10
1 3
1 6
1 9
2 10
2 0
EE
9
9
6
EE
</p>