/ SeriousOJ /

Record Detail

Compile Error

foo.cc:21:23: error: 'int link [500005]' redeclared as different kind of entity
   21 | int par[mxN], link[mxN];
      |                       ^
In file included from /usr/include/c++/13/bits/atomic_wait.h:45,
                 from /usr/include/c++/13/bits/atomic_base.h:42,
                 from /usr/include/c++/13/bits/shared_ptr_atomic.h:33,
                 from /usr/include/c++/13/memory:81,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:56,
                 from foo.cc:3:
/usr/include/unistd.h:819:12: note: previous declaration 'int link(const char*, const char*)'
  819 | extern int link (const char *__from, const char *__to)
      |            ^~~~
foo.cc: In function 'int main()':
foo.cc:33:57: error: assignment of read-only location '*(link + ((sizetype)i))'
   33 |         for (int i = 0; i < N; i++) par[i] = 0, link[i] = -1;
      |                                                 ~~~~~~~~^~~~
foo.cc:39:33: error: assignment of read-only location '*(link + ((sizetype)i))'
   39 |             if (at < N) link[i] = at, par[at]++;
      |                         ~~~~~~~~^~~~
foo.cc:46:27: error: invalid conversion from 'int (*)(const char*, const char*) noexcept' to 'int' [-fpermissive]
   46 |             int L = link[i];
      |                           ^
      |                           |
      |                           int (*)(const char*, const char*) noexcept

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], link[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, link[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) link[i] = at, par[at]++;
            if (par[i]) continue;
            tot++;
        }
        // printf("%d\n", tot);
        
        for (int i = 0; i < N; i++) {
            int L = link[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:32:41
Judged At
2024-10-03 13:35:08
Judged By
Score
0
Total Time
0ms
Peak Memory
0 Bytes