-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path844C.cpp
More file actions
70 lines (65 loc) · 1.1 KB
/
844C.cpp
File metadata and controls
70 lines (65 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <bits/stdc++.h>
using namespace std;
int n, count1 = 1;
int c[100010];
int a[100010], b[100010];
vector<int> ans_arrays[100010];
int b_search(int target) {
int lo = 0;
int hi = n - 1 ;
if(target == b[n-1])
return n-1;
while (lo <= hi) {
int mid = (hi+lo)/2;
//printf("%d\n", mid);
if( target == b[mid]) {
return mid;
}
else if(b[mid] < target) {
lo = mid + 1;
}
else
hi = mid - 1;
}
}
int main() {
scanf("%d",&n);
for (int i = 0; i < n; ++i)
{
scanf("%d",&a[i]);
b[i] = a[i];
c[i] = 0;
}
sort(b, b+n);
int ans = 0;
int flag = true;
for (int i = 0; i < n; ++i)
{
flag = true;
int target = a[i];
//printf("%d\n", a[i]);
int in = i;
while(c[in] == 0) {
flag = false;
c[in] = count1;
ans_arrays[count1].push_back(in);
int index = b_search(target);
target = a[index];
in = index;
}
if(!flag)
count1++;
}
printf("%d\n", count1-1);
for (int i = 1; i < count1; ++i)
{
ans = ans_arrays[i].size();
printf("%d ", ans);
for (int j = 0; j < ans; ++j)
{
printf("%d ", ans_arrays[i][j]+1);
}
printf("\n");
}
return 0;
}