Advertisement
MinhNGUYEN2k4

compress v2

May 24th, 2021
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.24 KB | None | 0 0
  1. //int a[N];
  2.  
  3. void compress()
  4. {
  5.     vector<int> b(a+1,a+1+n);
  6.     sort(b.begin(),b.end());
  7.     for(int i=1; i<=n; i++)
  8.     {
  9.         int x = a[i];
  10.         int k = lower_bound(b.begin(),b.end(),x)-b.begin()+1;
  11.         a[i] = k;
  12.     }
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement