ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#212169 | #3816. 元素 | Panjunnan | Compile Error | / | / | C++ | 1.0kb | 2024-10-13 11:46:21 | 2024-10-13 12:29:21 |
answer
#include <iostream>
#include <vector>
#include <unordered_set>
#include <algorithm>
using namespace std;
const int MAXN = 100005;
int a[MAXN];
int first[MAXN]; // 存储每个数字首次出现的索引
int last[MAXN]; // 存储每个数字最后一次出现的索引
unordered_set<int> elements; // 存储当前区间内出现过的元素
int main() {
int n, q;
cin >> n >> q;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
first[a[i]] = i;
last[a[i]] = i;
}
while (q--) {
int l, r;
cin >> l >> r;
elements.clear();
int maxR = 0, minL = r + 1;
for (int i = l; i <= r; ++i) {
elements.insert(a[i]);
last[a[i]] = i;
}
for (int num : elements) {
int curL = first[num];
int curR = last[num];
if (curL > maxR) maxR = curL;
if (curR < minL) minL = curR;
}
cout << minL - maxR + 1 << endl;
}
return 0;
}
详细
In file included from /usr/include/c++/4.8/unordered_set:35:0, from answer.code:3: /usr/include/c++/4.8/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options. #error This file requires compiler and library support for the \ ^ answer.code:11:1: error: 'unordered_set' does not name a type unordered_se...