#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int n, m;
struct student
{
vector<int> t;
int id;
};
bool cmp(student a, student b)
{
for (int i = 0; i < n; i++)
{
if (a.t[i] < b.t[i]) return a.t[i] < b.t[i];
}
return a.id < b.id;
}
vector<student> tab;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
student st;
st.t.clear();
st.id = 0;
for (int i = 1; i <= m; i++)
{
st.id = i;
tab.push_back(st);
}
for (int i = 0; i < n; i++)
{
int v;
cin >> v;
tab[0].t.push_back(v);
}
for (int i = 1; i < m; i++)
{
for (int j = 0; j < n; j++) tab[i].t.push_back(tab[i-1].t[j]);
int p, x;
cin >> p >> x;
tab[i].t[p-1] = x;
}
sort(tab.begin(), tab.end(), cmp);
for (int i = 0; i < m; i++) cout << tab[i].id << " ";
cout << "\n";
}
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 | #include <iostream> #include <algorithm> #include <vector> using namespace std; int n, m; struct student { vector<int> t; int id; }; bool cmp(student a, student b) { for (int i = 0; i < n; i++) { if (a.t[i] < b.t[i]) return a.t[i] < b.t[i]; } return a.id < b.id; } vector<student> tab; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; student st; st.t.clear(); st.id = 0; for (int i = 1; i <= m; i++) { st.id = i; tab.push_back(st); } for (int i = 0; i < n; i++) { int v; cin >> v; tab[0].t.push_back(v); } for (int i = 1; i < m; i++) { for (int j = 0; j < n; j++) tab[i].t.push_back(tab[i-1].t[j]); int p, x; cin >> p >> x; tab[i].t[p-1] = x; } sort(tab.begin(), tab.end(), cmp); for (int i = 0; i < m; i++) cout << tab[i].id << " "; cout << "\n"; } |
English