codeforces 631C. Report

时间:2023-01-10 14:31:31

题目链接

按题目给出的r, 维护一个递减的数列,然后在末尾补一个0。 比如样例给出的

4 2
1 2 4 3
2 3
1 2 递减的数列就是3 2 0, 操作的时候, 先变[3, 2), 然后变[2, 0), 具体的过程看代码。
 
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
#define pb(x) push_back(x)
#define ll long long
#define mk(x, y) make_pair(x, y)
#define lson l, m, rt<<1
#define mem(a) memset(a, 0, sizeof(a))
#define rson m+1, r, rt<<1|1
#define mem1(a) memset(a, -1, sizeof(a))
#define mem2(a) memset(a, 0x3f, sizeof(a))
#define rep(i, n, a) for(int i = a; i<n; i++)
#define fi first
#define se second
typedef pair<int, int> pll;
const double PI = acos(-1.0);
const double eps = 1e-;
const int mod = 1e9+;
const int inf = ;
const int dir[][] = { {-, }, {, }, {, -}, {, } };
const int maxn = 2e5+;
int st[], a[maxn], b[maxn], c[maxn];
int main()
{
int n, m, sign, pos;
cin>>n>>m;
for(int i = ; i<=n; i++)
scanf("%d", &a[i]);
int r = ;
for(int i = ; i<m; i++) {
scanf("%d%d", &sign, &pos);
while(r>&&pos>=st[r-])
r--;
st[r] = pos, b[r] = sign;
r++;
}
st[r++] = ;
int l = , rr = st[];
for(int i = ; i<=n; i++)
c[i] = a[i];
sort(c+, c++rr);
for(int i = ; i<r; i++) {
for(int j = st[i-]; j>st[i]; j--) {
a[j] = (b[i-] == )?c[l++]:c[rr--];
}
}
for(int i = ; i<=n; i++)
printf("%d ", a[i]);
return ;
}