TLE#20求调
  • 板块P2710 数列
  • 楼主gitxiaozheng
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/12/15 15:32
  • 上次更新2024/12/15 18:33:35
查看原帖
TLE#20求调
1472321
gitxiaozheng楼主2024/12/15 15:32
#include<bits/stdc++.h>
using namespace std;
#define L long long
vector<L> n;
vector <L> temp;
L N,M,t1,insert1,insert2,insert3,delete1,delete2,reverse1,reverse2,m1,m2,m3,g1,g2,g3,g11,ma1,ma2;
string caozuo;
void Insert();
void Delete();
void Reverse();
void Make_Same();
void get_sum();
void get();
void max_sum();
auto beg=n.begin();
int main(){
//  	freopen("D:\\work\\cpp\\P2710\\example.in","r",stdin);
//  	freopen("D:\\work\\cpp\\P2710\\example.out","w",stdout);
	cin>>N>>M;
	while(N--){
		scanf("%lld",&t1);
		n.push_back(t1);
	}
	
	while(M--){

		cin>>caozuo;
//		cout<<caozuo<<endl;
		if(caozuo=="INSERT"){
			Insert();
		}
		if(caozuo=="DELETE"){
			Delete();
		}
		if(caozuo=="REVERSE"){
			Reverse();
		}
		if(caozuo=="MAKE-SAME"){
			Make_Same();
		}
		if(caozuo=="GET-SUM"){
			get_sum();
		}
		if(caozuo=="GET"){
			get();
		}
		if(caozuo=="MAX-SUM"){
			max_sum();
		}
//		cout<<caozuo<<endl;
//		for(L a:n)
//			cout<<a<<" ";
//		cout<<endl;
	}
//  	fclose(stdin);
//  	fclose(stdout);
	return 0;
}
void Insert(){
	cin>>insert1>>insert2;
	L temp3=n.size();
	for(int i2=1;i2<=insert2;i2++){
		cin>>insert3;
		beg=n.begin();
		if(temp3==0)
			n.push_back(insert3);
		else
			auto temp2=n.insert(beg+insert1+i2-1,insert3);
	}
}
void Delete(){
	cin>>delete1>>delete2;
	beg=n.begin();
	auto temp3=n.erase(beg+delete1-1,beg+delete1+delete2-1);
}
void Reverse(){
	cin>>reverse1>>reverse2;
	beg=n.begin();
	reverse(beg+reverse1-1,beg+reverse1+reverse2-1);
}
void Make_Same(){
	cin>>m1>>m2>>m3;
	for(int i=m1-1;i<=m1+m2-2;i++){
		n[i]=m3;
	}
}
void get_sum(){
	cin>>g1>>g2;
	g3=0;
	if(n.empty()){
    	cout<<0<<endl;
    	return;
	}
	for(int i=g1-1;i<=g1+g2-2;i++){
		g3+=n[i];
	}
	cout<<g3<<endl;
}
void get(){
	cin>>g11;
	cout<<n[g11-1]<<endl;
}
void max_sum(){
	cin>>ma1>>ma2;
	if(ma2==1){
		cout<<n[ma1-1]<<endl;
		return;
	}
	beg=n.begin();
	temp.push_back(0);
    
    if(n.empty()){
    	cout<<0<<endl;
    	return;
	}
	for(int i4=ma1-1;i4<=ma1+ma2-2;i4++){
		temp.push_back(n[i4]);
	}
	L t=temp.size();
	temp[0]=0;
    L ans=temp[1];
    for(int i = 1; i <= temp.size()-1; i++) {
        if(temp[i-1]>0){
			temp[i]+=temp[i-1];
		}
        else{
			temp[i]+=0;
		}
        if(temp[i]>ans){
			ans=temp[i];
		}
    }
    cout<<ans<<endl;

    for(int i = 0; i <= t-1; i++) {
		temp.erase(temp.begin());
    }
}
2024/12/15 15:32
加载中...