Advertisement
a53

SCLM2

a53
Feb 7th, 2017
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int N, v[100005], P[100005], Q[100005], cnt;
  4.  
  5. int main(void)
  6. {
  7. int i, l, r, m, x;
  8.  
  9. freopen("sclm2.in", "r", stdin);
  10. freopen("sclm2.out", "w", stdout);
  11.  
  12. scanf("%d", &N);
  13. for (i = 1; i <= N; ++i)
  14. scanf("%d", &v[i]);
  15. for (i = 1; i <= N; ++i)
  16. {
  17. if (v[i] >= P[cnt])
  18. P[++cnt] = v[i], Q[i] = cnt;
  19. else
  20. {
  21. for (l = 1, r = cnt, x = cnt; l <= r; )
  22. {
  23. m = (l + r) / 2;
  24. if (P[m] <= v[i]) l=m+1;
  25. else x = m, r=m-1;
  26. }
  27. P[x] = v[i]; Q[i] = x;
  28. }
  29. }
  30.  
  31. printf("%d\n", cnt);
  32. return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement