题解
2025-06-27 20:31:38
发布于:浙江
4阅读
0回复
0点赞
#include <iostream>
#include <vector>
#include <unordered_map>
#include <string>
using namespace std;
void solve() {
int n;
cin >> n;
vector<int> a(n);
unordered_map<int, int> first_pos, last_pos;
for (int i = 0; i < n; ++i) {
cin >> a[i];
if (first_pos.find(a[i]) == first_pos.end()) {
first_pos[a[i]] = i;
}
last_pos[a[i]] = i;
}
vector<int> ans(n, 0);
int min_first = n, max_last = -1;
for (int m = 1; m <= n; ++m) {
min_first = min(min_first, first_pos[m]);
max_last = max(max_last, last_pos[m]);
if (max_last - min_first + 1 == m) {
ans[m - 1] = 1;
}
}
for (int num : ans) {
cout << num;
}
cout << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin >> T;
while (T--) {
solve();
}
return 0;
}
这里空空如也
有帮助,赞一个