fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define gc getchar_unlocked
  4. #define fo(i,n) for(i=0;i<n;i++)
  5. #define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
  6. #define ll long long
  7. #define si(x) scanf("%d",&x)
  8. #define sl(x) scanf("%lld",&x)
  9. #define ss(s) scanf("%s",s)
  10. #define pi(x) printf("%d\n",x)
  11. #define pl(x) printf("%lld\n",x)
  12. #define ps(s) printf("%s\n",s)
  13. #define pb push_back
  14. #define mp make_pair
  15. #define F first
  16. #define S second
  17. #define all(x) x.begin(), x.end()
  18. #define clr(x) memset(x, 0, sizeof(x))
  19. #define sortall(x) sort(all(x))
  20. #define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
  21. #define PI 3.1415926535897932384626
  22. typedef pair<int, int> pii;
  23. typedef pair<ll, ll> pl;
  24. typedef vector<int> vi;
  25. typedef vector<ll> vl;
  26. typedef vector<pii> vpii;
  27. typedef vector<pl> vpl;
  28. typedef vector<vi> vvi;
  29. typedef vector<vl> vvl;
  30. int mpow(int base, int exp);
  31. void ipgraph(int m);
  32. void dfs(int u, int par);
  33. const int mod = 1000000007;
  34. const int N = 3e5, M = N;
  35. //=======================
  36.  
  37. vi A, inc;
  38. //Input: Array A
  39. //Output: inc[i] = max len K, such that
  40. //1. A[i],A[i+1],...,A[i+K-1] represents 1,2,3,...K
  41. //2. A[i]>=1, A[i+1] >= 2, .... , A[i+K-1] >= K
  42. void build(vi &inc){
  43. inc.clear();
  44. int i, n = A.size();
  45. fo(i, n) A[i] -= i, inc.pb(1);
  46. int j = 0;
  47. int lim = 1;
  48. fo(i, n){
  49. while(j<n and A[j] >= lim) j++;
  50. inc[i] = j-i;
  51. cout << inc[i] << " ";
  52. lim--;
  53. }
  54. }
  55. int main()
  56. {
  57. ios_base::sync_with_stdio(false);
  58. cin.tie(NULL);
  59. int i,k,j,t,n;
  60. cin >> n;
  61. fo(i, n) cin >> k, A.pb(k);
  62. build(inc);
  63. return 0;
  64. }
  65.  
  66.  
Success #stdin #stdout 0s 15232KB
stdin
5 
1 2 3 3 3 
stdout
3 3 3 2 1