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
| #include <cstdio> #include <cmath> #include <algorithm> #include <vector> using ll = long long; inline ll read() { ll S = 0, C = 0; char Y = getchar(); while (Y > 57 || Y < 48) C |= Y == 45, Y = getchar(); while (Y <= 57 and Y >= 48) S = (S << 3) + (S << 1) + Y - 48, Y = getchar(); return C ? -S : S; }
constexpr int M = 300, B = 1000;
void eachT() { int n = read(), q = read();
std::vector<int> a(n + 1); for (int i = 1; i <= n; ++i) { a[i] = read(); }
std::vector<std::vector<int> > pre(M, std::vector<int>(n + 1, 0)); for (int j = 0; j < M; ++j) { for (int i = 1; i <= n; ++i) { pre[j][i] = pre[j][i - 1] + (a[i] > j); } }
std::vector<std::vector<std::pair<int, int> > > ask(n + 1); std::vector<int> ans(q + 1); for (int i = 1; i <= q; ++i) { int id = read(), k = read(); if (k > n / 2) { ans[i] = id <= k or a[id] > 1; } else { ask[k].emplace_back(id, i); } }
for (int k = 1; k <= n / 2; ++k) { if (ask[k].empty()) continue; std::sort(ask[k].begin(), ask[k].end());
if (k <= B) { int now = 1, cnt = 0, it = 0; for (int i = 1; i <= n; ++i) { while (it < ask[k].size() and ask[k][it].first == i) { ans[ask[k][it].second] = a[i] >= now; ++it; } if (a[i] >= now and ++cnt == k) ++now, cnt = 0; } }
else { int pos = 0, now = 0, it = 0; while (pos <= n) { pos = std::lower_bound(pre[now].begin() + pos, pre[now].end(), pre[now][pos] + k) - pre[now].begin(); now += 1; while (it < ask[k].size() and ask[k][it].first <= pos) { ans[ask[k][it].second] = a[ask[k][it].first] >= now; ++it; } } } }
for (int i = 1; i <= q; ++i) { printf("%s\n", ans[i] ? "YES" : "NO"); } }
int main() { eachT(); return 0; }
|