Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- int sz = 1, a[1000001];
- pair<int, int> kol[1000001], ar[1000001];
- int fun(int x, int ind)
- {
- int y = 0;
- if(a[ind] <= x)
- {
- if(ar[ind].second == 0)
- {
- ar[ind].second = sz;
- a[sz] = x;
- sz++;
- }else
- {
- y = fun(x, ar[ind].second);
- }
- return y + kol[ind].first + 1;
- }else
- {
- kol[ind].first++;
- if(ar[ind].first == 0)
- {
- ar[ind].first = sz;
- a[sz] = x;
- sz++;
- return 0;
- }else
- {
- y = fun(x, ar[ind].first);
- }
- return y;
- }
- }
- int main()
- {
- int n;
- cin >> n;
- for(int i = 1; i <= n; i++)
- {
- int x;
- cin >> x;
- cout << fun(x, 0) << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement