Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define _test int _TEST; cin>>_TEST; while(_TEST--)
- #define pb push_back
- int main()
- {
- _test
- {
- int n, k;
- cin>>n>>k;
- vector<int> a(n);
- for(auto &e: a) cin>>e;
- vector<vector<int>> pos(k);
- set<int> st;
- for(int i=0; i<n; i++)
- {
- pos[a[i]-1].pb(i);
- st.insert(i);
- }
- vector<int> ans(k);
- for(int c=0; c<k; c++)
- {
- if(!pos[c].size()) continue;
- ans[c] = 2*(*st.rbegin()-*st.begin()+1);
- for(auto e: pos[c])
- st.erase(e);
- }
- for(auto e: ans) cout<<e<<" ";
- cout<<"\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement