usingnamespacestd; usingnamespace FAST_IO; const ll mod = 1e9 + 7; constint INF = 0x3f3f3f3f; const ll INF_LL = 0x3f3f3f3f3f3f3f3f; constdouble eps = 1e-5; constint maxn = 1e3 + 10; constint maxm = 1e5 + 10; int t, n, m, k; int a[maxn]; int order[maxn]; // 记录每个数字填入到了哪个位置,这样方便的找前一个或后一个位置 bool st[maxn]; intmain() { // #define COMP_DATA #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); #endif ios::sync_with_stdio(false); cin.tie(0); cin >> n >> m >> k; bool flag = false; for (int i = 1; i <= m; i++) { cin >> a[i]; if (a[i] == 1) { flag = true; } } for (int i = 1, x, y; i <= k; i++) { cin >> x >> y; order[x] = y; st[y] = true; if (x == 1) { cout << y << endl; return0; } }
if (flag) { // 1在m中,从前往后摆放 int index = 1; for (int i = 1; i <= m; i++) { while (st[index]) index++; // 这个m中的a[i]也在k中 if (order[a[i]] != 0) { index = order[a[i]]; } else { order[a[i]] = index; st[index] = true; if (a[i] == 1) { cout << index << endl; return0; } } } } else { int index = n; for (int i = m; i >= 1; i--) { while (st[index]) index--; if (order[a[i]] != 0) { index = order[a[i]]; } else { st[index] = true; order[a[i]] = index; } }
for (int i = 1; i <= n; i++) { if (!st[i]) { cout << i << endl; return0; } } } return0; }