B. Queries on a String
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://codeforces.com/contest/598/problem/B
Description
You are given a string s and should process m queries. Each query is described by two 1-based indices li, ri and integer ki. It means that you should cyclically shift the substring s[li... ri] ki times. The queries should be processed one after another in the order they are given.
One operation of a cyclic shift (rotation) is equivalent to moving the last character to the position of the first character and shifting all other characters one position to the right.
For example, if the string s is abacaba and the query is l1 = 3, r1 = 6, k1 = 1 then the answer is abbacaa. If after that we would process the query l2 = 1, r2 = 4, k2 = 2 then we would get the string baabcaa.
Input
The first line of the input contains the string s (1 ≤ |s| ≤ 10 000) in its initial state, where |s| stands for the length of s. It contains only lowercase English letters.
Second line contains a single integer m (1 ≤ m ≤ 300) — the number of queries.
The i-th of the next m lines contains three integers li, ri and ki (1 ≤ li ≤ ri ≤ |s|, 1 ≤ ki ≤ 1 000 000) — the description of the i-th query.
Output
Print the resulting string s after processing all m queries.
Sample Input
abacaba
2
3 6 1
1 4 2
Sample Output
baabcaa
HINT
题意
给你一个字符串,然后有Q次操作,每次操作可以使得区间的字符串向右平移K个字符
然后问你最后的字符是什么模样
题解:
询问只有300个,所以可以直接暴力就好了
代码
#include<iostream>
using namespace std; int main()
{
string s1,s2;
cin>>s1;
s2=s1;
int q;cin>>q;
while(q--)
{
int l,r,k;cin>>l>>r>>k;
l--,r--;
int len = r-l+;k%=len;
for(int i=;i<len;i++)
{
s2[(i+k)%len+l]=s1[l+i];
}
for(int i=l;i<=r;i++)
s1[i]=s2[i];
}
cout<<s1<<endl;
}