QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#699163 | #8838. Jesse's Job | kenkenken | RE | 133ms | 26612kb | C++23 | 2.3kb | 2024-11-02 02:35:26 | 2024-11-02 02:35:26 |
Judging History
answer
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define pob pop_back
#define SZ(x) (int)(x.size())
#define all(x) begin(x), end(x)
#ifdef LOCAL
#define HEHE freopen("in.txt", "r", stdin);
#define debug(...) {cerr << #__VA_ARGS__ << " = "; dbg(__VA_ARGS__);}
#else
#define HEHE ios_base::sync_with_stdio(0), cin.tie(0);
#define debug(...) 7122;
#endif
using namespace std;
#define chmax(a, b) (a) = (a) > (b) ? (a) : (b)
#define chmin(a, b) (a) = (a) < (b) ? (a) : (b)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
void dbg() { cerr << '\n'; }
template<typename T, typename ...U>
void dbg(T t, U ...u) { cerr << t << ' '; dbg(u...); }
#define int long long
struct DSU {
int p[100005];
int sz;
int Find(int x) {
return p[x] < 0 ? x : p[x] = Find(p[x]);
}
void Union(int a, int b) {
a = Find(a); b = Find(b);
if (a == b) return;
if (-p[a] < -p[b]) swap(a, b);
p[a] += p[b];
p[b] = a;
sz--;
}
} dsu;
void solve() {
int n; cin >> n;
vector<int> a(n), p(n);
FOR (i, 0, n - 1) cin >> a[i], a[i]--, p[a[i]] = i;
vector<int> vis(n);
int x = 0;
vector<int> v;
while (!vis[x]) {
v.pb(x);
vis[x] = 1;
x = p[x];
}
if (v.size() != n) {
cout << n << '\n';
cout << v.size() << '\n';
for (int i : v) cout << i + 1 << ' ';
cout << '\n';
}
else {
vector<int> v1, v2;
FOR (i, 0, n - 1) dsu.p[i] = -1;
dsu.sz = n;
if (n == 2) {
v1.pb(1);
}
else {
FOR (i, 0, n - 1) {
if (dsu.Find(a[p[i]]) != dsu.Find(p[i]) and dsu.sz > 2) {
dsu.Union(a[p[i]], p[i]);
}
}
FOR (i, 0, n - 1) {
if (dsu.Find(i) == dsu.Find(0)) {
v1.pb(i);
}
}
}
cout << n - 2 << '\n';
sort(all(v1));
v1.resize(unique(all(v1)) - v1.begin());
cout << v1.size() << '\n';
for (int i : v1) cout << i + 1 << ' ';
cout << '\n';
}
}
signed main() {
HEHE
int t; cin >> t;
while (t--) solve();
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3540kb
input:
3 2 2 1 4 2 1 4 3 6 3 5 4 2 6 1
output:
0 1 2 4 2 1 2 4 5 1 2 3 4 6
result:
ok Correct (3 test cases)
Test #2:
score: 0
Accepted
time: 1ms
memory: 3548kb
input:
872 6 1 5 2 6 3 4 6 5 2 1 3 4 6 4 2 1 3 4 6 2 3 1 4 5 6 6 4 5 1 6 2 3 6 6 2 3 1 4 5 5 2 1 3 4 5 6 1 2 6 4 3 5 4 2 1 4 3 6 1 6 4 2 5 3 6 6 1 3 5 4 2 6 2 1 4 5 6 3 6 3 4 1 5 6 2 6 4 1 5 3 2 6 6 5 2 1 6 3 4 6 4 1 6 2 5 3 6 5 1 3 6 2 4 6 6 2 5 4 3 1 6 6 2 5 3 1 4 6 5 2 4 1 3 6 6 6 1 3 2 4 5 6 2 3 4 6 5 ...
output:
6 1 1 6 4 1 3 4 5 4 2 1 2 6 3 1 3 2 6 4 1 3 6 4 6 4 1 4 5 6 5 2 1 2 6 1 1 4 2 1 2 6 1 1 6 3 1 2 6 6 2 1 2 6 2 1 3 6 5 1 2 5 3 4 6 3 1 3 5 6 3 1 2 4 6 3 1 2 5 6 2 1 6 6 5 1 5 3 4 6 6 4 1 4 3 5 6 5 1 2 4 5 6 6 5 1 6 4 3 2 6 5 1 6 2 3 5 6 2 1 4 4 5 1 2 3 4 6 6 2 1 3 6 1 1 6 1...
result:
ok Correct (872 test cases)
Test #3:
score: 0
Accepted
time: 29ms
memory: 3596kb
input:
46232 7 2 1 7 5 3 6 4 7 5 6 2 4 7 1 3 4 3 4 2 1 7 4 5 1 6 3 7 2 8 4 2 6 5 1 7 3 8 8 3 4 8 7 1 2 5 6 7 6 2 4 3 7 5 1 8 8 1 3 2 7 5 4 6 8 6 5 4 2 1 3 8 7 8 8 3 5 6 2 7 4 1 8 7 3 6 1 8 5 4 2 8 2 3 4 5 8 6 7 1 8 5 8 2 4 7 3 6 1 8 3 4 8 2 7 6 1 5 8 2 8 3 5 7 6 1 4 8 8 4 5 7 6 1 3 2 8 5 2 6 3 4 8 1 7 8 2 ...
output:
7 2 1 2 7 6 1 6 2 3 7 5 2 2 1 4 5 6 1 2 3 4 5 7 8 3 1 5 4 6 4 1 3 5 7 7 4 1 7 5 6 8 7 1 2 4 7 5 6 8 8 6 1 5 2 4 3 6 8 2 1 8 8 3 1 4 7 8 6 1 8 5 4 3 2 8 7 1 8 2 3 6 7 5 8 5 1 7 5 8 3 8 6 1 7 5 4 8 2 6 5 1 3 5 6 7 8 7 1 7 8 6 3 4 5 8 6 1 8 6 7 4 2 6 6 1 3 4 5 6 8 7 1 1 8 7 1 5 3 4 ...
result:
ok Correct (46232 test cases)
Test #4:
score: 0
Accepted
time: 132ms
memory: 26612kb
input:
1 999995 992870 210969 579550 405695 249895 436695 476463 929789 907510 311379 340877 491996 59204 996443 681309 483046 760005 905577 711115 275827 697004 450345 678866 276460 310113 542672 27 914370 232581 624905 590395 136666 628293 731656 670994 184745 662928 389422 848680 447853 325275 979617 82...
output:
999995 3 1 132245 992870
result:
ok Correct (1 test case)
Test #5:
score: 0
Accepted
time: 133ms
memory: 26468kb
input:
1 999999 132956 959208 556000 604257 627699 841942 392337 85216 596714 941258 128586 471931 589450 975529 945897 459533 603544 562877 170464 568730 134581 853340 114919 588755 677661 246220 410344 431559 600933 71503 340747 300767 956226 134024 377489 953726 922690 597383 328440 183077 305496 911409...
output:
999999 3 1 709905 132956
result:
ok Correct (1 test case)
Test #6:
score: -100
Runtime Error
input:
1 999995 151304 350332 773183 104266 183633 346263 526539 191085 531746 355173 883744 387959 24944 911448 969746 652626 567671 859523 590384 980797 692606 699234 873314 30142 292030 794805 784083 528201 66334 787834 981995 233166 953602 312617 136612 832397 103749 244552 955161 491539 668517 866412 ...