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
#include <bits/stdc++.h>
using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back

const int ac = 5e5 + 5;
int A[ac];
pair<vector<int>, int> B[ac];

bool comp(const pair<vector<int>, int>& P, const pair<vector<int>, int>& Q)
{
	for (int i = 0; i < P.x.size(); i++) if (P.x[i] < Q.x[i]) return 1;
		else if (P.x[i] > Q.x[i]) return 0;
	return P.y < Q.y;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, m; cin >> n >> m;
	for (int i = 0; i < n; i++) cin >> A[i];
	B[0].x.resize(n);
	for (int i = 0; i < n; i++) B[0].x[i] = A[i];
	for (int j = 1; j < m; j++)
	{
		B[j].y = j;
		B[j].x.resize(n);
		int a, b; cin >> a >> b;
		A[a - 1] = b;
		for (int i = 0; i < n; i++) B[j].x[i] = A[i];
	}
	sort(B, B + m, comp);
	for (int i = 0; i < m; i++) cout << B[i].y + 1 << ' ';
	cout << '\n';
}