bitset压位,因为是颜色数,直接倍增,重合部分不管,没了。
// powered by c++11
// by Isaunoya
#include
#define rep(i, x, y) for (register int i = (x); i <= (y); ++i)
#define Rep(i, x, y) for (register int i = (x); i >= (y); --i)
using namespace std;
using db = double;
using ll = long long;
using uint = unsigned int;
// #define int long long
using pii = pair;
#define ve vector
#define Tp template
#define all(v) v.begin(), v.end()
#define sz(v) ((int)v.size())
#define pb emplace_back
#define fir first
#define sec second
// the cmin && cmax
Tp void cmax(T& x, const T& y) {
if (x < y) x = y;
}
Tp void cmin(T& x, const T& y) {
if (x > y) x = y;
}
// sort , unique , reverse
Tp void sort(ve& v) { sort(all(v)); }
Tp void unique(ve& v) {
sort(all(v));
v.erase(unique(all(v)), v.end());
}
Tp void reverse(ve& v) { reverse(all(v)); }
const int SZ = 0x191981;
struct FILEIN {
~FILEIN() {}
char qwq[SZ], *S = qwq, *T = qwq, ch;
char GETC() { return (S == T) && (T = (S = qwq) + fread(qwq, 1, SZ, stdin), S == T) ? EOF : *S++; }
FILEIN& operator>>(char& c) {
while (isspace(c = GETC()))
;
return *this;
}
FILEIN& operator>>(string& s) {
while (isspace(ch = GETC()))
;
s = ch;
while (!isspace(ch = GETC())) s += ch;
return *this;
}
Tp void read(T& x) {
bool sign = 1;
while ((ch = GETC()) < 0x30)
if (ch == 0x2d) sign = 0;
x = (ch ^ 0x30);
while ((ch = GETC()) > 0x2f) x = x * 0xa + (ch ^ 0x30);
x = sign ? x : -x;
}
FILEIN& operator>>(int& x) { return read(x), *this; }
// FILEIN& operator>>(signed& x) { return read(x), *this; }
FILEIN& operator>>(unsigned& x) { return read(x), *this; }
} in;
struct FILEOUT {
const static int LIMIT = 0x114514;
char quq[SZ], ST[0x114];
signed sz, O;
~FILEOUT() { flush(); }
void flush() {
fwrite(quq, 1, O, stdout);
fflush(stdout);
O = 0;
}
FILEOUT& operator<<(char c) { return quq[O++] = c, *this; }
FILEOUT& operator<<(string str) {
if (O > LIMIT) flush();
for (char c : str) quq[O++] = c;
return *this;
}
Tp void write(T x) {
if (O > LIMIT) flush();
if (x < 0) {
quq[O++] = 0x2d;
x = -x;
}
do {
ST[++sz] = x % 0xa ^ 0x30;
x /= 0xa;
} while (x);
while (sz) quq[O++] = ST[sz--];
return;
}
FILEOUT& operator<<(int x) { return write(x), *this; }
// FILEOUT& operator<<(signed x) { return write(x), *this; }
FILEOUT& operator<<(unsigned x) { return write(x), *this; }
} out;
const int maxn = 1e5 + 51;
const int S = 1400, T = 73, K = 9;
int n, m, p, a[maxn], b[maxn], cnt;
struct Bitset {
uint s[maxn / 32 + 2];
void set(uint x) { s[x >> 5] |= 1u << (x & 31); }
int count() {
int ans = 0;
rep(i, 0, cnt) ans += __builtin_popcount(s[i]);
return ans;
}
void clear() { memset(s, 0, sizeof(s)); }
} f[T][K], ans, tmp;
Bitset operator|(Bitset a, Bitset b) {
rep(i, 0, cnt) tmp.s[i] = a.s[i] | b.s[i];
return tmp;
}
int lg[T], tot, L[T], R[T], lastans = -1;
inline int bl(int x) { return (x - 1) / S + 1; }
void qry(int l, int r) {
const int bL = bl(l), bR = bl(r);
if (bL + 1 > bR - 1) {
rep(i, l, r) ans.set(a[i]);
} else {
rep(i, l, R[bL]) ans.set(a[i]);
rep(i, L[bR], r) ans.set(a[i]);
int k = lg[(bR - 1) - (bL + 1) + 1];
ans = ans | f[(bL + 1)][k];
ans = ans | f[(bR - 1) - (1 << k) + 1][k];
}
}
signed main() {
#ifdef _WIN64
freopen("testdata.in", "r", stdin);
#else
ios_base ::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
#endif
// code begin.
in >> n >> m >> p;
rep(i, 1, n) in >> a[i], b[i] = a[i];
sort(b + 1, b + n + 1), cnt = unique(b + 1, b + n + 1) - b - 1;
rep(i, 1, n) a[i] = lower_bound(b + 1, b + cnt + 1, a[i]) - b - 1;
cnt = cnt - 1 >> 5, tot = bl(n);
rep(i, 1, tot) L[i] = R[i - 1] + 1, R[i] = i * S;
R[tot] = n;
rep(i, 1, tot) rep(j, L[i], R[i]) f[i][0].set(a[j]);
lg[1] = 0;
rep(i, 2, tot) lg[i] = lg[i >> 1] + 1;
rep(j, 1, lg[tot]) for (int i = 1; i + (1 << j) - 1 <= tot; i++) f[i][j] =
f[i][j - 1] | f[i + (1 << j - 1)][j - 1];
while (m--) {
ans.clear();
int k, l, r;
in >> k;
rep(i, 1, k) {
in >> l >> r;
if (p && lastans != -1) {
l = (l ^ lastans) % n + 1, r = (r ^ lastans) % n + 1;
if (l > r) l ^= r ^= l ^= r;
}
qry(l, r);
}
out << (lastans = ans.count()) << '\n';
}
return 0;
// code end.
}