QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#321141 | #8212. Football in Osijek | ucup-team992# | RE | 2ms | 7988kb | C++20 | 4.6kb | 2024-02-04 05:10:48 | 2024-02-04 05:10:48 |
Judging History
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 = {{}};
bool in_cycle[MAXN];
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> size_add;
for (int i = 1; i < size(comps); i++) {
int cycle = 0;
vector<int> tails;
for (auto x: comps[i]) {
if (size(adj[x]) > 2) {
int c = x;
while (not (cycle and c == x)) {
cycle++;
in_cycle[c] = true;
c = a[c];
}
break;
}
}
if (cycle == 0) {
cycle = size(comps[i]);
tails.push_back(0);
for (auto x: comps[i]) {
in_cycle[x] = true;
}
}
for (auto x: comps[i]) {
if (size(adj[x]) == 1) {
int tail = 0;
while (not in_cycle[x]) {
tail++;
x = a[x];
}
tails.push_back(tail);
}
}
sort(tails.begin(), tails.end());
size_add.push_back(cycle + tails[0]);
for (int j = 1; j < size(tails); j++) {
size_add.push_back(tails[j]);
}
delta[cycle]++;
delta[cycle + tails[0] + 1]--;
}
sort(size_add.begin(), size_add.end(), greater<>());
// >= 1
int tot_sz = 0;
for (int j = 0; j < size(size_add); j++) {
if (j) {
for (int i = tot_sz+1; i <= tot_sz + size_add[j]; i++) {
ans[i] = j;
}
}
tot_sz += size_add[j];
}
// 1
for (int i = 1; i <= size_add[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);
// }
// };
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 5952kb
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: 5656kb
input:
1 1
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 2ms
memory: 7988kb
input:
2 2 2
output:
0 0
result:
ok 2 number(s): "0 0"
Test #4:
score: -100
Runtime Error
input:
10 4 7 2 8 4 3 4 9 7 3