#P8337. [Ynoi2004] rsxc

[Ynoi2004] rsxc

Problem Description

You are given a non-negative integer sequence a0,a1,,an1a_0, a_1, \dots, a_{n-1} of length nn (1n6×1051 \le n \le 6 \times 10^5), where 0ai<2300 \le a_i < 2^{30}.

There are qq queries (1q1061 \le q \le 10^6).

Each query gives two integers l,rl, r (0lr<n0 \le l \le r < n). Find how many pairs of integers (x,y)(x, y) satisfy:

  • lxyrl \le x \le y \le r;
  • i,jS:ijS\forall i, j \in S: i \oplus j \in S, where S:={ak}k=xyS := \{a_k\}_{k=x}^y.

Input Format

Since the amount of data is large, you do not need to do input/output. Please complete the init(int, int, vector<int>) and solve(int, int) functions in the following program and submit it. The correct solution does not depend on the template.

#include <bits/stdc++.h>
using namespace std;

void init(int n, int q, vector<int> a) {
  // implement...
}

long long solve(int l, int r) {
  // implement...
}

int main() {
  int n, q;
  uint64_t s;
  cin >> n >> q >> s;
  string r;
  cin >> r;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    for (int s = 5 * i; s < 5 * i + 5; s++)
      a[i] = (a[i] * 64 + (int)(r[s]) - (int)('0'));
  init(n, q, a);
  uint64_t state = 0;
  auto splitmix64 = [&](uint64_t v) {
    uint64_t z = (v + 0x9e3779b97f4a7c15);
    z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9;
    z = (z ^ (z >> 27)) * 0x94d049bb133111eb;
    return z ^ (z >> 31);
  };
  mt19937_64 rng(s);
  for (int i = 0; i < q; i++) {
    int l = (rng() ^ state) % n;
    int r = (rng() ^ state) % n;
    long long ans = solve(min(l, r), max(l, r));
    state = splitmix64(state + ans);
    if ((i + 1) % (1 << 15) == 0)
      cout << state << endl;
  }
  cout << state << endl;
}
5 10 2
0000000001000020000300004
4834712607666044912
20 100 16500242824326557842
0000500006000070000800000000010000200003000040000000001000020000300004000090000:0000;0000<0000=0000>
5449866856465492064

Hint

Idea: Powerless. Solution: ccz181078 & nzhtl1477 & w33z. Code: w33z. Data: w33z.

For 100%100\% of the testdata, 1n6×1051 \le n \le 6 \times 10^5, 1q1061 \le q \le 10^6, 0ai<2300 \le a_i < 2^{30}, and 0lr<n0 \le l \le r < n.

Translated by ChatGPT 5