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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <bits/stdc++.h>

using namespace std;


struct Change {
  int i, v;
};


struct Comparator {
  vector<int> &A;
  vector<Change> &C;
  int step;
  vector< vector<int> > S;
  
  Comparator(vector<int> &_A, vector<Change> &_C): A(_A), C(_C) {
    int n = A.size();
    int m = C.size() + 1;
    int instances = 300000000 / 4 / n - 1;
    step = max(1, m / instances);
    instances = (m + step - 1) / step;
    S.reserve(instances);
    
    vector<int> T(A);
    for(int i = 0; i < m - 1; i++) {
      if(i % step == 0) S.push_back(T);
      T[C[i].i] = C[i].v;
    }
  }
  
  int cmp(int p, int q) const {
    if(p == q) return 0;
    if(p >  q) return -cmp(q, p);
    
    int s0 = p / step;
    int i0 = s0 * step;
    vector<int> P(S[s0]);
    for(int i = i0; i < p; i++) P[C[i].i] = C[i].v;
    
    vector<int> Q(P);
    set<int> ch;
    for(int i = p; i < q; i++) {
      Q[C[i].i] = C[i].v;
      ch.insert(C[i].i);
    }
    for(set<int>::const_iterator it = ch.begin(); it != ch.end(); it++) {
      if(P[*it] != Q[*it]) return (P[*it] < Q[*it] ? -1 : 1);
    }
    return 0;
  }
  
  bool operator()(int p, int q) const {
    return cmp(p, q) < 0;
  }
};


int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  int n, m;
  cin >> n >> m;
  
  vector<int> A(n);
  for(int i = 0; i < n; i++) cin >> A[i];
  
  vector<Change> C(m-1);
  for(int i = 0; i < m-1; i++) {
    cin >> C[i].i >> C[i].v;
    C[i].i--;
  }
  
  Comparator cmp(A, C);
  vector<int> Z(m);
  for(int i = 0; i < m; i++) Z[i] = i;
  sort(Z.begin(), Z.end(), cmp);
  for(int i = 0; i < m; i++) cout << Z[i] + 1 << ' ';
  cout << '\n';
  
  return 0;
}