Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- vector<int> ans;
- int main() {
- int n;
- cin >> n;
- vector<int> a(n);
- for (auto &i:a)
- cin>>i;
- memset(in, 0, sizeof in);
- int day = 1;
- for (int i= 0; i< a.size(); ++i) {
- update (abs(a[i]), sign(a[i]));
- // employee already entered that day and is entering
- if (in[abs(a[i])] == day && a[i] > 0) {
- cout << -1 << endl;
- return 0;
- }
- // employee didnt entered that day and is leaving
- if (in[abs(a[i])] < day && a[i] < 0) {
- cout << -1 << endl;
- return 0;
- }
- // employee entered that day
- if (a[i] > 0)
- in[a[i]] = day;
- int q = query();
- // office is empty new day starts
- if (q == 0) {
- ans.pb(i+1);
- day++;
- }
- }
- // office is not empty
- int q = query();
- if (q != 0)
- cout << -1 << endl;
- else {
- cout << ans.size() << endl;
- for (int i= 0; i< ans.size(); ++i) {
- if (i) {
- cout << " " << ans[i]-ans[i-1];
- } else
- cout << ans[i];
- }
- cout << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement