Advertisement
ec1117

Untitled

Nov 21st, 2020
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. Greedy Subseqs 11/21
  2.  
  3. LazySegTree<int,MX> L;
  4. int n,k,lef[MX];
  5. vi a;
  6. vpi v;
  7.  
  8. int main() {
  9.     // you should actually read the stuff at the bottom
  10.     setIO(); re(n,k); a.resz(n); re(a);
  11.     F0R(i,n) {
  12.         int l = i;
  13.         while (sz(v) && a[v.back().s] < a[i]) {
  14.             l = v.back().f;
  15.             v.pop_back();
  16.         }
  17.         lef[i] = l;
  18.         v.pb({l,i});
  19.     }
  20.     F0R(i,n) {
  21.         L.upd(lef[i],i,-1);
  22.         if (i >= k-1) pr(-L.qmin(i-(k-1),i)," ");
  23.     }
  24.     // you should actually read the stuff at the bottom
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement