/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 2.324 MiB
#2 Accepted 3ms 2.535 MiB
#3 Accepted 3ms 2.32 MiB
#4 Accepted 53ms 4.434 MiB
#5 Accepted 62ms 4.98 MiB
#6 Accepted 61ms 4.145 MiB
#7 Accepted 62ms 4.305 MiB
#8 Accepted 64ms 5.086 MiB
#9 Accepted 83ms 5.059 MiB
#10 Accepted 65ms 4.895 MiB
#11 Accepted 64ms 4.965 MiB
#12 Accepted 64ms 5.09 MiB
#13 Accepted 66ms 5.105 MiB
#14 Accepted 65ms 5.082 MiB
#15 Accepted 65ms 4.941 MiB
#16 Accepted 64ms 5.016 MiB
#17 Accepted 63ms 5.168 MiB
#18 Accepted 64ms 5.172 MiB
#19 Accepted 66ms 5.051 MiB
#20 Accepted 68ms 4.961 MiB

Code

// I AM A MUSLIM

#include "bits/stdc++.h"

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

#define fastIO std::ios::sync_with_stdio(0);std::cin.tie(0)
#define ll long long int
#define flush fflush(stdout)
#define bl printf("\n")
#define yn(a, b) printf("%s\n", a >= b ? "Yes":"No")
// #define int ll

using pii = std::pair<int,int>;

const int MOD = 1000000007;
// const int MOD = 998244353;
const int mxN = 500005, inf = INT_MAX;

int par[mxN], lnk[mxN];

signed main() {
    // fastIO;
    int testCases=1;
    scanf("%d",&testCases);
    // std::cin>>testCases;
    
    for (int TC = 1; TC <= testCases; TC++) {
        int N;
        scanf("%d",&N);
        int tot = 0;
        for (int i = 0; i < N; i++) par[i] = 0, lnk[i] = -1;
        
        int a[N]; for (auto &i : a) scanf("%d",&i);
        
        for (int i = 0; i < N; i++) {
            int at = i+a[i];
            if (at < N) lnk[i] = at, par[at]++;
            if (par[i]) continue;
            tot++;
        }
        // printf("%d\n", tot);
        
        for (int i = 0; i < N; i++) {
            int L = lnk[i];
            // printf("(%d %d)\n", i, L);
            int ans = tot;
            if (L != -1 && par[L] == 1) ans++;
            printf("%d ",ans);
        } bl;
        
    }
    
    return 0;
}

/*

*/

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 18:33:30
Judged At
2024-10-03 13:35:07
Judged By
Score
100
Total Time
83ms
Peak Memory
5.172 MiB