6
2024-07-08 16:54:47
发布于:浙江
19阅读
0回复
0点赞
这题不会,看不懂
全部评论 1
```cpp #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; }
2025-06-27 来自 浙江
0
有帮助,赞一个