Advertisement
dmkozyrev

acmp.ru 647

Apr 30th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. struct Set {
  7.     vector<int> a;
  8.    
  9.     Set(int n) : a(n, 0) {}
  10.    
  11.     int mark(int index) {
  12.         for (int i = index; i < (int)a.size(); i |= i+1)
  13.             a[i]++;
  14.     }
  15.    
  16.     int countDown(int index) {
  17.         int s = 0;
  18.         for (int i = index; i >= 0; i &= i+1, --i)
  19.             s += a[i];
  20.         return s;
  21.     }
  22. };
  23.  
  24. int main() {
  25. //  freopen("in.txt", "r", stdin);
  26. //  freopen("out.txt", "w", stdout);
  27.     int N, M;
  28.     scanf("%d %d", &N, &M);
  29.     vector<int> pos (N+1, 0);
  30.     Set set(N+M);
  31.     for (int i = 1; i <= N; ++i)
  32.         pos[i] = M+i-1;
  33.    
  34.     for (int i = 0, s = M-1, q; i < M; ++i) {
  35.         scanf("%d", &q);
  36.         printf("%d ", pos[q]-set.countDown(pos[q])-s);
  37.         set.mark(pos[q]);
  38.         pos[q] = s--;
  39.     }
  40.        
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement