Sreekar_0125

Untitled

Apr 7th, 2024
1,057
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. bool ok(int m, int mx) {
  2.     // map<int, int> hash;
  3.     vi hash(N + 1, 0);
  4.     f(i, 0, m) hash[v[i]]++;
  5.     set<int> st;
  6.     f(i, 0, n + 5)
  7.     {
  8.         if(hash[i] == 0)
  9.         {  
  10.             st.insert(i);
  11.         }
  12.     }
  13.  
  14.     if(*st.begin() == mx) return true;
  15.     f(i, m, n)
  16.     {
  17.         hash[v[i]]++;
  18.         if(st.find(v[i]) != st.end()) st.erase(v[i]);
  19.         hash[v[i - m]]--;
  20.         if(hash[v[i - m]] == 0)
  21.         {
  22.             st.insert(v[i - m]);
  23.         }
  24.    
  25.         if(*st.begin() == mx) return true;
  26.     }
  27.     return false;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment