【JZOJ5623】program

Description
Description

Input
Input

Output
Output

Sample

Input:
10 5
8>6<2<>54<
4 7
1 10
4 4
2 9
8 10
Output:
0 0 0 0 0 0 0 0 0 0
4 4 4 3 3 2 1 1 1 0
0 0 0 0 0 0 0 0 0 0
2 2 2 1 2 2 1 0 0 0
0 0 0 1 2 1 0 0 0 0

Data Constraint
Output


Analysis

假设从第一个位置开始走,走回第一处立刻折返,走到n位置,有一个很长的路径
那么在其中一个区间 [l,r] [ l , r ] 中走,它只对应这条路径中的一个子段
那只用记录从1开始走第i个时间点,0~9的状态,第一次走到i的时间f[i],第一次从i走到之前的时间 g[i] g [ i ]
直接模拟即可

#include<cstring>
#include<cstdio>
#include<algorithm>
#define N 1200000

using namespace std;

int f[N],g[N],num[N][10],n,q,dir=1,nxt[N];
struct link{int num,las,nex;}a[N];

void del(int x){
    if(!x)return;
    a[a[x].las].nex=a[x].nex;a[a[x].nex].las=a[x].las;
}

int main(){
    scanf("%d %d\n",&n,&q);a[0].nex=1;nxt[0]=1;
    for(int i=1;i<=n;i++){
        char c=getchar();nxt[i]=a[i].nex=i+1;a[i].las=i-1;
        if(c>='0' && c<='9')a[i].num=c-'0';else a[i].num=(c=='<')?10:11;
    }f[0]=1;
    for(int i=1,t=2,las=0;i<=n+1;++t,i=dir?a[i].nex:a[i].las){
        if(i==418){
            int yyy=1;
            yyy=0;
        }
        if(!f[i])f[i]=t;
        for(int j=nxt[i];j<=a[i].nex && f[j];j=nxt[j]){
            g[j]=t;nxt[i]=nxt[j];
        }
        for(int j=0;j<10;j++)num[t][j]=num[t-1][j];
        if(i>n)break;
        if(i==0){
            if(a[las].num>9)del(las);dir=1;las=0;
        }else
        if(a[i].num>9){
            if(a[las].num>9)del(las);dir=a[i].num-10;las=i;
        }else{
            las=0;
            if(a[i].num==0){
                del(i);++num[t][0];
            }else ++num[t][a[i].num--];
        }
    }
    for(int i=1;i<=q;i++){
        int l,r;scanf("%d %d",&l,&r);
        int h=f[l]-1,t=min((g[l]?g[l]:n*23),f[r+1])-1;
        for(int j=0;j<10;j++)printf("%d ",num[t][j]-num[h][j]);printf("\n");
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值