QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#321131#8212. Football in Osijekucup-team992#WA 2ms5940kbC++204.0kb2024-02-04 04:50:182024-02-04 04:50:19

Judging History

你现在查看的是最新测评结果

  • [2024-02-04 04:50:19]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:5940kb
  • [2024-02-04 04:50:18]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define ar array
#define ll long long
typedef int uci;
#define int long long
#define F first
#define S second
typedef complex<double> cd;

seed_seq seq{
    (uint64_t) chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count(),
    (uint64_t) __builtin_ia32_rdtsc(),
    (uint64_t) (uintptr_t) make_unique<char>().get()
};
mt19937 rng(seq);
// mt19937_64 lrng(seq);

struct debugger{
    template <typename T>
    debugger& operator<<(T &a){
        #ifdef DEBUG
            cerr << a;
        #endif
        return *this;
    }
    template <typename T>
    debugger& operator<<(T &&a){
        #ifdef DEBUG
            cerr << a;
        #endif
        return *this;
    }
} deb;

const double PI = acos(-1.0);
const int MAX_N = 1e5 + 1;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;

//! function insert

//THINK FIRST, CODE SECOND
//DON'T GET STUCK ON ONE STRATEGY
//CALM DOWNNN FOR ONCE IN YOUR LIFE
//REDUCE
//COUGH E??!?!?!! O.O
//uwu i see you ryan

const int MAXN = 5e5 + 1;
int a[MAXN];
vector<int> adj[MAXN];

int comp[MAXN];
vector<vector<int>> comps = {{}};

void dfs(int c) {
    comp[c] = size(comps)-1;
    comps.back().push_back(c);

    for (auto ne: adj[c]) {
        if (comp[ne] == 0) {
            dfs(ne);
        }
    }
}

void solve() {
    int n; cin >> n;

    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        adj[i].push_back(a[i]);
        adj[a[i]].push_back(i);
    }

    for (int i = 1; i <= n; i++) {
        if (comp[i] == 0) {
            comps.emplace_back();
            dfs(i);
        }
    }

    vector<int> delta(n+2);
    vector<int> ans(n+1);

    vector<int> comp_sizes;

    for (int i = 1; i < size(comps); i++) {
        comp_sizes.push_back(size(comps[i]));

        int cycle = 0;

        for (auto x: comps[i]) {
            if (size(adj[x]) == 3) {
                int c = x;
                while (not (cycle and c == x)) {
                    cycle++;
                    c = a[c];
                }
            }
        }

        if (cycle == 0) {
            cycle = size(comps[i]);
        }

        delta[cycle]++;
        delta[size(comps[i])+1]--;
    }

    sort(comp_sizes.begin(), comp_sizes.end(), greater<>());

    // >= 1
    int tot_sz = 0;
    for (int j = 0; j < size(comp_sizes); j++) {
        if (j) {
            for (int i = tot_sz+1; i <= tot_sz + comp_sizes[j]; i++) {
                ans[i] = j;
            }
        }
        tot_sz += comp_sizes[j];
    }

    // 1
    for (int i = 1; i <= comp_sizes[0]; i++) {
        ans[i] = 1;
    }

    // 0
    for (int i = 1; i <= n; i++) {
        delta[i] += delta[i-1];
        if (delta[i]) {
            ans[i] = 0;
        }
    }


    for (int i = 1; i <= n; i++) {
        cout << ans[i] << ' ';
    }
}


uci main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    solve();
}

/*
    random number generator stuff
    num = rng(); gives integer number
    num = uniform_int_distribution<int>(a, b)(rng); -> bounds [a, b]
    num = uniform_real_distribution<double>(a, b)(rng); -> bounds [a, b)
    can also instantiate distributions and call on generator:
    uniform_int_distribution<int> thing(a, b);
    num = thing(rng);
*/
// struct custom_hash {
//     static uint64_t splitmix64(uint64_t x) {
//         // http://xorshift.di.unimi.it/splitmix64.c
//         x += 0x9e3779b97f4a7c15;
//         x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
//         x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
//         return x ^ (x >> 31);
//     }
//     size_t operator()(uint64_t x) const {
//         static const uint64_t FIXED_RANDOM = lrng();
//         return splitmix64(x + FIXED_RANDOM);
//     }
// };

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 5640kb

input:

5
2 3 1 3 5

output:

0 1 0 0 1 

result:

ok 5 number(s): "0 1 0 0 1"

Test #2:

score: 0
Accepted
time: 1ms
memory: 5704kb

input:

1
1

output:

0 

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 0ms
memory: 5940kb

input:

2
2 2

output:

0 0 

result:

ok 2 number(s): "0 0"

Test #4:

score: -100
Wrong Answer
time: 2ms
memory: 5708kb

input:

10
4 7 2 8 4 3 4 9 7 3

output:

1 1 1 0 0 0 0 0 0 0 

result:

wrong answer 8th numbers differ - expected: '1', found: '0'