/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 320.0 KiB
#2 Accepted 2ms 524.0 KiB
#3 Accepted 1ms 324.0 KiB
#4 Accepted 25ms 2.312 MiB
#5 Accepted 26ms 2.988 MiB
#6 Accepted 25ms 2.434 MiB
#7 Accepted 25ms 2.395 MiB
#8 Accepted 30ms 3.145 MiB
#9 Accepted 37ms 3.41 MiB
#10 Accepted 26ms 2.988 MiB
#11 Accepted 26ms 3.227 MiB
#12 Accepted 27ms 3.16 MiB
#13 Accepted 26ms 3.066 MiB
#14 Accepted 26ms 3.07 MiB
#15 Accepted 26ms 3.062 MiB
#16 Accepted 26ms 3.066 MiB
#17 Accepted 27ms 3.066 MiB
#18 Accepted 27ms 3.074 MiB
#19 Accepted 28ms 3.066 MiB
#20 Accepted 29ms 3.062 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-11-11 03:22:19
Judged By
Score
100
Total Time
37ms
Peak Memory
3.41 MiB