Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- void test_case(const int &tc) {
- int n;
- string s;
- cin >> n >> s;
- s = '$' + s;
- vector<int> lower_true, lower_false;
- queue<int> upper_true, upper_false;
- for (int i = 1; i <= n; ++i) {
- if (s[i] == '1') {
- upper_true.emplace(i);
- } else {
- upper_false.emplace(i);
- }
- }
- int x;
- for (x = 1; x <= n; ++x) {
- while (!upper_true.empty() && upper_true.front() <= x) {
- lower_true.emplace_back(upper_true.front());
- upper_true.pop();
- }
- while (!upper_false.empty() && upper_false.front() <= x) {
- lower_false.emplace_back(upper_false.front());
- upper_false.pop();
- }
- if (lower_true.size() + upper_false.size() - (s[x] == '1') == lower_false.size() + upper_true.size() - (s[x] == '0')) {
- break;
- }
- }
- if (s[x] == '1') {
- lower_true.pop_back();
- } else {
- lower_false.pop_back();
- }
- for (const int &it : lower_true) {
- cout << it << ' ';
- }
- while (!upper_false.empty()) {
- cout << upper_false.front() << ' ';
- upper_false.pop();
- }
- cout << x << ' ';
- for (const int &it : lower_false) {
- cout << it << ' ';
- }
- while (!upper_true.empty()) {
- cout << upper_true.front() << ' ';
- upper_true.pop();
- }
- cout << '\n';
- }
- int main() {
- int T;
- cin >> T;
- for (int tc = 1; tc <= T; ++tc)
- test_case(tc);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement