Problem: B. Queries on a String

发布时间 2023-11-29 17:17:38作者: jiangXxin

image
题意简述:
给出一个字符串,每次给定l,r,k,选择一个子串l-r,然后子串向右移动k个单位.

做法:
每次k对子串的长度取模,然后模拟即可(使用substr函数截取前半段和后半段,交换前半段和后半段即可)

点击查看代码
// Problem: B. Queries on a String
// Contest: Codeforces - Educational Codeforces Round 1
// URL: https://codeforces.com/contest/598/problem/B
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// Author: a2954898606
// Create Time:2023-11-29 13:32:43
// 
// Powered by CP Editor (https://cpeditor.org)

/*
    /\_/\
   (o   o)
  /      \
 // ^ ^  \\
///      \\\
 \       |
  \_____/
 /\_  _/\
 */
#include<bits/stdc++.h>

#define all(X) (X).begin(),(X).end()
#define all2(X) (X).begin()+1,(X).end()
#define pb push_back
#define mp make_pair
#define sz(X) (int)(X).size()

#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl

using namespace std;
typedef long long unt;
typedef vector<long long> vt_unt;
typedef vector<int> vt_int;
typedef vector<char> vt_char;

template<typename T1,typename T2> inline bool ckmin(T1 &a,T2 b){
	if(a>b){
		a=b;
		return true;
	}
	return false;
}
template<typename T1,typename T2> inline bool ckmax(T1 &a,T2 b){
	if(a<b){
		a=b;
		return true;
	}
	return false;
}

namespace smart_math{
    long long quickpow(long long a,long long b,long long mod=0){
        long long ret=1;
        while(b){
            if(b&1)ret*=a;
            if(mod)ret%=mod;
            b>>=1;
            a*=a;
            if(mod)a%=mod;
        }
        if(mod)ret%=mod;
        return ret;
    }
    long long quickmul(long long a,long long b,long long mod=0){
    	long long ret=0;
    	while(b){
    		if(b&1)ret+=a;
    		if(mod)ret%=mod;
    		b>>=1;
    		a=a+a;
    		if(mod)a%=mod;
		}
		if(mod)ret%=mod;
		return ret;
	}
	long long ceil_x(long long a,long long b){
		if(a%b==0)return a/b;
		else return (a/b)+1;
	}
}
using namespace smart_math;
const long long mod=1e9+7;
const long long N=310000;
const long long M=300;



int solve(){
	string s;
	cin>>s;
	s=" "+s;
	int q;
	cin>>q;
	while(q--){
		int l,r,k;
		cin>>l>>r>>k;
		int len=r-l+1;
		k%=len;
		int m=len-k;//front
		//cout<<"m:"<<m<<endl;
		string t=s.substr(l,m);
		//cout<<"t:"<<t<<endl;
		int cnt=0;
		for(int i=r-k+1;i<=r;i++){
			s[l+cnt]=s[i];
			cnt++;
		}
		cnt=0;
		for(int i=l+k;i<=r;i++){
			s[i]=t[cnt];
			cnt++;
		}
		//cout<<s<<endl;
	}
	for(int i=1;i<sz(s);i++){
		cout<<s[i];
	}
	cout<<endl;
    return 0;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int t;
    t=1;
    //cin>>t;
    while(t--){
        int flag=solve();
        if(flag==1) YES;
        if(flag==-1) NO;
    }
    return 0;
}