P19027 [GeeksforGeeks] Lazy pasha1646
普及
题目描述

Given a string S of size N and Q queries.Each query is either of the following types:
Type 1- Rotate the string by K character from the end.
Type 2- Print the character at the I'th index of the resulting string at that instant.
Answer all queries.
Example 1:
Input:
N=7 Q=5
S=abcdefg
Query_{1}: Type=1 K=2
Query_{2}: Type=2 I=0
Query_{3}: Type=2 I=6
Query_{4}: Type=1 K=4
Query_{5}: Type=2 I=1
Output:
f
e
c
Explanation:
After First query String becomes-"fgabcde"
Second query returns - 'f'
Third query returns -'e'
After Fourth Query String becomes-"bcdefga"
Fifth Query returns -'c'
Example 2:
Input:
N=5 Q=2
S=geeks
Query_{1}: Type=1 K=4
Query_{2}: Type=2 I=4
Output:
g
Explanation:
After first query,string becomes "eeksg".
Second query returns 'g'.
Your task:
You don't need to read input or print anything.Your task is to complete the function StringQuery() which takes an integer N,an integer Q, a string S and two arrays Q1 and Q2(containing Query type and K/I respectively) and returns an array containing the answers to the queries.
Expected Time Complexity:O(Q)
Expected Auxillary Space:O(1)
Constraints:
1<=N<=10^{5}
1<=Q<=10^{4}
1<=Type<=2
1<=K<=10^{9}
0<=I

输入格式

见题面

输出格式

见题面

样例输入
N=7 Q=5 S=abcdefg Query_{1}:Type=1 K=2 Query_{2}:Type=2 I=0 Query_{3}:Type=2 I=6 Query_{4}:Type=1 K=4 Query_{5}:Type=2 I=1
样例输出
f e c