-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAugLong1.cpp
53 lines (52 loc) · 869 Bytes
/
AugLong1.cpp
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
#include<bits/stdc++.h>
using namespace std;
bool visited[100000];
int a[100000];
// 1 1 1 1
// 0 0 0 0
//
int miniSolve(int n, int N){
int result = 0,start = n;
int final = start,l=0;
int check[N];
// visited[start] = true;
while(!visited[start]){
// cout<<start<<endl;
visited[start] = true;
start = a[start] + start + 1;
result += 1;
start%=N;
}
while(final!=start){
final = final + a[final] + 1;
final%=N;
result --;
}
return result;
}
int solve(int n){
int ans = 0;
for(int i=0;i<n;i++){
if(!visited[i]){
ans += miniSolve(i,n);
}
}
for(int i =0;i<n;i++)
visited[i] = false;
return ans;
}
int main(){
ios_base::sync_with_stdio(0);
int t;
cin>>t;
while(t--){
int n;cin>>n;
// memset(visited, false, sizeof(visited));
for(int i=0;i<n;i++){
cin>>a[i];
}
int ans = solve(n);
cout<<ans<<endl;
}
return 0;
}