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

using namespace std;

int **t, *d;
int n;

bool Por(int a, int b)
{
    for(int i=0; i < n; i++)
    {
        if(t[a][i] > t[b][i])
            return false;
        else if(t[a][i] < t[b][i])
            return true;
    }
    if(a < b)
        return true;
    return false;
}

int main()
{
    ios_base::sync_with_stdio(0);
    int m;
    cin >> n >> m;
    t = new int *[m];
    d = new int[m];
    for(int i=0; i < m; i++)
    {
        t[i] = new int[n];
        d[i] = i;
    }
    for(int i=0; i < n; i++)
    {
        cin >> t[0][i];
    }
    for(int i=1; i < m; i++)
    {
        for(int j=0; j < n; j++)
        {
            t[i][j] = t[i-1][j];
        }
        int p, x;
        cin >> p >> x;
        t[i][p-1] = x;
    }
    sort(d, d+m, Por);
    for(int i=0; i < m; i++)
    {
        cout << d[i]+1 << " ";
    }

    return 0;
}