forked from KevinMathewT/Competitive-Programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlternatingSubarrayPrefixAgain.cpp
More file actions
46 lines (38 loc) · 897 Bytes
/
Copy pathAlternatingSubarrayPrefixAgain.cpp
File metadata and controls
46 lines (38 loc) · 897 Bytes
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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double ld;
// Kevin Mathew T
// Birla Institute of Technology, Mesra
// GitHub - https://github.com/KevinMathewT
// CodeForces - https://codeforces.com/profile/KevinMathew
// CodeChef - https://www.codechef.com/users/KevinMathew
// HackerRank - https://www.hackerrank.com/KevinMathew?
ll n, a[100010], dp[100010];
void solve(){
cin >> n;
for(ll i=0;i<n;i++)
cin >> a[i];
dp[n-1] = 1;
for(ll i=n-2;i>=0;i--)
if((a[i] * a[i+1]) < 0)
dp[i] = dp[i+1] + 1;
else
dp[i] = 1;
for(ll i=0;i<n;i++)
cout << dp[i] << ' ';
cout << "\n";
}
int main()
{
// freopen("input.txt", "r", stdin); //Comment
// freopen("output.txt", "w", stdout); //this out.
ios::sync_with_stdio(false); //Not
cin.tie(NULL); //this.
cout.tie(0); //or this.
ll T;
cin >> T;
while(T--)
solve();
return 0;
}