Advertisement
Guest User

Untitled

a guest
Jan 20th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int t,n,s[20][100010],k,tam[20],topo,inicio,fim;
  6.  
  7. int elev(int x){
  8. int r=1;
  9. for(int f=0;f<x;f++) r*=2;
  10. return r;
  11. }
  12.  
  13. int busc(int camada,int pos){
  14. if(inicio>((pos+1)*elev(camada))-1 || fim<pos*elev(camada) || s[camada][pos]==0) return 0;
  15. if(inicio<=pos*elev(camada) && fim>=((pos+1)*elev(camada))-1) return s[camada][pos];
  16. return max(busc(camada-1,2*pos),busc(camada-1,(2*pos)+1));
  17. }
  18.  
  19. int main(){
  20. scanf("%d", &t);
  21. for(int i=0;i<t;i++){
  22. scanf("%d %d", &n, &k);
  23. for(int j=0;j<n;j++) scanf("%d", &s[0][j]);
  24. tam[0]=n;
  25. s[0][n]=0;
  26. for(topo=0;tam[topo]>1;topo++){
  27. for(tam[topo+1]=0;tam[topo+1]<(tam[topo]+1)/2;tam[topo+1]++) s[topo+1][tam[topo+1]]=max(s[topo][2*tam[topo+1]],s[topo][(2*tam[topo+1])+1]);
  28. s[topo+1][tam[topo+1]]=0;
  29. }
  30. for(int j=0;j<n-k;j++){
  31. inicio=j;
  32. fim=j+k-1;
  33. printf("%d ", busc(topo,0));
  34. }
  35. inicio=n-k;
  36. fim=n-1;
  37. printf("%d\n", busc(topo,0));
  38. }
  39. return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement