#include <bits/stdc++.h>
using namespace std;
#define ios ios::sync_with_stdio(0)
#define endl '\n'
#define int long long
#define ar array<int, 2>
#define arr array<int, 3>
const int N = 2e5 + 5, M = 2 * N;
const int inf = 0x3f3f3f3f3f3f3f3f;
int mod = 998244353; //1e9+7;
int t, n, m, k;
ar st[N];
signed main()
{
ios;
#ifdef DEBUG
freopen("../1.in", "r", stdin);
#endif
// 这题还是可以刷的。
// 就是实现技巧如果好的话。。会很舒服。。
// 虽然我自己做出来的哈哈哈。。
cin >> n >> m;
int a[n + 1], b[n + 1];
for (int i = 1; i <= n; ++i)
cin >> a[i], b[i] = a[i];
int l = 0;
while (m--)
{
int x, y;
cin >> x >> y;
while (l && st[l][1] <= y)
l--;
st[++l] = {x, y};
}
sort(a + 1, a + st[1][1] + 1);
int x = 1, y = st[1][1];
st[l + 1][1] = 0; //这个很细节。l在进退的时候 这个位置是有可能被污染过的。
// 后面我们要用到。。所以要给他稳定的重置为0
for (int i = 1; i <= l; ++i)
{
auto &[u, v] = st[i];
for (int j = v; j > st[i + 1][1]; j--)
if (u == 1)
b[j] = a[y--];
else
b[j] = a[x++];
}
for (int i = 1; i <= n; ++i)
cout << b[i] << " ";
};
1422C - Bargain | 1611F - ATM and Students |
660A - Co-prime Array | 1692F - 3SUM |
1470A - Strange Birthday Party | 190D - Non-Secret Cypher |
1721B - Deadly Laser | 1721C - Min-Max Array Transformation |
1721A - Image | 1180C - Valeriy and Deque |
557A - Ilya and Diplomas | 1037D - Valid BFS |
1144F - Graph Without Long Directed Paths | 1228A - Distinct Digits |
355B - Vasya and Public Transport | 1230A - Dawid and Bags of Candies |
1530A - Binary Decimal | 1472D - Even-Odd Game |
441C - Valera and Tubes | 1328E - Tree Queries |
265A - Colorful Stones (Simplified Edition) | 296A - Yaroslav and Permutations |
967B - Watering System | 152A - Marks |
1398A - Bad Triangle | 137A - Postcards and photos |
1674D - A-B-C Sort | 334A - Candy Bags |
855A - Tom Riddle's Diary | 1417A - Copy-paste |