Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int t,n,s[20][100010],k,tam[20],topo,inicio,fim;
- int elev(int x){
- int r=1;
- for(int f=0;f<x;f++) r*=2;
- return r;
- }
- int busc(int camada,int pos){
- if(inicio>((pos+1)*elev(camada))-1 || fim<pos*elev(camada) || s[camada][pos]==0) return 0;
- if(inicio<=pos*elev(camada) && fim>=((pos+1)*elev(camada))-1) return s[camada][pos];
- return max(busc(camada-1,2*pos),busc(camada-1,(2*pos)+1));
- }
- int main(){
- scanf("%d", &t);
- for(int i=0;i<t;i++){
- scanf("%d %d", &n, &k);
- for(int j=0;j<n;j++) scanf("%d", &s[0][j]);
- tam[0]=n;
- s[0][n]=0;
- for(topo=0;tam[topo]>1;topo++){
- 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]);
- s[topo+1][tam[topo+1]]=0;
- }
- for(int j=0;j<n-k;j++){
- inicio=j;
- fim=j+k-1;
- printf("%d ", busc(topo,0));
- }
- inicio=n-k;
- fim=n-1;
- printf("%d\n", busc(topo,0));
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement