/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Accepted 2ms 532.0 KiB
#3 Accepted 2ms 532.0 KiB
#4 Accepted 23ms 2.316 MiB
#5 Accepted 24ms 3.074 MiB
#6 Accepted 23ms 2.309 MiB
#7 Accepted 23ms 2.312 MiB
#8 Accepted 28ms 3.07 MiB
#9 Accepted 33ms 3.316 MiB
#10 Accepted 26ms 3.066 MiB
#11 Accepted 25ms 3.102 MiB
#12 Accepted 25ms 3.059 MiB
#13 Accepted 25ms 3.062 MiB
#14 Accepted 24ms 3.07 MiB
#15 Accepted 25ms 3.062 MiB
#16 Accepted 24ms 3.062 MiB
#17 Accepted 25ms 3.02 MiB
#18 Accepted 25ms 3.09 MiB
#19 Accepted 25ms 3.145 MiB
#20 Accepted 26ms 3.07 MiB

Code

#include <bits/stdc++.h>

#pragma GCC optimize("Ofast")
using namespace std;

void solve(int cs) {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> sf(n, 0);
  int cnt = 0;
  for (int i = n - 1; i; i--) {
    if (i + a[i] < n) {
      sf[i + a[i]]++;
      if (sf[i + a[i]] == 1) {
        cnt += 1;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    cout << n - cnt << " \n"[i == n - 1];
    if (i < n - 1) {
      if (i + 1 + a[i + 1] < n) {
        sf[i + 1 + a[i + 1]]--;
        if (sf[i + 1 + a[i + 1]] == 0) {
          cnt -= 1;
        }
      }
    } 
    if (i + a[i] < n) {
      sf[i + a[i]]++;
      if (sf[i + a[i]] == 1) {
        cnt += 1;
      }
    }
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tc = 1;
  cin >> tc;
  for (int cs = 1; cs <= tc; cs++) {
    solve(cs);
  }
  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:24:40
Judged At
2024-10-03 13:35:15
Judged By
Score
100
Total Time
33ms
Peak Memory
3.316 MiB