#P12539. [XJTUPC 2025] 结束乐队

    ID: 12374 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>线段树二分2025O2优化高校校赛

[XJTUPC 2025] 结束乐队

Description

"I'm here to end the band"

A girl band is taking a group photo, but the photographer has bad intentions. She plans to process the photos and then post them on social media, causing dissatisfaction among fans, which will cause the popularity of some members of the band to rise or fall. She thinks this will end the band. Her plan is as follows:

It is known that the girl band has nn members, who are lined up from left to right for the photo. The initial popularity ranking of each member is different, ranging from 11 to nn. The photographer plans to take kk photos and publish them on social media after each photo. Each of her photos only contains a continuous section of the band member permutation, so that the fans of the most popular member who does not appear in this photo will be extremely angry and quit following her, causing the ranking of this member to drop by one (the original ranking of the member who was one lower will rise). Through kk operations, she successfully disrupted the ranking of the band members, and her goal was achieved.

But now she has a problem because there are too many members in the band; for each captured photo, she can't judge which member who doesn't appear ranks first, so she turned to you for help, hoping you can help her solve the problem.

Formally, given a permutation a1,a2,,ana_1, a_2, \dots, a_n from 11 to nn, perform kk operations, each operation:

  • Given an interval [l,r][l,r], find the smallest positive integer that does not appear in the interval [l,r][l,r] in the current permutation, and set this number to xx (i.e. $x=\min\{p\mid \forall i \in [l,r],p\neq a_i,p\geq 1\}$);
  • If x<nx<n, output xx, and swap the positions of the numbers xx and x+1x+1 in the current permutation a1,a2,,ana_1, a_2, \dots, a_n;
  • If xnx\ge n, output the string peace\tt{peace}.

Wherein, the permutation a1,a2,,ana_1, a_2, \dots, a_n from 11 to nn refers to a set of numbers that satisfies {a1,a2,,an}={1,2,n}\{a_1, a_2, \dots, a_n\} = \{1, 2, \dots n\}.

Input Format

The first line contains a positive integer nn (1n5×1051\le n\le 5\times 10^5), indicating the size of the permutation.

The second line contains nn positive integers aia_i, separated by a space, indicating the initial permutation a1,a2,,ana_1, a_2, \dots, a_n ({a1,a2,,an}={1,2,n}\{a_1, a_2, \dots, a_n\} = \{1, 2, \dots n\}).

The third line contains a positive integer kk (1k1051\le k\le 10^5), indicating the number of operations.

The next kk lines, each containing two positive integers ll and rr (1lrn1\le l\le r\le n), separated by a space, indicate the range of operations.

Output Format

For each operation in each test data, give the answer and perform the modification.

Remember that the smallest positive integer that does not appear in the interval [l,r][l,r] in the permutation a1,a2,,ana_1, a_2, \dots, a_n is xx:

  • If x<nx<n, output xx and swap the positions of the numbers xx and x+1x+1 in the current permutation a1,a2,,ana_1, a_2, \dots, a_n;
  • If xnx\ge n, output the string peace\tt{peace}.
5
4 3 1 2 5
5
2 4
2 5
1 3
1 3
1 5
4
peace
2
3
peace
10
10 9 4 3 2 1 6 5 8 7
3
1 10
2 9
3 9
peace
7
8

Hint

For the first sample:

The first operation is [2,4][2,4], and the current permutation is 4,3,1,2,54,3,1,2,5.

The smallest positive integer that does not appear in the interval [2,4][2,4] is 44. Output 44 and swap the positions of 44 and 55 in the permutation.

The second operation is [2,5][2,5], and the current permutation is 5,3,1,2,45,3,1,2,4.

The smallest positive integer that does not appear in the interval [2,5][2,5] is 55. Output peace\tt{peace}, and the permutation remains unchanged.

The third operation is [1,3][1,3], and the current permutation is 5,3,1,2,45,3,1,2,4.

The smallest positive integer that does not appear in the interval [1,3][1,3] is 22. Output 22 and swap the positions of 22 and 33 in the permutation.

The fourth operation is [1,3][1,3], and the current permutation is 5,2,1,3,45,2,1,3,4.

The smallest positive integer that does not appear in the interval [1,3][1,3] is 33. Output 33 and swap the positions of 33 and 44 in the permutation.

The fifth operation [1,5][1,5], the current permutation is 5,2,1,4,35,2,1,4,3.

The smallest positive integer that does not appear in the interval [1,5][1,5] is 66. Output peace\tt{peace}, the permutation remains unchanged.