#include<iostream> #include<vector> using ll = longlong; constint N = 2e5 + 8; inline ll read(){ ll S = 0, C = 0; char Y = getchar(); while (Y > 57 || Y < 48) C |= Y == 45, Y = getchar(); while (Y <= 57and Y >= 48) S = (S << 3) + (S << 1) + Y - 48, Y = getchar(); return C ? -S : S; }
std::vector<int> E[N]; int w[N];
voiddfs(int u){ int mn = 0x3f3f3f3f;
if (E[u].empty()) mn = w[u]; elsefor (auto& v : E[u]) { dfs(v);
#include<cstdio> #include<cmath> #include<algorithm> #include<vector> using ll = longlong; inline ll read(){ ll S = 0, C = 0; char Y = getchar(); while (Y > 57 || Y < 48) C |= Y == 45, Y = getchar(); while (Y <= 57and Y >= 48) S = (S << 3) + (S << 1) + Y - 48, Y = getchar(); return C ? -S : S; }
constexprint M = 300, B = 1000;
voideachT(){ 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; } // 小小优化 k>n/2 直接出答案 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) { // 注意询问有相同 因此是 while 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 有 k 个的位置 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"); } }
#include<cstdio> #include<cmath> #include<algorithm> #include<vector> using ll = longlong; inline ll read(){ ll S = 0, C = 0; char Y = getchar(); while (Y > 57 || Y < 48) C |= Y == 45, Y = getchar(); while (Y <= 57and Y >= 48) S = (S << 3) + (S << 1) + Y - 48, Y = getchar(); return C ? -S : S; }
constexprint M = 300, B = 3000;
voideachT(){ 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 i = 1; i <= n; ++i) { for (int j = 0; j < M; ++j) { pre[j][i] = pre[j][i - 1] + (a[i] > j); } } std::vector<std::vector<int> > uplevel(n + 1); for (int k = 1; k <= n; ++k) { uplevel[k].push_back(0); if (k <= B) { int now = 0, cnt = 0; for (int i = 1; i <= n; ++i) { if (a[i] > now and ++cnt == k) { uplevel[k].push_back(i); now++; cnt = 0; } } } else { int now = 0, pos = 0; while (pos <= n) { pos = std::lower_bound(pre[now].begin(), pre[now].end(), k + pre[now][pos]) - pre[now].begin(); uplevel[k].push_back(pos); now++; } } }
for (int i = 0; i < q; ++i) { int id = read(), k = read(); auto ok = a[id] >= uplevel[k].size() or id <= uplevel[k][a[id]]; printf("%s\n", ok ? "YES" : "NO"); } }