Advertisement
Josif_tepe

Untitled

Feb 3rd, 2023
828
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. #include <ext/pb_ds/assoc_container.hpp>
  4. #include <ext/pb_ds/tree_policy.hpp>
  5. using namespace __gnu_pbds;
  6. using namespace std;
  7. typedef long long ll;
  8.  
  9.  
  10. typedef tree <pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
  11.  
  12. int main() {
  13.     ios_base::sync_with_stdio(false);
  14.     ordered_set o_set;
  15.     int n, k;
  16.     cin >> n >> k;
  17.     vector<int> v(n);
  18.     for(int i = 0; i < n; i++) {
  19.         cin >> v[i];
  20.         o_set.insert(make_pair(v[i], i));
  21.        
  22.         if(i >= k) {
  23.             o_set.erase(o_set.lower_bound(make_pair(v[i - k], 0)));
  24.         }
  25.         if(i >= k - 1) {
  26.             cout << (*o_set.find_by_order((k - 1) / 2)).first << " ";
  27.         }
  28.     }
  29.    
  30.     return 0;
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement