{题解}[jzoj4778]【NOIP2016提高A组模拟9.14】数列编辑器

传送门

Description

题目

Analysis

考虑模拟
简单地考虑,使用模拟链表和指针完成L-R-I-D操作
至于Q
观察到N为当前光标前的数字个数
只要指针到哪,更新到哪即可。

当然,你也可以用两个完成
stack1[i]表示光标左边的第i个数字
stack2[i]表示光标右边的(倒数)第i个数字

Code(双栈)

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int Q = 1001000;
int q;
int ans[Q],sum[Q];
int stack1[Q],stack2[Q],tail1,tail2;
//stack1未删除 stack2墓地 
int main()
{
    //freopen("D:/LiuYuanHao/4778_1.in","r",stdin);
    freopen("editor.in","r",stdin);freopen("editor.out","w",stdout);
    memset(ans,128,sizeof ans);
    scanf("%d\n", &q);
    for (int i = 1;i <= q;i ++)
    {
        char c = getchar();
        int xx;
        if (c == 'I') 
        {
            scanf("%d", &xx);
            stack1[++ tail1] = xx;
            sum[tail1] = sum[tail1 - 1] + xx;
            ans[tail1] = max(sum[tail1],ans[tail1 - 1]);
        }
        if (c == 'Q')
            scanf("%d", &xx),
            printf("%d\n", ans[xx]);
        if (c == 'L' && tail1 > 0)
            stack2[++ tail2] = stack1[tail1 --];
        if (c == 'R' && tail2 > 0)
        {
            stack1[++ tail1] = stack2[tail2 --];
            sum[tail1] = sum[tail1 - 1] + stack1[tail1];
            ans[tail1] = max(sum[tail1], ans[tail1 - 1]);
        }
        if (c == 'D') tail1 --;
        scanf("\n"); 
    }
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值