/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 324.0 KiB
#2 Accepted 2ms 320.0 KiB
#3 Accepted 2ms 484.0 KiB
#4 Accepted 43ms 14.578 MiB
#5 Accepted 46ms 13.824 MiB
#6 Accepted 43ms 14.68 MiB
#7 Accepted 43ms 14.602 MiB
#8 Accepted 45ms 14.336 MiB
#9 Accepted 40ms 9.367 MiB
#10 Accepted 46ms 13.656 MiB
#11 Accepted 46ms 13.566 MiB
#12 Accepted 47ms 13.594 MiB
#13 Accepted 46ms 13.574 MiB
#14 Accepted 46ms 13.43 MiB
#15 Accepted 46ms 13.582 MiB
#16 Accepted 47ms 13.582 MiB
#17 Accepted 47ms 13.496 MiB
#18 Accepted 47ms 13.418 MiB
#19 Accepted 49ms 13.426 MiB
#20 Accepted 52ms 13.332 MiB

Code

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1000000007;
#define sz(x) (ll)(x).size()
#define rd ({ll x; cin >> x; x; })
#define dbg(x) cerr << "[" #x "]  " << (x) << "\n\n"
// #define errv(x) {cerr << "["#x"]  ["; for (const auto& ___ : (x)) cerr << ___ << ", "; cerr << "]\n";}
// #define errvn(x, n) {cerr << "["#x"]  ["; for (auto ___ = 0; ___ < (n); ++___) cerr << (x)[___] << ", "; cerr << "]\n";}
// #define cerr if(0)cerr
#define xx first
#define yy second
mt19937 rnd(std::chrono::high_resolution_clock::now().time_since_epoch().count());
/*_________________________________________________________________________________________________________________________*/

void Solve()
{
    ll n;
    cin >> n;
    vector<ll> arr(n);
    for (int i = 0; i < n; i++)
        cin >> arr[i];
    vector<pair<vector<ll>, ll>> fTree(n, { {}, -1 });
    vector<bool> vis(n, false);
    ll base = 0;
    for (int i = 0; i < n; i++) {
        ll nextIndex = i + arr[i];
        if (nextIndex < n) {
            fTree[nextIndex].xx.push_back(i);
            vis[nextIndex] = true;
            fTree[i].yy = nextIndex;
        }
        if (!vis[i]) {
            vis[i] = true;
            base++;
        }
    }
    // dbg(base);
    for (int i = 0; i < n; i++) {
        ll nextIndex = i + arr[i];
        if (nextIndex < n) {
            if (sz(fTree[nextIndex].xx) == 1) {
                cout << base + 1 << ' ';
                continue;
            }
        }
        cout << base << ' ';
    }
    cout << "\n";
}

int32_t main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t = 1;
    cin >> t;
    for (int i = 1; i <= t; i++) {
        // cout << "Case #" << i << ": "; // cout << "Case " << i << ": ";
        Solve();
    }
    return 0;
}
// Coded by Tahsin Arafat (@TahsinArafat)

Information

Submit By
Type
Submission
Problem
P1066 Light switches
Contest
Brain Booster #4
Language
C++20 (G++ 13.2.0)
Submit At
2024-07-14 17:54:29
Judged At
2024-10-03 13:35:40
Judged By
Score
100
Total Time
52ms
Peak Memory
14.68 MiB