Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define DIM 100005
- int a[DIM], lung[DIM], best[DIM];
- int n, max, poz;
- void read()
- {
- int i;
- scanf("%d", &n);
- for (i = n; i; --i)
- scanf("%d", &a[i]);
- }
- int cbin(int st, int dr, int x)
- {
- int mij;
- for (; st <= dr; )
- {
- mij = (st + dr) / 2;
- if (a[lung[mij]] >= a[x] && (a[lung[mij + 1]] <= a[x] || mij + 1 > max))
- return mij;
- else if (a[lung[mij]] >= a[x])
- st = mij + 1;
- else
- dr = mij - 1;
- }
- return 0;
- }
- void solve()
- {
- int i, j;
- for (i = 1; i <= n; ++i)
- {
- j = cbin(1, max, i);
- if (j == max || a[i] >= a[lung[j + 1]])
- {
- lung[j + 1] = i;
- best[n - i + 1] = j + 1;
- if (j + 1 > max) max = j + 1;
- }
- }
- max = best[n];
- for (i = n - 1; i; --i)
- if (best[i] < max)
- best[i] = max;
- else
- max = best[i];
- for (i = 1; i <= n; i++)
- printf("%d\n", best[i]);
- }
- int main()
- {
- freopen("in.txt", "r", stdin);
- freopen("out.txt", "w", stdout);
- read();
- solve();
- return 0;
- }
Add Comment
Please, Sign In to add comment