CF1044D.Deduction Queries

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There is an array aa of 2302^{30} integers, indexed from 00 to 230−12^{30}-1. Initially, you know that 0≤ai<2300 \leq a_i \lt 2^{30} (0≤i<2300 \leq i \lt 2^{30}), but you do not know any of the values. Your task is to process queries of two types:

  • 1 l r x: You are informed that the bitwise xor of the subarray [l,r][l, r] (ends inclusive) is equal to xx. That is, al⊕al+1⊕…⊕ar−1⊕ar=xa_l \oplus a_{l+1} \oplus \ldots \oplus a_{r-1} \oplus a_r = x, where ⊕\oplus is the bitwise xor operator. In some cases, the received update contradicts past updates. In this case, you should ignore the contradicting update (the current update).
  • 2 l r: You are asked to output the bitwise xor of the subarray [l,r][l, r] (ends inclusive). If it is still impossible to know this value, considering all past updates, then output −1-1.

Note that the queries are encoded. That is, you need to write an online solution.

存在一个长度为 2302^{30} 的整数数组 aa,下标范围从 00 到 230−12^{30}-1。初始时,你知道对所有 ii(0≤i<2300 \leq i < 2^{30})均有 0≤ai<2300 \leq a_i < 2^{30},但你并不知道任何具体的 aia_i 值。你的任务是处理两类查询:

  • 1 l r x:你被告知子数组 [l,r][l, r](含端点)的按位异或值等于 xx。即 al⊕al+1⊕…⊕ar−1⊕ar=xa_l \oplus a_{l+1} \oplus \ldots \oplus a_{r-1} \oplus a_r = x,其中 ⊕\oplus 表示按位异或运算。在某些情况下,新收到的更新与之前已接收的更新矛盾。此时,你应忽略该矛盾的更新(即忽略当前这条更新)。
  • 2 l r:你需要输出子数组 [l,r][l, r](含端点)的按位异或值。如果根据所有已接收的更新仍无法确定该值,则输出 −1-1。

注意:这些查询是经过编码的,即你需要编写一个在线解法。

输入格式

The first line contains a single integer qq (1≤q≤2⋅1051 \leq q \leq 2 \cdot 10^5) — the number of queries.

Each of the next qq lines describes a query. It contains one integer tt (1≤t≤21 \leq t \leq 2) — the type of query.

The given queries will be encoded in the following way: let lastlast be the answer to the last query of the second type that you have answered (initially, last=0last = 0). If the last answer was −1-1, set last=1last = 1.

  • If t=1t = 1, three integers follow, l′l', r′r', and x′x' (0≤l′,r′,x′<2300 \leq l', r', x' \lt 2^{30}), meaning that you got an update. First, do the following:

    l=l′⊕lastl = l' \oplus last, r=r′⊕lastr = r' \oplus last, x=x′⊕lastx = x' \oplus last

    and, if l>rl \gt r, swap ll and rr.

    This means you got an update that the bitwise xor of the subarray [l,r][l, r] is equal to xx (notice that you need to ignore updates that contradict previous updates).

  • If t=2t = 2, two integers follow, l′l' and r′r' (0≤l′,r′<2300 \leq l', r' \lt 2^{30}), meaning that you got a query. First, do the following:

    l=l′⊕lastl = l' \oplus last, r=r′⊕lastr = r' \oplus last

    and, if l>rl \gt r, swap ll and rr.

    For the given query, you need to print the bitwise xor of the subarray [l,r][l, r]. If it is impossible to know, print −1-1. Don't forget to change the value of lastlast.

It is guaranteed there will be at least one query of the second type.

第一行包含一个整数 qq(1≤q≤2⋅1051 \leq q \leq 2 \cdot 10^5),表示查询的次数。

接下来的 qq 行,每行描述一个查询。每行包含一个整数 tt(1≤t≤21 \leq t \leq 2),表示查询类型。

这些查询将按如下方式编码:令 lastlast 表示你上一次回答的第二类查询的答案(初始时 last=0last = 0);若上一次答案为 −1-1,则令 last=1last = 1。

  • 若 t=1t = 1,其后跟着三个整数 l′l'、r′r' 和 x′x'(0≤l′,r′,x′<2300 \leq l', r', x' < 2^{30}),表示一次更新操作。首先执行以下步骤:

    l=l′⊕lastl = l' \oplus last, r=r′⊕lastr = r' \oplus last, x=x′⊕lastx = x' \oplus last

    若 l>rl > r,则交换 ll 和 rr。

    这意味着你收到一条更新信息:子数组 [l,r][l, r] 的按位异或值等于 xx(注意:需忽略与先前更新矛盾的更新)。

  • 若 t=2t = 2,其后跟着两个整数 l′l' 和 r′r'(0≤l′,r′<2300 \leq l', r' < 2^{30}),表示一次查询操作。首先执行以下步骤:

    l=l′⊕lastl = l' \oplus last, r=r′⊕lastr = r' \oplus last

    若 l>rl > r,则交换 ll 和 rr。

    对于该查询,你需要输出子数组 [l,r][l, r] 的按位异或值;若无法确定,输出 −1-1。别忘了更新 lastlast 的值。

保证至少存在一个第二类查询。

输出格式

After every query of the second type, output the bitwise xor of the given subarray or −1-1 if it is still impossible to know.

每次执行第二种类型的查询后,输出给定子数组的按位异或值;如果此时仍无法确定该值,则输出 −1-1。

输入输出样例

  • 输入#1

    12
    2 1 2
    2 1 1073741822
    1 0 3 4
    2 0 0
    2 3 3
    2 0 3
    1 6 7 3
    2 4 4
    1 0 2 1
    2 0 0
    2 4 4
    2 0 0

    输出#1

    -1
    -1
    -1
    -1
    5
    -1
    6
    3
    5
  • 输入#2

    4
    1 5 5 9
    1 6 6 5
    1 6 5 10
    2 6 5

    输出#2

    12

说明/提示

In the first example, the real queries (without being encoded) are:

  • 12

  • 2 1 2

  • 2 0 1073741823

  • 1 1 2 5

  • 2 1 1

  • 2 2 2

  • 2 1 2

  • 1 2 3 6

  • 2 1 1

  • 1 1 3 0

  • 2 1 1

  • 2 2 2

  • 2 3 3

  • The answers for the first two queries are −1-1 because we don't have any such information on the array initially.

  • The first update tells us a1⊕a2=5a_1 \oplus a_2 = 5. Note that we still can't be certain about the values a1a_1 or a2a_2 independently (for example, it could be that a1=1,a2=4a_1 = 1, a_2 = 4, and also a1=3,a2=6a_1 = 3, a_2 = 6).

  • After we receive all three updates, we have enough information to deduce a1,a2,a3a_1, a_2, a_3 independently.

In the second example, notice that after the first two updates we already know that a5⊕a6=12a_5 \oplus a_6 = 12, so the third update is contradicting, and we ignore it.

在第一个例子中,真实的查询(未编码)如下:

  • 12

  • 2 1 2

  • 2 0 1073741823

  • 1 1 2 5

  • 2 1 1

  • 2 2 2

  • 2 1 2

  • 1 2 3 6

  • 2 1 1

  • 1 1 3 0

  • 2 1 1

  • 2 2 2

  • 2 3 3

  • 前两个查询的答案为 −1-1,因为我们初始时对数组没有任何相关信息。

  • 第一个更新告诉我们 a1⊕a2=5a_1 \oplus a_2 = 5。注意,我们仍无法独立确定 a1a_1 或 a2a_2 的具体值(例如,可能有 a1=1,a2=4a_1 = 1, a_2 = 4,也可能有 a1=3,a2=6a_1 = 3, a_2 = 6)。

  • 在接收全部三个更新后,我们便拥有了足够信息,可独立推导出 a1,a2,a3a_1, a_2, a_3 的值。

在第二个例子中,请注意:前两个更新之后,我们已知 a5⊕a6=12a_5 \oplus a_6 = 12,因此第三个更新与此矛盾,将被忽略。

输入解题思路,AI测评打分。不知道怎么写?

首页