哪位大佬能帮我看看,全WA
查看原帖
哪位大佬能帮我看看,全WA
734880
Dbbeg楼主2024/7/16 20:10

在另外一个网站上过了

#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<ctime>
#include<deque>
#include<list>
#include<stack>
#include<utility>
#include<climits>
#define ite iterator
#define fs fixed<<setprecision
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

inline ll read(){ll x=0,f=1;char z;z=getchar();while(z<'0'||z>'9'){if(z=='-')f=-1;z=getchar();}while(z>='0'&&z<='9')x=x*10+z-'0',z=getchar();return x*f;}
inline void write(ll x){if(x<0){x=-x;putchar('-');}if(x>9){write(x/10);}putchar(x%10+'0');}
inline void space(ull x=1){for(ull i=1;i<=x;++i)putchar(' ');}
inline void nxtl(ull x=1){for(ull i=1;i<=x;++i)putchar('\n');}

const int MAXINT = 2147483647;
const int MAXN = 1000000;

int n;
string opt;

class OppositeTopStack{
private:
	const int Bottom = 1;
	int LeftTop = 0 , RightTop = 0;
	int LeftStack[MAXN] , RightStack[MAXN];
	int LeftPrefixSum[MAXN] , MaxPrefixSum[MAXN] = {-MAXINT};

public:
	void MoveToLeft(){//向左移动 
		if(!LeftTop)  return;
		RightStack[++RightTop] = LeftStack[LeftTop--];
	}
	void MoveToRight(){//向右移动 
		if(!RightTop)  return;
		LeftStack[++LeftTop] = RightStack[RightTop--];
		LeftPrefixSum[LeftTop] = LeftPrefixSum[LeftTop-1] + LeftStack[LeftTop];
		MaxPrefixSum[LeftTop] = max(MaxPrefixSum[LeftTop-1] , LeftPrefixSum[LeftTop]);
	}
	void Insert(const int x){//光标处输入 
		LeftStack[++LeftTop] = x;
		LeftPrefixSum[LeftTop] = LeftPrefixSum[LeftTop-1] + LeftStack[LeftTop];
		MaxPrefixSum[LeftTop] = max(MaxPrefixSum[LeftTop-1] , LeftPrefixSum[LeftTop]);
	}
	void Erase(){//删除 
		if(LeftTop)  --LeftTop;
	}
	int QueryMaxPrefixSum(int k) const{//求最大前缀和 
//		if(!k)  return 0;
		return MaxPrefixSum[k];
	}
	void PrintAll() const{//调试用 
		printf("The list is : ");
		for(int i = 1 ; i <= LeftTop ; ++i)
			printf("%d " , LeftStack[i]);
		printf("| ");
		for(int i = RightTop ; i >= 1 ; --i)
			printf("%d " , RightStack[i]);
		nxtl();
	}
}target;


int ChangeToNumber(int l , int r){
	
	int ret = 0 , times = 1;
	if('-' == opt[l])
		times = -times , ++l;
	
	for(int i = r ; i >= l ; --i){
		ret += (opt[i] - '0') * times;
		times *= 10;
	}
	
	return ret;
}


int main(){
	
//	freopen("kkk.txt" , "w" , stdout);
	
	scanf("%d" , &n);
	
	while(n--){
		char opt;
		int num;
		do
			scanf("%c" , &opt);
		while('\n' == opt);
//		cout << "-----" << opt << endl;
		if('I' == opt){
			scanf("%d" , &num);
			target.Insert(num);//插入 
		}
		else if('D' == opt)
			target.Erase();//删除 
		else if('L' == opt)
			target.MoveToLeft();//左移 
		else if('R' == opt)
			target.MoveToRight();//右移 
		else{
			scanf("%d" , &num);
			printf("%d\n" , target.QueryMaxPrefixSum(num));//最大前缀和 
		}
		//target.PrintAll();输出该列表
	}
	
	return 0;
}

2024/7/16 20:10
加载中...