-
Notifications
You must be signed in to change notification settings - Fork 5
/
1253B.cpp
69 lines (67 loc) · 1.14 KB
/
1253B.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//21171_somesh || asomesh999
//AC
#include<bits/stdc++.h>
using namespace std;
#define fr(i,a,b) for(long long i=a;i<b;i++)
#define io ios::sync_with_stdio(false);cin.tie(NULL);
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
long int mod=1000000007;
int main()
{
io
int n;
cin >> n;
vl arr(n);
fr(i, 0, n) cin >> arr[i];
map<int, int> mp;
set<int> st;
int flag = 0;
vector<int> ans;
fr(i, 0, n) {
if (arr[i] < 0) {
auto it = st.find(-arr[i]);
if (it == st.end()) {
flag = 1;
break;
} else {
st.erase(it);
if (st.empty()) {
mp.clear();
ans.push_back(i);
}
}
} else {
if (st.find(abs(arr[i])) == st.end()) {
if (mp.find(abs(arr[i])) == mp.end()) {
st.insert(arr[i]);
mp[arr[i]]++;
} else {
flag = 1;
break;
}
} else {
flag = 1;
break;
}
}
}
if (!st.empty()) {
flag = 1;
}
if (flag) {
cout << -1;
return 0;
}
cout << (int) ans.size() << '\n';
int prev = 0;
for(auto it : ans) {
cout << it + 1 - prev << ' ';
prev = it + 1;
}
return 0;
}