P2201 输出有BUG 悬关
  • 板块灌水区
  • 楼主yjjh
  • 当前回复2
  • 已保存回复2
  • 发布时间2024/3/8 12:57
  • 上次更新2024/3/8 17:19:29
查看原帖
P2201 输出有BUG 悬关
1036002
yjjh楼主2024/3/8 12:57

题目:P2201 数列编辑器

用栈打的,输出有BUG,所以0分

救救孩子吧!!!

代码如下:

#include <bits/stdc++.h>
using namespace std;
stack<int>gbq;
stack<int>gbh;
int f[1114514],s[1114514],tt;
int maa(){
    tt++;
    s[tt]=s[tt-1]+gbq.top();
    f[tt]=max(f[tt-1],s[tt]);
}
int ii(int x){
    gbq.push(x);
    maa();
}
int dd(){
    gbq.pop();
    if(tt>0){
        tt--;
    	maa();
    }
}
int ll(){
    if(gbq.size()!=0){
        int o=gbq.top();
        gbq.pop();
        gbh.push(o);
        tt--;
        maa();
    }
}
int rr(){
    if(gbh.size()!=0){
        int o=gbh.top();
        gbh.pop();
        gbq.push(o);
        maa();
    }
}
int qq(int k){
    cout <<f[k]<<endl;
}
int main(){
    int n;
    cin >>n;
    for(int i=0;i<n;i++){
        char c;
        int x,k;
        cin >>c;
        if(c=='I'){
            cin >>x;
            ii(x);
        }else if(c=='D')dd();
        else if(c=='L')ll();
        else if(c=='R')rr();
        else if(c=='Q'){
            cin >>k;
            qq(k);
        }
    }
    return 0;
}
2024/3/8 12:57
加载中...