fork download
  1. #include <stdio.h>
  2. void scan_int(int *x){
  3. register int c=getchar_unlocked();
  4. *x=0;
  5. for( ; (c<48 || c>57); c = getchar_unlocked());
  6. for( ; (c>47 && c<58); c = getchar_unlocked()) *x = (*x << 1) + (*x << 3) + c - 48;
  7. }
  8. void getRange(int height[], int n){
  9. int min_index=0,temp,i,j;
  10. printf("1 ");
  11. for(i=1; i<n; i++){
  12. if(height[i]>=height[i-1]){
  13. temp=i-min_index;
  14. j=min_index-1;
  15. while(j>=0 && height[i]>=height[j]){ temp++;j--; }
  16. printf("%d ",temp+1);
  17. }else{
  18. printf("1 ");
  19. min_index=i;
  20. }
  21. }
  22. printf("\n");
  23. }
  24. int main()
  25. {
  26. int t,n,height[1000000],i,j;
  27. scan_int(&t);
  28. while(t--){
  29. scan_int(&n);
  30. for(i=0; i<n; i++)
  31. scan_int(&height[i]);
  32. getRange(height,n);
  33. }
  34. return 0;
  35. }
Success #stdin #stdout 0s 14096KB
stdin
1
7
11 12 6 7 6 7 8
stdout
1 2 1 2 1 4 5