1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);  
  int n, m;
  cin >> n >> m;
  vector< vector<int> > XD; 
  XD.push_back(vector<int>(n + 1));
  for(int i = 0; i < n; i++) {
    cin >> XD[0][i];
  }
  XD[0][n] = 1;
  for(int j = 0; j < m - 1; j++) {
    int p, x;
    cin >> p >> x; p--;
    XD.push_back(XD[j]);
    XD[j+1][p] = x;
    XD[j+1][n]++;
  }
  sort(XD.begin(), XD.end());
  for(int j = 0; j < m; j++) {
    cout << XD[j][n] << ' ';
  }
  cout << '\n';
  return 0;
}