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
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

bool comp(vector<long> v11, vector<long> v22) {
	vector<long>::iterator i1 = v11.begin();
	vector<long>::iterator i2 = v22.begin();

	i1++;
	i2++;

	while(i1 != v11.end()) {
		if((*i1) < (*i2)) return true;
		i1++;
		i2++;
	}
	return false;
}

int main() {
	vector<vector<long>> v;
	vector<long> v2;
	int n, m;
	cin >> n >> m;

	v2.push_back(1);
	for(int i = 0; i < n; i++) {
		long x;
		cin >> x;
		v2.push_back(x);
	}

	v.push_back(v2);
	vector<long> *nn = new vector<long>(v2);

	for(int i = 0; i < m-1; i++) {
		long p, x;
		cin >> p >> x;

		(*nn)[0] = i+2;
		(*nn)[p] = x;
		v.push_back(*nn);
		nn = new vector<long>(*nn);
	}

	sort(v.begin(), v.end(), comp);

	for(vector<vector<long>>::iterator it = v.begin(); it != v.end(); it++) cout << (*it)[0] << " ";


	return 0;
}