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
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
#include <algorithm>
#include <cstdio>
#include <map>
#include <set>
#include <vector>

#define PRA_BRUT_ENABLED

using namespace std;

static const int N = 500000;
static const int M = 500000;

static int t[N + 1];
static int p[M];
static int x[M];
static int u[M];
static map<int, int> s[M];

static bool compare(const int i, const int j)
{
    if (i == j)
    {
        return false;
    }

    for(int k = 0; k < s[i].size(); k++)
    {
        const int r = s[i][k] - s[j][k];

        if (r)
        {
            return r < 0;
        }
    }

    return i < j;
}

static void readTemperatures(int t[], const int n)
{
    for(int i = 1; i <= n; i++)
    {
        scanf("%d", t + i);
    }
}

static void readChanges(int p[], int x[], const int m)
{
    for(int i = 1; i < m; i++)
    {
        scanf("%d%d", p + i, x + i);
     }
}

static void buildStates(int u[], map<int, int> s[], int t[], const int p[], const int x[], const int m)
{
    const set<int> dset(p + 1, p + m);
    const vector<int> d(dset.begin(), dset.end());

    for(int i = 0; i < d.size(); i++)
    {
        s[0][i] = t[d[i]];
    }

    u[0] = 0;

    for(int i = 1; i < m; i++)
    {
        u[i] = i;
        t[p[i]] = x[i];

        for(int j = 0; j < d.size(); j++)
        {
            s[i][j] = t[d[j]];
        }
    }
}

static void print(const int u[], const int m)
{
    for(int i = 0; i < m; i++)
    {
        printf("%d ", u[i] + 1);
    }
    printf("\n");
}

#ifdef PRA_BRUT_ENABLED
int main()
{
    int n, m;
    scanf("%d%d", &n, &m);

    readTemperatures(t, n);
    readChanges(p, x, m);
    buildStates(u, s, t, p, x, m);
    sort(u, u + m, compare);
    print(u, m);

    return 0;
}
#endif