#include <algorithm> #include <cstdio> #include <map> #include <vector> using namespace std; #define LL long long #define PB push_back #define MAX_N 501000 #define MAX_M 501000 struct Change { int idx, from, to; int valid_before; }; int N, M; vector<int> aktualna; vector<vector<int> > prace; Change changes[MAX_M]; map<int, int> last_change_from[MAX_N]; void input(); void solve(); int main() { input(); solve(); for (auto& p : prace) { printf("%d ", p[N]); } printf("\n"); } void nowa_praca(vector<int>& act, int idx) { act.PB(idx); prace.PB(aktualna); act.pop_back(); } void input() { int in, p, x; scanf("%d %d", &N, &M); for (int i = 0; i < N; ++i) { scanf("%d", &in); aktualna.PB(in); } nowa_praca(aktualna, 1); for (int i = 2; i <= M; ++i) { scanf("%d %d", &p, &x); aktualna[p - 1] = x; nowa_praca(aktualna, i); } } void solve() { sort(prace.begin(), prace.end()); }
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 | #include <algorithm> #include <cstdio> #include <map> #include <vector> using namespace std; #define LL long long #define PB push_back #define MAX_N 501000 #define MAX_M 501000 struct Change { int idx, from, to; int valid_before; }; int N, M; vector<int> aktualna; vector<vector<int> > prace; Change changes[MAX_M]; map<int, int> last_change_from[MAX_N]; void input(); void solve(); int main() { input(); solve(); for (auto& p : prace) { printf("%d ", p[N]); } printf("\n"); } void nowa_praca(vector<int>& act, int idx) { act.PB(idx); prace.PB(aktualna); act.pop_back(); } void input() { int in, p, x; scanf("%d %d", &N, &M); for (int i = 0; i < N; ++i) { scanf("%d", &in); aktualna.PB(in); } nowa_praca(aktualna, 1); for (int i = 2; i <= M; ++i) { scanf("%d %d", &p, &x); aktualna[p - 1] = x; nowa_praca(aktualna, i); } } void solve() { sort(prace.begin(), prace.end()); } |