import java.util.Arrays;
import java.util.Scanner;
public class 双向排序3 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
operation [] operations = new operation[m+1];
int [] num = new int[n+1]; //从索引1开始
int top = 0;
for (int i = 1; i <= m; i++) {
int p = sc.nextInt();
int q = sc.nextInt();
/**
* 9 5
* 0 9
* 1 2
* 0 7
* 1 4
* 0 5
*/
//降序数据
if (p == 0) {
while (top > 0 && operations[top].p == 0) {
q = Math.max(operations[top--].q, q);
}
while (top - 2 >= 0 && operations[top-1].q <= q) {
top -= 2;
}
operations[++top] = new operation(0, q);
} else if (top != 0) {
while (top > 0 && operations[top].p == 1) {
q = Math.min(operations[top--].q, q);
}
while (top - 2 >= 0 && operations[top - 1].q >= q) {
top -= 2;
}
operations[++top] = new operation(1, q);
}
}
// System.out.println(Arrays.toString(operations));
int k = n;
int l = 1, r = n;
for (int i = 1; i <= top; i++) {
//降序操作,固定前面,添加后面
if (operations[i].p == 0) {
while (l <= r && r > operations[i].q) {
num[r--] = k--;
}
// System.out.println(operations[i]);
// System.out.println(Arrays.toString(num));
}else {
//升序操作,固定后面,添加前面
while (l <= r && l < operations[i].q) {
num[l++] = k--;
}
// System.out.println(operations[i]);
// System.out.println(Arrays.toString(num));
}
}
//发现中间还有没有填完的
//如果最后一条是升序,则中间为升序操作
if (operations[top].p == 1) {
while (l <= r) {
num[r--] = k--;
}
} else if (operations[top].p == 0) {
while (l <= r) {
num[l++] = k--;
}
}
for (int i = 1; i <= n; i++) {
System.out.print(num[i]+" ");
}
}
static class operation{
int p;
int q;
public operation(int p, int q) {
this.p = p;
this.q = q;
}
@Override
public String toString() {
return "operation{" +
"p=" + p +
", q=" + q +
'}';
}
}
}
04-30
1万+