#include <cstdio> #include <algorithm> using namespace std; class Data{ public: int *value; int index; Data(int index){ this->index = index; value = new int[this->size]; } static int size; }; int Data::size; Data **tab; bool compare(Data *item1, Data *item2){ for(int i = 0; i < Data::size; ++i){ if(item1->value[i] < item2->value[i]){ return true; } if(item2->value[i] > item2->value[i]){ return false; } } return item1->index < item2->index; } int main(){ int n, m; scanf("%d %d", &n, &m); Data::size = n; tab = new Data*[m]; for(int i = 0; i < m; ++i){ tab[i] = new Data(i+1); } for(int i = 0; i < n; ++i){ int a; scanf("%d ", &a); tab[0]->value[i] = a; } for(int i = 0; i < m-1; ++i){ int a, b; scanf("%d %d", &a, &b); for(int j = 0; j < n; ++j){ tab[i+1]->value[j] = tab[i]->value[j]; } tab[i+1]->value[a-1] = b; } sort(tab, tab+m, compare); for(int i = 0; i < m; ++i){ printf("%d ", tab[i]->index); } return 0; }
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 | #include <cstdio> #include <algorithm> using namespace std; class Data{ public: int *value; int index; Data(int index){ this->index = index; value = new int[this->size]; } static int size; }; int Data::size; Data **tab; bool compare(Data *item1, Data *item2){ for(int i = 0; i < Data::size; ++i){ if(item1->value[i] < item2->value[i]){ return true; } if(item2->value[i] > item2->value[i]){ return false; } } return item1->index < item2->index; } int main(){ int n, m; scanf("%d %d", &n, &m); Data::size = n; tab = new Data*[m]; for(int i = 0; i < m; ++i){ tab[i] = new Data(i+1); } for(int i = 0; i < n; ++i){ int a; scanf("%d ", &a); tab[0]->value[i] = a; } for(int i = 0; i < m-1; ++i){ int a, b; scanf("%d %d", &a, &b); for(int j = 0; j < n; ++j){ tab[i+1]->value[j] = tab[i]->value[j]; } tab[i+1]->value[a-1] = b; } sort(tab, tab+m, compare); for(int i = 0; i < m; ++i){ printf("%d ", tab[i]->index); } return 0; } |