Hiho----Microsoft Pen Test "combination Lock"

Source: Internet
Author: User

Combination Lock time limit: 10000ms one point time limit: 1000ms memory limit: 256MB description

Finally, you come to the interview. You know a Microsoft interviewer are in the though the door is locked. There is a combination lock on the door. There is N rotators on the lock, each consists of alphabetic characters, namely, ' A '-' Z '. You need to unlock the door to meet the interviewer inside. There is a note besides the lock, which shows the steps to unlock it.

Note:there is M steps totally; Each step was one of the four kinds of operations shown below:

Type1: CMD 1 I J X: (i and J are integers, 1 <= i <= J <= N; X is a character, within ' a '-' Z ')

This was a sequence operation:turn the ith to the jth rotators to character X (the left most rotator is defined as the 1st Rotator)

For EXAMPLE:ABCDEFG = CMD 1 2 3 Z = AZZDEFG

Type2: CMD 2 i J K: (i, J, and K is all integers, 1 <= i <= J <= N)

This was a sequence operation:turn the ith to the jth rotators up K times (if character A was turned up once, it was B; if Z is turned up once, it's A now. )

For EXAMPLE:ABCDEFG = CMD 2 2 3 1 = ACDDEFG

Type3: CMD 3 K: (k is an integer, 1 <= K <= N)

This was a concatenation operation:move the K leftmost rotators to the rightmost end.

For EXAMPLE:ABCDEFG = CMD 3 3 = DEFGABC

Type4: CMD 4 i J(i, j is integers, 1 <= i <= J <= N):

This is a recursive operation, which means:

If i > J:do nothingelse:cmd 4 i+1 jcmd 2 I J 1

For EXAMPLE:ABCDEFG = CMD 4 2 3 = ACEDEFG

Input

1st line:2 integers, N, M (1 <= N <= 50000, 1 <= M <= 50000)

2nd line:a string of N characters, standing for the original status of the lock.

3rd ~ (3+m-1) th Lines:each line contains a string, representing one step.

Output

One line of N characters, showing the final status of the the lock.

Tips

Come on! You need to do these operations as fast as possible.

Sample input
7 4ABCDEFGCMD 1 2 5 ccmd 2 3 7 4CMD 3 3CMD 4 1 7
Sample output
Himofin

Hiho----Microsoft Pen Test "combination Lock"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.