CF2170F.Build XOR on a Segment

省选/NOI-

通过率:0%

时间限制:5.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

You are given an array of nn integers a1,a2,…,ana_1, a_2, \dots, a_n, where all numbers are from 11 to 212−12^{12} - 1.

You have to process qq queries. Each query is defined by three integers li,ri,xil_i, r_i, x_i: you need to find the smallest set S=s1,s2,…,skS = {s_1, s_2, \dots, s_k} that satisfies the following conditions:

  • each sjs_j is equal to some element from the subarray from the lil_i-th position to the rir_i-th position inclusive;
  • s1⊕s2⊕⋯⊕sk=xis_1 \oplus s_2 \oplus \dots \oplus s_k = x_i, where ⊕\oplus denotes bitwise XOR.

给你一个包含 nn 个整数的数组 a1,a2,…,ana_1, a_2, \dots, a_n,其中所有数均在 11 到 212−12^{12} - 1 之间。

你需要处理 qq 个查询。每个查询由三个整数 li,ri,xil_i, r_i, x_i 定义:你需要找出满足以下条件的最小集合 S={s1,s2,…,sk}S = \{s_1, s_2, \dots, s_k\}:

  • 每个 sjs_j 等于子数组(从第 lil_i 个位置到第 rir_i 个位置,含端点)中的某个元素;
  • s1⊕s2⊕⋯⊕sk=xis_1 \oplus s_2 \oplus \dots \oplus s_k = x_i,其中 ⊕\oplus 表示按位异或运算。

输入格式

The first line contains one integer nn (2≤n≤1042 \le n \le 10^4).

The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤212−11 \le a_i \le 2^{12} - 1).

The third line contains one integer qq (1≤q≤1061 \le q \le 10^6).

Then qq lines follow. The ii-th of them contains three integers li,ri,xil_i, r_i, x_i (1≤li≤ri≤n1 \le l_i \le r_i \le n; 1≤xi≤212−11 \le x_i \le 2^{12} - 1).

第一行包含一个整数 nn(2≤n≤1042 \le n \le 10^4)。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤212−11 \le a_i \le 2^{12} - 1)。

第三行包含一个整数 qq(1≤q≤1061 \le q \le 10^6)。

接下来是 qq 行。其中第 ii 行包含三个整数 li,ri,xil_i, r_i, x_i(1≤li≤ri≤n1 \le l_i \le r_i \le n;1≤xi≤212−11 \le x_i \le 2^{12} - 1)。

输出格式

For each query, print one integer — the minimum size of the required set. If such a set does not exist, print 00.

对于每个查询,输出一个整数——所需集合的最小大小。如果这样的集合不存在,则输出 00。

输入输出样例

  • 输入#1

    7
    3 5 4 1 7 3 1
    5
    1 3 1
    1 4 1
    1 3 2
    4 7 5
    1 7 8

    输出#1

    2 1 3 3 0

说明/提示

Consider the queries from the example:

  • in the first query, you can choose S=5,4S = {5, 4};
  • in the second query, you can choose S=1S = {1};
  • in the third query, you can choose S=4,3,5S = {4, 3, 5};
  • in the fourth query, you can choose S=1,3,7S = {1, 3, 7}.

考虑示例中的查询:

  • 在第一个查询中,你可以选择 S=5,4S = {5, 4};
  • 在第二个查询中,你可以选择 S=1S = {1};
  • 在第三个查询中,你可以选择 S=4,3,5S = {4, 3, 5};
  • 在第四个查询中,你可以选择 S=1,3,7S = {1, 3, 7}。

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

首页