fork(2) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define file(name) if (fopen(name".INP", "r")){freopen(name".INP", "r", stdin); freopen(name".OUT", "w", stdout);}
  5.  
  6. const int maxn = 1e6 + 7;
  7.  
  8. int n, k, st[int(log2(maxn)) + 1][maxn];
  9.  
  10. int get(int l, int r){
  11. int LOG = log2(r - l + 1);
  12. return min(st[LOG][l], st[LOG][r - (1 << LOG) + 1]);
  13. }
  14.  
  15. void solution(){
  16.  
  17. cin >> n >> k;
  18. for (int i = 1; i <= n; i++) cin >> st[0][i];
  19. for (int i = 1; (1 << i) <= n; i++)
  20. for (int j = 1; j <= n - (1 << i) + 1; j++)
  21. st[i][j] = min(st[i-1][j], st[i-1][j + (1 << (i - 1))]);
  22. for (int i = 1; i <= n - k + 1; i++){
  23. int l = i, r = i + k - 1;
  24. cout << get(l, r) << "\n";
  25. }
  26.  
  27. }
  28.  
  29. signed main(){
  30. ios_base::sync_with_stdio(0);
  31. cin.tie(0); cout.tie(0);
  32.  
  33. file("TEST");
  34.  
  35. int test = 1;
  36. while (test --> 0) solution();
  37.  
  38. return 0;
  39. }
Runtime error #stdin #stdout 0.01s 5552KB
stdin
Standard input is empty
stdout
Standard output is empty