Codeforces 598B Queries on a String 【思维】

原创 2016年08月30日 21:19:41
B. Queries on a String
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a string s and should process m queries. Each query is described by two 1-based indices liri 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 liri 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.

Examples
input
abacaba
2
3 6 1
1 4 2
output
baabcaa
Note

The sample is described in problem statement.


/*
    题意:给你一个字符串和m次查询,每次查询给你l,r,k
          表示在区间[l,r]内依次把最后的元素移到最前面k次,
          求m次查询以后的字符串
    类型:字符串
    分析:先把k%(R-L+1),得到有效移动次数,再从后向前扫一遍,
          求出当前位置i经过k次变化后到达的位置.
          最后从前向后扫一遍,更新字符.
*/

#include<cstdio>
#include<iostream>
using namespace std;
char s[10005],t[10005];
int m;
int main()
{
    cin>>s;
    cin>>m;
    while(m--){
        int l,r,k;
        cin>>l>>r>>k;
        int len=(r-l+1);
        k%=len;
        for(int i=r-1;i>=l-1;i--){
            int pos=(i-(l-1)+k)%len+l-1;
            t[pos]=s[i];
        }
        for(int i=l-1;i<=r-1;i++){
            s[i]=t[i];
        }
    }
    cout<<s<<endl;
    return 0;
}


版权声明:写得不好,希望大家及时指出,共同进步(っ °Д °;)っ另外转载也希望注明一下出处,蟹蟹~

相关文章推荐

CodeForces - 859C Pie Rules DP(逆推)(思维好题)

传送门:Codeforces 859c 题意:有n个物品,每个物品有不同的价值,物品按顺序分给两个人,有一块令牌,每回合拥有令牌的人拥有物品的分配权,但是该回合未获得物品的那个人会在下回合获得令牌,...

Codeforces 485D Maximum Value【思维+技巧枚举】

D. Maximum Value time limit per test 1 second memory limit per test 256 megabytes input ...

Coderforces 598.B Queries on a String

7.15.B 模拟的基础上化简求解

【Educational Codeforces Round 1B】【字符串平移 水题】Queries on a String 字符串平移水题

B. Queries on a String time limit per test 2 seconds memory limit per test 256 megabytes...

Educational Codeforces Round 1 B.Queries on a String(模拟)

题目大意:给定一个字符串,经过m次移动(移动方式为:在区间[l,r]内(下标从1开始),向右移动1个字符,执行k次),然后输出它。 简单的模拟题,只需要注意k对(r-l+1)取模即可。...

codeforces - Queries on a String(模拟+取余)

B. Queries on a String time limit per test 2 seconds memory limit per test 256 megabytes...

CF--B - Queries on a String

B. Queries on a String time limit per test 2 seconds memory limit per test 256 megabytes input st...
  • Inite
  • Inite
  • 2015年11月14日 09:17
  • 330

Codeforces #371(Div.2)C.Sonya and Queries【map应用】【思维】

传送门 :C. Sonya and Queries 描述: C. Sonya and Queries time limit per test 1 second memory limit p...

Codeforces 369E Valera and Queries【逆向思维+离线+树状数组】好题!好题!好题!

E. Valera and Queries time limit per test 2 seconds memory limit per test 512 megabytes i...

codeforces 714C Sonya and Queries [思维]【STL】

题目链接:http://codeforces.com/contest/714/problem/C————————————-. C. Sonya and Queries time limit per...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Codeforces 598B Queries on a String 【思维】
举报原因:
原因补充:

(最多只允许输入30个字)