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
|
#include <bits/stdc++.h> using namespace std; #define resetIO(x) \ freopen(#x ".in", "r", stdin), freopen(#x ".out", "w", stdout) #define debug(fmt, ...) \ fprintf(stderr, "[%s:%d] " fmt "\n", __FILE__, __LINE__, ##__VA_ARGS__) template <class _Tp> inline _Tp& read(_Tp& x) { bool sign = false; char ch = getchar(); double tmp = 1; for (; !isdigit(ch); ch = getchar()) sign |= (ch == '-'); for (x = 0; isdigit(ch); ch = getchar()) x = x * 10 + (ch ^ 48); return sign ? (x = -x) : x; } template <class _Tp> inline void write(_Tp x) { if (x < 0) putchar('-'), x = -x; if (x > 9) write(x / 10); putchar((x % 10) ^ 48); } bool m_be; using ll = long long; const int MAXN = 1e5 + 10; const int MAXB = 320; const int INF = 0x3f3f3f3f; int n, m, q, blk, vblk, a[MAXN], cnt[MAXN], lst[MAXN], pre[MAXB][MAXN]; bool ans[MAXN]; bitset<MAXN> bs1, bs2; struct Query { int op, l, r, x, i; } qr[MAXN]; inline void add(int x) { !cnt[x]++ && (bs1[x] = bs2[m - x] = 1); } inline void dec(int x) { !--cnt[x] && (bs1[x] = bs2[m - x] = 0); } inline void chkmax(int& x, int y) { (x < y) && (x = y); } bool m_ed; signed main() { read(n), read(q), m = 1e5; for (int i = 1; i <= n; ++i) read(a[i]); for (int i = 1; i <= q; ++i) { int op, l, r, x; read(op), read(l), read(r), read(x); qr[i] = {op, l, r, x, i}; } blk = ceil(sqrt(n)), vblk = ceil(sqrt(m)); sort(qr + 1, qr + q + 1, [&](const Query& x, const Query& y) { int bx = (x.l - 1) / blk, by = (y.l - 1) / blk; return bx < by || (bx == by && ((bx & 1) ? x.r < y.r : x.r > y.r)); }); for (int i = 1; i <= vblk; ++i) { fill(lst + 1, lst + m + 1, 0); for (int j = 1; j <= n; ++j) { lst[a[j]] = j; pre[i][j] = pre[i][j - 1]; if (a[j] * i <= m && lst[a[j] * i]) chkmax(pre[i][j], lst[a[j] * i]); if (a[j] % i == 0 && lst[a[j] / i]) chkmax(pre[i][j], lst[a[j] / i]); } } int l = 1, r = 0; bs1.reset(), bs2.reset(); for (int i = 1; i <= q; ++i) { while (l > qr[i].l) add(a[--l]); while (r < qr[i].r) add(a[++r]); while (l < qr[i].l) dec(a[l++]); while (r > qr[i].r) dec(a[r--]); if (qr[i].op == 1) { ans[qr[i].i] = (bs1 & (bs1 << qr[i].x)).any(); } else if (qr[i].op == 2) { ans[qr[i].i] = (bs1 & (bs2 >> (m - qr[i].x))).any(); } else if (qr[i].op == 3) { for (int j = 1; j * j <= qr[i].x; ++j) if (qr[i].x % j == 0) ans[qr[i].i] |= bs1[j] && bs1[qr[i].x / j]; } else if (qr[i].x > vblk) { for (int j = 1; j * qr[i].x <= m; ++j) ans[qr[i].i] |= bs1[j] && bs1[j * qr[i].x]; } else { ans[qr[i].i] = pre[qr[i].x][qr[i].r] >= qr[i].l; } } for (int i = 1; i <= q; ++i) puts(ans[i] ? "yuno" : "yumi"); return 0; }
|