关闭

Codeforces 598B Queries on a String 【思维】

标签: codeforces字符串
392人阅读 评论(0) 收藏 举报
分类:
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;
}


0
0
查看评论

CodeForces - 598B Queries on a String

B. Queries on a String time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard ...
  • qq_37804582
  • qq_37804582
  • 2017-07-25 09:39
  • 153

Codeforces 598B Queries on a String 【水题】

B. Queries on a String time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You ar...
  • chenzhenyu123456
  • chenzhenyu123456
  • 2015-11-15 18:27
  • 680

(CodeForces - 598B)Queries on a String

(CodeForces - 598B)Queries on a StringYou are given a string s and should process m queries. Each query is described by two 1-based indices li, ri and...
  • wozaipermanent
  • wozaipermanent
  • 2017-09-07 08:02
  • 210

【CodeForces】598B - Queries on a String

http://codeforces.com/problemset/problem/598/A一个字符串s以及m次操作,每次操作给定l、r、k,表示在区间[l,r]内依次把元素右移k次, 最后一位移到最前。 求m次操作后的字符串。#include <iostream> #include ...
  • zqf3535
  • zqf3535
  • 2017-08-14 16:41
  • 60

CodeForces 598B Queries on a String

思路: 一年前学的三步翻转。。一年后才用上。!不过暴力好像也过了! #include #include #include #include using namespace std; void reverse(char *left,char *right) { while...
  • qq_33951440
  • qq_33951440
  • 2017-04-03 20:55
  • 108

coderforce 598B Queries on a String

题意:给出一个字符串(1的字符当成一个环来逆时针转 k 次,得到一个新字符串,以后每次查询修改,都是在此字符串基础上进行的。 思路:先用一个字符串临时存放(L--r)的字符,因为下标是从0开始,所以是(src[L-1]到src[r-1])位字符,再按每次查询修改k次进行修改因是环,所以位置 i -...
  • zyx520ytt
  • zyx520ytt
  • 2015-11-16 22:07
  • 278

Codeforces 598B Queries on a String(rotate(begin,mid,end))

B. Queries on a Stringtime limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given ...
  • wcs_152
  • wcs_152
  • 2017-02-18 13:52
  • 102

codeforces 710f String Set Queries ac自动机 二进制分组

题意:维护一个字符串集合,支持插入一个串,删除一个串,询问集合中的串在给出的串中出现多少次,一个串出现多次算多次。并且不会有两次插入的串相同。强制在线。考虑没有删除的情况,将插入串的个数二进制拆分,对于每2k2^k 个串维护一个ac自动机。 这样共有loglog个ac自动机 。插入时如果当前ac...
  • make_it_for_good
  • make_it_for_good
  • 2016-09-02 19:05
  • 692

Codeforces 729D Sea Battle(思维题,好题)

D. Sea Battle time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output ...
  • fouzhe
  • fouzhe
  • 2016-11-21 22:51
  • 542

Codeforces 911G - Mass Change Queries

G. Mass Change Queries time limit per test 3 seconds memory limit per test 512 megabytes input standard input output standard ...
  • lkqlxjlxr71
  • lkqlxjlxr71
  • 2018-01-16 20:16
  • 67
    个人资料
    • 访问:46998次
    • 积分:1707
    • 等级:
    • 排名:千里之外
    • 原创:128篇
    • 转载:3篇
    • 译文:0篇
    • 评论:5条
    最新评论