Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- vector<pair<int,int>>all;
- int n;
- cin >> n;
- int prom;
- int last = -1;
- int verx = -1;
- bool was = false;
- vector <int>answ;
- for (int i = 1; i <= n; i++)
- {
- cin >> prom;
- if (prom > 0)
- {
- last = i-1;
- if (!was)
- {
- verx = last;
- }
- was = 0;
- }
- else
- {
- if (prom == 0)
- {
- for (int j = i-2; j >= 0; j--)
- {
- if (all[j].first > 0&&all[j].first!=0)
- all[j].second *= 2;
- }
- }
- else
- {
- was = 1;
- all[verx].second--;
- answ.push_back(all[verx].first);
- bool u = false;
- if (all[verx].second == 0)
- u = 1;
- bool p = false;
- for (int j = verx - 1; j >= 0; j--)
- {
- if (all[j].first > 0 && all[j].first != 0)
- {
- if (u)
- last = j;
- verx = j;
- p = 1;
- break;
- }
- }
- if (!p)
- if(!u)
- verx = last;
- else
- {
- verx = -1;
- last = -1;
- }
- }
- }
- all.push_back({ prom, 1 });
- }
- for (int i = 0; i < answ.size(); i++)
- {
- cout << answ[i] << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement