题解 P3674 小清新人渣的本愿

题面
首先莫队,必定的
第一,第二两种操作维护两个$bitset$,然后位移后求个交就好了
第三种操作。。。直接暴力枚举因数就好了。。。
$O(n\sqrt m+\frac{mc}{\omega}+m\sqrt c)$

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
#include <bits/stdc++.h>
using namespace std;
const int c = 100000;
typedef bitset<100010> bs;
bs now1, now2;
int nowl = 1, nowr = 0;
int ans[100010];
int qid[100010], n, m;
struct query {
int l, r, id, opt, x;
friend inline int operator < (const query &a, const query &b) {
return qid[a.l] == qid[b.l] ? qid[a.l] & 1 ? a.r < b.r : a.r > b.r : a.l < b.l;
}
} q[100010];
int a[100010], buc[100010];
inline void add(int x) {
buc[x]++;
now1[x] = 1;
now2[c - x] = 1;
}
inline void del(int x) {
buc[x]--;
if(buc[x] == 0) now1[x] = 0, now2[c - x] = 0;
}
int main() {
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; i++) scanf("%d", a + i);
for(int i = 1; i <= m; i++) {
scanf("%d%d%d%d", &q[i].opt, &q[i].l, &q[i].r, &q[i].x);
q[i].id = i;
}
int qs = sqrt(c);
for(int i = 1; i <= n; i++) qid[i] = (i - 1) / qs;
sort(q + 1, q + 1 + m);
for(int i = 1; i <= m; i++) {
while(nowl > q[i].l) add(a[--nowl]);
while(nowr < q[i].r) add(a[++nowr]);
while(nowl < q[i].l) del(a[nowl++]);
while(nowr > q[i].r) del(a[nowr--]);
if(q[i].opt == 1) ans[q[i].id] = (now1 & (now1 << q[i].x)).any();
else if(q[i].opt == 2) ans[q[i].id] = ((now1 << (c - q[i].x)) & now2).any();
else
for(int j = 1; j * j <= q[i].x; j++)
if(q[i].x % j == 0 && now1[j] && now1[q[i].x / j]) {
ans[q[i].id] = 1;
break;
}
}
for(int i = 1; i <= m; i++) puts(ans[i] ? "hana" : "bi");
return 0;
}