这不很简单吗?
2025-12-23 15:03:48
发布于:广东
24阅读
0回复
0点赞
#include <iostream>
#include <unordered_set>
#include <vector>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
vector<int> a(n + 1); // 下标从1开始,方便处理区间
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
while (m--) {
int L, R;
cin >> L >> R;
unordered_set<int> s;
for (int i = L; i <= R; ++i) {
s.insert(a[i]);
}
cout << s.size() << '\n';
}
return 0;
}
这里空空如也




有帮助,赞一个