首页 > 其他分享 >Problem: B. Queries on a String

Problem: B. Queries on a String

时间:2023-11-29 17:23:24浏览次数:33  
标签:return String int long ret Queries Problem define mod

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;
}

标签:return,String,int,long,ret,Queries,Problem,define,mod
From: https://www.cnblogs.com/jiangXxin/p/17865372.html

相关文章

  • Problem: A. Tricky Sum
    A:做法:数据比较小,用求和公式(n+1)*n/2,减去所有2的幂即可点击查看代码//Problem:A.TrickySum//Contest:Codeforces-EducationalCodeforcesRound1//URL:https://codeforces.com/contest/598/problem/A//MemoryLimit:256MB//TimeLimit:1000ms//Aut......
  • .Net中C# DateTime类的ToString()方法的使用
    Console.WriteLine("ToShortDateString:"+DateTime.Now.ToShortDateString());Console.WriteLine("ToLongDateString:"+DateTime.Now.ToLongDateString());Console.WriteLine("ToShortTimeString:"+DateTime.Now.ToShortTimeString()......
  • 论文:FEED-FORWARD NETWORKS WITH ATTENTION CAN SOLVE SOME LONG-TERM MEMORY PROBLEM
    题目:FEED-FORWARDNETWORKSWITHATTENTIONCANSOLVESOMELONG-TERMMEMORYPROBLEMS”(Raffel和Ellis,2016,p.1)“带有注意力的前馈网络可以解决一些长期记忆问题”(Raffel和Ellis,2016,p.1)(pdf)这篇论文提出了一种适用于前馈神经网络的简化注意力模型,并展示了......
  • go基础数据类型 - string的底层
    先上一段代码:funcmain(){ content:="长沙boy" content1:="boy" fmt.Printf("content:%d\n",unsafe.Sizeof(content)) fmt.Printf("content1:%d\n",unsafe.Sizeof(content1))}打印的结果:content:16content1:16问题1、从这里......
  • C# 比使用app.config,用自定义的ConnectionString
    usingSystem.Data;usingSystem.Data.SqlClient;usingSystem.IO;usingSystem.Reflection;namespaceAssist{publicclassContextHelper{publicstaticstringConnectionString;publicstaticstringSerializePath=Path.GetDirector......
  • java字符串String类的常用方法
    java字符串String类的常用方法字符串的创建:(1)定义字符串直接赋值,在字符串池中开辟空间()Stringstr1=“Hello”;//在字符串池中写入字符串"hello"Stringstr2=“Hello”;//直接引用字符串池中的"Hello"System.out.println(str1==str2);//地址相同,输出:true(2)使用new关键字调用字......
  • SP19543 GSS8 - Can you answer these queries VIII 题解
    更好的阅读体验SP19543GSS8-CanyouanswerthesequeriesVIIIfhq+二项式定理。提供一个不太一样的思路。默认下标从\(1\)开始。首先插入删除,区间查询,想到可以平衡树维护或者离线下来做线段树。本文中是用的是fhq,好写一些。\(k\)非常的小,考虑对于每一个\(k\)的答......
  • 无涯教程-MySQL String Functions函数
    Sr.No.Name&Description1ASCII()返回最左边字符的数值2BIN()返回参数的字符串表示形式3BIT_LENGTH()返回参数的长度(以位为单位)4CHAR_LENGTH()返回参数中的字符数5CHAR()返回传递的每个整数的字符6CHARACTER_LENGTH()CHAR_LENGTH()的同义词7......
  • Count Beautiful Substrings II
    CountBeautifulSubstringsIIYouaregivenastring s andapositiveinteger k.Let vowels and consonants bethenumberofvowelsandconsonantsinastring.Astringis beautiful if:vowels==consonants.(vowels*consonants)%k==0,inothert......
  • The Design of Feedback Control Systems--Advanced Problems
    AP10.1Athree-axispick-and-placeapplicationrequirestheprecisemovementofaroboticarminthree-dimensionalspace,asshowninFigureAP10.1forjoint2.Thearmhasspecificlinearpathsitmustfollowtoavoidotherpiecesofmachinery.Theovers......