ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#212162 | #3816. 元素 | Aaron | Compile Error | / | / | C++11 | 1.3kb | 2024-10-13 11:43:34 | 2024-10-13 12:28:42 |
answer
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, q;
cin >> n >> q;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
while (q--) {
int l, r;
cin >> l >> r;
l--; r--;
unordered_set<int> t;
for (int i = l; i <= r; ++i) {
t.insert(a[i]);
}
int min = numeric_limits<int>::max();
unordered_map<int, int> cnt;
int ans = 0;
int left = 0;
for (int right = 0; right < n; ++right) {
if (t.find(a[right]) != t.end()) {
if (cnt[a[right]] == 0) {
ans++;
}
cnt[a[right]]++;
}
while (ans == t.size()) {
min = min(min, right - left + 1);
if (t.find(a[left]) != t.end()) {
cnt[a[left]]--;
if (cnt[a[left]] == 0) {
ans--;
}
}
left++;
}
}
if (min == numeric_limits<int>::max()) {
cout << -1 << endl;
} else {
cout << min << endl;
}
}
return 0;
}
Details
answer.code: In function 'int main()': answer.code:37:48: error: 'min' cannot be used as a function min = min(min, right - left + 1);\x0d ^