题目链接
题意
Alice
和Bob
将进行一场射击比赛
题解
点击查看代码
#include <bits/stdc++.h>
using i64 = long long;
i64 seed = std::chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937_64 rng(seed ^ std::random_device{}());
constexpr int M = 1E6 + 5;
i64 hash[M];
void solve() {
int n, q;
std::cin >> n >> q;
std::vector<int> a(n);
for (int i = 0; i < n; ++i) {
std::cin >> a[i];
}
std::vector<i64> pref(n + 1);
for (int i = 0; i < n; ++i) {
pref[i + 1] = pref[i] ^ hash[a[i]];
}
for (int i = 0; i < q; ++i) {
int l, r;
std::cin >> l >> r;
if ((r - l + 1) % 2) {
std::cout << "NO\n";
continue;
}
--l;
std::cout << ((pref[r] ^ pref[l]) == 0 ? "YES\n" : "NO\n");
}
}
int main() {
std::ios::sync_with_stdio(false); std::cin.tie(nullptr);
for (int i = 1; i < M; ++i) {
hash[i] = rng() % i64(1e18);
}
int T;
std::cin >> T;
while (T--) {
solve();
}
return 0;
}