13825 - The Last of DYY's Hamon   

Description

 

"Oh no! The power is off again!" Says a student playing games in the dorm.

"This is the last of my Hamon!" -DYY.

Our greatest ​vice president for general affairs is trying to resolve the power outage problem by the end of his term. In the beginning, He's trying to ask Doraemon for help. Unfortunately, Doraemon already retired last semester! In turn, he seeks cheap labor, the Pokemon Pikachu to do him a favor. By using Pikachu's move "10 万ボルト (Thunderbolt)", the campus would generate enough electricity, and can be lit up forever! This is too trivial for him...How clever is DYY!

The main power pipe of the campus is connecting the substation in a line, each substation has a id number representing it. Now, DYY wants to rearrange the order of the substations, by reversing the segments on the power pipe. Help him!


This is a partial judge problem. For the given linked list, you would only need to implement the function "reverse" to do the corresponding operation. For your convenience, we already pass the pointer of node_l and node_r to the function. You can refer to the following image to know the detail. If you implement the function and reverse the linked list correctly, the given program would output two lines - the reversed linked list and "pikachuuuu!!", and you can pass this problem.

 

 

Input

  • The first line contains two integers N and Q (1 < N, Q ≤ 100) - the number of substations and the number of the operation instructed by DYY
  • The second line contains N integers x1, x2, ..., xn (1 <= xi <= 109) - the id of each substation
  • Each of the next Q lines contains three integers l and r (1 < l ≤ r ≤ N) - reverse the l-th to r-th substations

 

Output

If you implement the function and reverse the linked list correctly, the given program would output two lines - the reversed linked list and "pikachuuuu!!", and you can pass this problem.

 

Sample Input  Download

Sample Output  Download

Partial Judge Code

13825.c

Partial Judge Header

13825.h

Tags




Discuss