南昌邀请赛ICPC H.Another Sequence

给两个数组,生成其两两或的数组。(从大到小排序)。然后操作查询和区间开方。

$FWT$一下,然后由于生成数组长度太长,但是我们只需要对$q$组操作,对操作离散化下,保留下需要操作的值和区间。就没了。

代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int, int>
#define mk make_pair
const int N = 1 << 17;
const int mod = 998244353;

int read()
{
int x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9')
{
if (c == '-')
f = -1;
c = getchar();
}
while (c >= '0' && c <= '9')
x = (x << 1) + (x << 3) + c - '0', c = getchar();
return x * f;
}
int qpow(int a, int x, int mo)
{
int res = 1;
while (x)
{
if (x & 1)
res = 1ll * res * a % mo;
x >>= 1;
a = 1ll * a * a % mo;
}
return res;
}
int inc(int x, int y, int mo)
{
if (y < 0)
y += mo;
if (x + y >= mo)
x -= mo;
return x + y;
}

const int SEN = 4e5 + 10;
struct segmentTree
{
int sum[SEN << 2], lazy[SEN << 2];
void addtag(int pos, int l, int r, int w)
{
lazy[pos] += w;
sum[pos] += w * (r - l + 1);
}
void pushdown(int pos, int l, int r)
{
if (lazy[pos])
{
int w = lazy[pos];
int mid = (l + r) >> 1;
addtag(pos << 1, l, mid, w);
addtag(pos << 1 | 1, mid + 1, r, w);
lazy[pos] = 0;
}
}
void pushup(int pos)
{
sum[pos] = sum[pos << 1 | 1] + sum[pos << 1];
}
int query(int ql, int qr, int pos, int l, int r)
{
if (ql <= l && r <= qr)
{
return sum[pos];
}
pushdown(pos, l, r);
int mid = (l + r) >> 1;
int ans = 0;
if (ql <= mid)
ans += query(ql, qr, pos << 1, l, mid);
if (qr > mid)
ans += query(ql, qr, pos << 1 | 1, mid + 1, r);
return ans;
}
void update(int ql, int qr, int w, int pos, int l, int r)
{
if (ql <= l && r <= qr)
{
addtag(pos, l, r, w);
return;
}
pushdown(pos, l, r);
int mid = (l + r) >> 1;

if (ql <= mid)
update(ql, qr, w, pos << 1, l, mid);
if (qr > mid)
update(ql, qr, w, pos << 1 | 1, mid + 1, r);
pushup(pos);
}
} T;
int Inv2;
void FWT(int *A, int n, int op, int t) //t=1 or t=2 and t=3 xor
{
for (int i = 2; i <= n; i <<= 1)
{
for (int j = 0, mid = i >> 1; j < n; j += i)
for (int k = 0; k < mid; k++)
{

if (t == 1)
A[j + mid + k] = inc(A[j + mid + k], A[j + k] * op, mod);
else if (t == 2)
A[j + k] = inc(A[j + k], A[j + mid + k] * op, mod);
else if (t == 3)
{
int x = A[j + k], y = A[j + mid + k];
if (op == 1)
A[j + k] = (x + y) % mod, A[j + mid + k] = (x - y + mod) % mod;
else
A[j + k] = 1ll * Inv2 * (x + y) % mod, A[j + mid + k] = 1ll * Inv2 * (x - y + mod) % mod;
}
}
}
}
void FWTX(int *A, int *B, int n, int t)
{
Inv2 = qpow(2, mod - 2, mod);
FWT(A, n, 1, t), FWT(B, n, 1, t);

for (int i = 0; i < n; ++i)
A[i] = 1ll * A[i] * B[i] % mod;
FWT(A, n, -1, t);
}

int f[N], g[N];
struct node
{
ll l, r;
} q[N];
ll li[N];
int a[N];
ll sum[N];
int cnt = 0;
int main()
{
int n = read();

for (int i = 1; i <= n; i++)
{
int x = read();
f[x]++;
}
for (int i = 1; i <= n; i++)
{
int x = read();
g[x]++;
}
FWTX(f, g, 1 << 17, 1);
sum[0] = f[0];
for (int i = 1; i < (1 << 17); i++)
{

sum[i] = sum[i - 1] + f[i];
}

int m = read();
for (int i = 1; i <= m; i++)
{
q[i].l = read(), q[i].r = read();
if (q[i].l != 0)
li[++cnt] = (q[i].l);
li[++cnt] = (q[i].r);
}
sort(1 + li, 1 + li + cnt);
cnt = unique(li + 1, li + 1 + cnt) - li - 1;
for (int i = 1; i <= m; i++)
{
if (q[i].l == 0)
{
int r = lower_bound(1 + li, 1 + li + cnt, q[i].r) - li;
a[r] = lower_bound(sum, sum + (1 << 17), q[i].r) - sum;
q[i].r = r;
}
else
{
q[i].l = lower_bound(1 + li, 1 + li + cnt, q[i].l) - li;
q[i].r = lower_bound(1 + li, 1 + li + cnt, q[i].r) - li;
}
}
for (int i = 1; i <= m; i++)
{
if (q[i].l == 0)
{
int p = T.query(q[i].r, q[i].r, 1, 1, cnt);
int res = a[q[i].r];
for (int j = 1; j <= p; j++)
{
res = sqrt(res);
if (res == 1)
break;
}
printf("%d\n", res);
}
else
{
T.update(q[i].l, q[i].r, 1, 1, 1, cnt);
}
}
}