intmain(){ cin >> n >> m; for (int i = 1; i <= n; ++i) scanf("%d", &a[i]); for (int i = 1; i <= m; ++i) scanf("%d", &b[i]); int j = 0; for (int i = 1; i <= m; ++i) { while (j + 1 <= b[i]) Q2.push(a[++j]); while (Q1.empty() || Q2.top() < Q1.top() || Q1.size() < i) { if (Q2.empty()) break; Q1.push(Q2.top()), Q2.pop(); } while (Q1.size() > i) Q2.push(Q1.top()), Q1.pop(); printf("%d\n", Q1.top()); } return0; }