Advertisement
Ankit_132

C

Sep 18th, 2023
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1.  
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. #define ll     long long
  7. #define _test   int _TEST; cin>>_TEST; while(_TEST--)
  8. #define pb     push_back
  9.  
  10. int main()
  11. {
  12.     _test
  13.     {
  14.         int n, k;
  15.         cin>>n>>k;
  16.  
  17.         vector<int> a(n);
  18.         for(auto &e: a)     cin>>e;
  19.  
  20.         vector<vector<int>> pos(k);
  21.         set<int> st;
  22.  
  23.         for(int i=0; i<n; i++)
  24.         {
  25.             pos[a[i]-1].pb(i);
  26.             st.insert(i);
  27.         }
  28.  
  29.         vector<int> ans(k);
  30.  
  31.         for(int c=0; c<k; c++)
  32.         {
  33.             if(!pos[c].size())      continue;
  34.  
  35.             ans[c] = 2*(*st.rbegin()-*st.begin()+1);
  36.  
  37.             for(auto e: pos[c])
  38.                 st.erase(e);
  39.         }
  40.  
  41.         for(auto e: ans)        cout<<e<<" ";
  42.         cout<<"\n";
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement