n, m =list(map(int, input().split()))ns =list(map(int, input().split()))Q =int(input())lrs = []for i inrange(Q): l, r =list(map(int, input().split()))print(len(set(ns[l -1: r -1])))
C++(57%)
Java 相同做法可 AC
```C++
include
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> ns(n+1, 0);
for (int i=1; i<=n; i++)
cin >> ns[i];
int Q;
cin >> Q;
set<int> tmp;
for (int i=0; i<Q; i++) {
int l, r;
cin >> l >> r;
for (int k=l; k<=r; k++)
tmp.insert(ns[k]);
cout << tmp.size() << endl;
tmp.clear();
}
return 0;