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
| #include <bits/stdc++.h> using namespace std;
#ifdef Fread #define getchar() ((p1 == p2 && p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin)) ? EOF : *p1 ++) char buf[1 << 21], *p1, *p2; #endif
template <typename T> void r1(T &x) { x = 0; char c(getchar()); int f(1); for(; !isdigit(c); c = getchar()) if(c == '-') f = -1; for(; isdigit(c);c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48); x *= f; }
const int maxn = 1e5 + 5; const int maxm = maxn << 1;
typedef int room[maxn];
int n, m; int a[maxn], bel[maxn];
const int lim = 316; const int Z = 1e5;
bitset<maxn * 2> B0, S0;
struct Node { int opt, l, r, val, id; int operator < (const Node &z) const { return (bel[l] == bel[z.l]) ? r < z.r : bel[l] < bel[z.l]; } }q[maxn]; int tot; vector<int> ql[maxn], qr[maxn], qid[maxn]; int pre[maxn], maxl[maxn]; int cnt[maxn];
void Add(int x) { int w = a[x]; ++ cnt[w]; B0[Z + w + 1] = 1; S0[Z - w] = 1; } void Del(int x) { int w = a[x]; -- cnt[w]; if(cnt[w] == 0) B0[Z + w + 1] = 0, S0[Z - w] = 0; }
int ans[maxn];
#define yes(_) ans[_] = 1
signed main() {
int i, j, B; r1(n), r1(m); B = sqrt(n); for(i = 1; i <= n; ++ i) r1(a[i]); for(i = 1; i <= n; ++ i) bel[i] = (i - 1) / B + 1; for(i = 1; i <= m; ++ i) { int opt, l, r, x; r1(opt), r1(l), r1(r), r1(x); if(opt != 4 || (opt == 4 && x > lim)) { q[++ tot] = (Node) {opt, l, r, x, i}; } else { ql[x].push_back(l), qr[x].push_back(r), qid[x].push_back(i); } } int m1 = m; m = tot; sort(q + 1, q + m + 1); int L(1), R(0); for(i = 1; i <= m; ++ i) { int x = q[i].val, opt = q[i].opt; while(L > q[i].l) Add(-- L); while(R < q[i].r) Add(++ R); while(L < q[i].l) Del(L ++); while(R > q[i].r) Del(R --); if(opt == 1) { if((B0 & (B0 >> x)) != 0) ans[q[i].id] = 1; } else if(opt == 2) { if(((B0 >> (x + 1)) & S0) != 0) ans[q[i].id] = 1; } else if(opt == 3) { for(int j = 1; j * j <= x; ++ j) if(x % j == 0) { if(j <= Z && (x / j) <= Z && B0[j + Z + 1] == 1 && B0[x / j + Z + 1] == 1) {ans[q[i].id] = 1;break;} } } else { for(int j = 1; j * x <= Z; ++ j) if(B0[j + Z + 1] && B0[j * x + Z + 1]) { ans[q[i].id] = 1; break; } } }
for(int x = 1; x <= lim; ++ x) if(!ql[x].empty()) { int l(0); for(i = 1; i <= n; ++ i) { int w = a[i]; pre[w] = i; if(w * x <= Z) l = max(l, pre[w * x]); if(w % x == 0) l = max(l, pre[w / x]); maxl[i] = l; } for(unsigned int i = 0; i < ql[x].size(); ++ i) { ans[qid[x][i]] = (ql[x][i] <= maxl[qr[x][i]]); } memset(pre, 0, sizeof(pre)); memset(maxl, 0, sizeof(maxl)); } #define YNOI #ifdef YNOI for(i = 1; i <= m1; ++ i) { if(ans[i]) puts("yuno"); else puts("yumi"); } #endif #ifndef YNOI for(i = 1; i <= m1; ++ i) { if(ans[i]) puts("hana"); else puts("bi"); } #endif
return 0; }
|