/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 332.0 KiB
#2 Accepted 2ms 336.0 KiB
#3 Accepted 2ms 540.0 KiB
#4 Accepted 50ms 3.793 MiB
#5 Accepted 56ms 4.555 MiB
#6 Accepted 47ms 4.078 MiB
#7 Accepted 57ms 3.973 MiB
#8 Accepted 67ms 4.746 MiB
#9 Accepted 80ms 4.922 MiB
#10 Accepted 70ms 4.691 MiB
#11 Accepted 57ms 4.555 MiB
#12 Accepted 68ms 4.695 MiB
#13 Accepted 58ms 4.625 MiB
#14 Accepted 62ms 4.594 MiB
#15 Accepted 65ms 4.672 MiB
#16 Accepted 64ms 4.586 MiB
#17 Accepted 58ms 4.695 MiB
#18 Accepted 57ms 4.605 MiB
#19 Accepted 60ms 4.559 MiB
#20 Accepted 66ms 4.578 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-11-11 03:22:54
Judged By
Score
100
Total Time
80ms
Peak Memory
4.922 MiB