We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
#include<bits/stdc++.h>#define FOR(i,s,e) for(long long i=static_cast<long long>(s);i<static_cast<long long>(e);i++)#define ppi pair<pair<int,int>,int>#define pi pair<int,int>#define pb push_back#define S second#define F firsttypedeflonglongll;usingnamespacestd;vector<int>tree;voidbuild(vector<int>&ar){intn=ar.size();tree.resize(n<<1);for(inti=0;i<n;i++){tree[i+n]=ar[i];}for(inti=n-1;i>0;i--){tree[i]=max(tree[i<<1],tree[i<<1|1]);}}voidchange(intind,intval){intn=tree.size()/2;tree[n+ind]=val;for(inti=(n+ind)/2;i>0;i/=2){tree[i]=tree[i*2]+tree[i*2+1];}}intquery(intl,intr){intans=0,n=tree.size()/2;for(l=l+n,r=r+n;l<r;l/=2,r/=2){if(r%2)ans=max(ans,tree[--r]);if(l%2)ans=max(ans,tree[l++]);}returnans;}voidf(){intn,k;cin>>n>>k;vector<int>v(n);FOR(i,0,n)cin>>v[i];build(v);for(inti=0;i<n-k+1;i++){cout<<query(i,i+k)<<" ";}}intmain(){ios_base::sync_with_stdio(false);cin.tie(nullptr);intt=1;cin>>t;while(t--){f();cout<<endl;}return0;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Deque-STL
You are viewing a single comment's thread. Return to all comments →
here's my c++ 20 code: