Codeforces 631C Report

来源:互联网 发布:linux添加sgid权限 编辑:程序博客网 时间:2024/05/21 19:21

题意:

给出一个2e5的数组,有两种操作

1.对【 1 , X 】升序排列

2.对【 1 , X 】序排列

求最终的数组

思路:

单调栈维护有效操作区间后,按序填入每个位置上的数即可。

代码:

#include <bits/stdc++.h>using namespace std;const int MAXN = 2e5 + 7;const int INF = 0x3f3f3f3f;int a[MAXN],b[MAXN],c[MAXN],aa[MAXN];int main(){int n, m, top;while (cin >> n >> m){for (int i = 1; i <= n; i++) cin >> a[i], aa[i] = a[i];b[0] = INF, top = 0;for (int i = 0; i < m; i++) {int x, y;cin >> x >> y;while (b[top] <= y) {top--;}top++;b[top] = y;c[top] = x;}b[top + 1] = 0;sort(aa + 1, aa + b[1] + 1);int pos = b[1], l = 1, r = b[1];for (int i = 1; i <= top; i++) {int len = b[i] - b[i + 1];if (c[i] == 1) {for (int j = 0; j < len; j++) {a[pos--] = aa[r--];}}else {for (int j = 0; j < len; j++) {a[pos--] = aa[l++];}}}for (int i = 1; i <= n; i++) cout << a[i] << ' ';cout << endl;}//system("pause");}


原创粉丝点击