CodeForces - 598BQueries on a String(水题)

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.

Example
Input
abacaba
2
3 6 1
1 4 2
Output
baabcaa

虽然说是水题,但我看题看了好久才看懂。。。

题目大意就是给你个字符串,执行若干次操作后输出该字符串

每次操作就是将给定区间[l,r]的所有字母首尾相连形成一个环,然后环上每个元素向后移动k位(其实就是循环移动,只是我不会表述)

代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<cmath>
using namespace std;
int pos[10005];//用该数组保存该位置对应字母在char[]数组中的位置
int prepos[10005];//用该数组保存该位置之前对应字母在char[]数组中的位置
char t[10005];
int main()
{
    int m,l,r,k;
    while(cin>>t)
    {
        int n=strlen(t);
        for(int i = 1; i <= n; i++) {
                pos[i]=i;
                prepos[i]=i;
        }
        cin>>m;
        for(int i = 0; i < m; i++)
        {
            cin>>l>>r>>k;
            for(int j = r; j >= l; j--)
            {
                int temp=l+(j-l+k)%(r-l+1);
                pos[temp] = prepos[j];
            }
            for(int j = r; j >= l; j--)
                prepos[j]=pos[j];
        }
        for(int i =1; i <= n; i++)
                cout<<t[pos[i]-1];
            cout<<endl;
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值