/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Accepted 2ms 324.0 KiB
#3 Accepted 1ms 532.0 KiB
#4 Accepted 28ms 3.816 MiB
#5 Accepted 32ms 4.648 MiB
#6 Accepted 27ms 3.812 MiB
#7 Accepted 28ms 3.879 MiB
#8 Accepted 34ms 4.641 MiB
#9 Accepted 38ms 4.82 MiB
#10 Accepted 32ms 4.785 MiB
#11 Accepted 31ms 4.711 MiB
#12 Accepted 32ms 4.555 MiB
#13 Accepted 32ms 4.625 MiB
#14 Accepted 31ms 4.562 MiB
#15 Accepted 33ms 4.559 MiB
#16 Accepted 33ms 4.555 MiB
#17 Accepted 33ms 4.527 MiB
#18 Accepted 33ms 4.598 MiB
#19 Accepted 33ms 4.668 MiB
#20 Accepted 34ms 4.551 MiB

Code

#include <bits/stdc++.h>
#define ll long long
#define endll '\n';
#define pb push_back
#define all(v) v.begin(), v.end()
using namespace std;

const int mod = 1e9 + 7, N = 1e6;

void solve()
{
    int n;
    cin >> n;
    int ar[n + 4];
    for (int i = 1; i <= n; i++)
        cin >> ar[i];
    int click = 0;
    int vis[n + 4] = {0};
    int last[n + 4] = {0};
    int clicked[n + 4] = {0};
    for (int i = 1; i <= n; i++)
    {
        if (vis[i] == 0)
        {
            click++;
            clicked[i] = 1;
            vis[i] = 0;
        }
        int nxt = ar[i] + i;
        if (nxt <= n)
        {
            vis[nxt] += 1;
            last[nxt] = i;
        }
    }
    // cout << "Clicke = ";
    // for (int i = 1; i <= n; i++)
    // {
    //     cout << clicked[i] << " ";
    // }
    // cout << endll;
    // cout << "vis = ";
    // for (int i = 1; i <= n; i++)
    // {
    //     cout << vis[i] << " ";
    // }
    // cout << endll;

    // cout << "last = ";
    // for (int i = 1; i <= n; i++)
    // {
    //     cout << last[i] << " ";
    // }
    // cout << endll;

    for (int i = 1; i <= n; i++)
    {
        int ans = click;
        int nxt = ar[i] + i;
        if (clicked[i] == 0)
        {

            if (vis[i])
            {
            }
            else
                ans++;

            if (nxt <= n)
            {
                if (vis[nxt] == 1 && last[nxt] == i)
                {
                    ans++;
                }
            }
        }
        else
        {

            if (nxt <= n)
            {
                if (vis[nxt] == 1 && last[nxt] == i)
                {
                    ans++;
                }
            }
        }
        cout << ans << " ";
    }
    cout << endll;
}

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
    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 17:31:46
Judged At
2024-10-03 13:36:03
Judged By
Score
100
Total Time
38ms
Peak Memory
4.82 MiB