CodeForces 598B Queries on a String

水题。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;

char s[10000+10];
char tmp[10000+10];
int cnt;
int m;

int main()
{
    scanf("%s",s);
    scanf("%d",&m);
    for(int i=1;i<=m;i++)
    {
        int li,ri,k;
        scanf("%d%d%d",&li,&ri,&k);
        li--;ri--;
        cnt=0;
        for(int i=li;i<=ri;i++) tmp[cnt++]=s[i];
        tmp[cnt]=0;

        int len=ri-li+1;
        int pos=k%len;

        pos=pos+li; // printf(" **** %d\n",pos);

        int u=0;
        for(int i=pos;i<=ri;i++) s[i]=tmp[u++];
        for(int i=li;i<pos;i++) s[i]=tmp[u++];
    }
    printf("%s\n",s);
    return 0;
}
时间: 2024-08-04 02:19:26

CodeForces 598B Queries on a String的相关文章

dp --- Codeforces 245H :Queries for Number of Palindromes

Queries for Number of Palindromes Problem's Link:   http://codeforces.com/problemset/problem/245/H Mean: 给你一个字符串,然后q个询问:从i到j这段字符串中存在多少个回文串. analyse: dp[i][j]表示i~j这段的回文串数. 首先判断i~j是否为回文,是则dp[i][j]=1,否则dp[i][j]=0; 那么dp[i][j]=dp[i][j]+dp[i][j-1]+dp[i+1[j

Codeforces 245H Queries for Number of Palindromes:区间dp

题目链接:http://codeforces.com/problemset/problem/245/H 题意: 给你一个字符串s. 然后有t个询问,每个询问给出x,y,问你区间[x,y]中的回文子串的个数. 题解: 表示状态: dp[x][y] = numbers 表示区间[x,y]中的回文子串个数. 找出答案: 每次询问:ans = dp[x][y] 如何转移: dp[x][y] = dp[x][y-1] + dp[x+1][y] - dp[x+1][y-1] + pal[x][y] 用到了容

CodeForces - 963D:Frequency of String (bitset暴力搞)

You are given a string ss. You should answer nn queries. The ii-th query consists of integer kiki and string mimi. The answer for this query is the minimum length of such a string tt that tt is a substring of ss and mimi has at least kiki occurrences

Codeforces 710 E. Generate a String (dp)

题目链接:http://codeforces.com/problemset/problem/710/E 加或者减一个字符代价为x,字符数量翻倍代价为y,初始空字符,问你到n个字符的最小代价是多少. dp[i]表示i个字符的最小代价. 当i为偶数个的时候,由+1或者*2得到. 当i为奇数个的时候,由+1或者*2-1得到. 1 //#pragma comment(linker, "/STACK:102400000, 102400000") 2 #include <algorithm&

CodeForces 632C - C. The Smallest String Concatenation

题意: n 个 串,把他们按照某个次序连起来 , 使连接后的字符串字典序最小. 做这题的时候我简直是蠢死了..... #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<string> using namespace std; const int maxn = 50010; string str[maxn]; bool cmp(str

Queries on a String

题意: 给你一个字符串s,接着有m次循环移位. 循环移位的一个操作就是将s的最后一个字符移动到第一个字符的位置,并且将所有其他的字符向右移动一个位置. 例如,s='abacaba',查询是L1=3,R1=6,K1=1,那么答案是’abbacaa’(解释:从s第三个位置到第六个位置’acab’,循环1次,把b移到第一位,其他往后移一位,就是’baca’,替换之前的’acab’),之后如果我们再做处理L2=1,R2=4,K2=2,那么答案就变’baabcaa’(解释:首先从第一个位置到第四个位置’a

【CodeForces 624C】Graph and String

题 题意 n个表示abc三个字符的点,a和b是相连的,b和c是相连的,相同的是相连的,现在给你n个点和他们之间的m条边,判断是否存在这样的字符串,存在则给出一个符合条件的. 分析 我的做法是找出所有的b,因为b是只和自己没有连接,所以有n-1个连线,然后找出第一个不是b的,然后所有和该点没有连线的都设置为c,有连线而不是b的就设置为a,然后再把该点设置为a. 接下来,根据题目条件,判断一下我设置出来的字符串成不成立.就是如果不相连接却是相同字母或者有b字母,还有如果相连接却是a和c,那都是不符合

Codeforces 245H Queries for Number of Palindromes

题意:给你一个字符串,再给你一个q(询问个数1000000),问你这个区间内回文串的个数. 解题思路: 1)dp,先把 i 到j 是回文串的真值赋值给 dp[i][j] ,然后从后往前dp    dp[i][j] += dp[i+1][j] + dp[i][j-1]  -dp[i+1][j-1]; 解题代码: 1 // File Name: 245h.dp.cpp 2 // Author: darkdream 3 // Created Time: 2015年03月30日 星期一 15时27分10

CodeForces 1328E-Tree Queries【LCA】

题意: ??给出一棵 \(n\) 个点的树,\(m\) 次询问,每次询问给出 \(k\) 个点,问这 \(k\) 个点能否在其中某个点到根节点 \(1\) 的路径上或者与路径的距离为 \(1\). 数据范围:\(2≤n≤2?10^{5}\) , \(1≤m≤2?10^{5}\) , \(1≤k_i≤n\) , \(\sum_{i=1}^{m}{k_i}≤2?10^5\) 分析: ??首先,要确定路径.显然,应该为深度最深的点到根节点的路径.然后,在判断其他的点是否满足要求. ??一开始的做法是,