QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#455389#6836. A Plus B Problemgrass8cow#WA 0ms11988kbC++172.2kb2024-06-26 13:08:292024-06-26 13:08:30

Judging History

你现在查看的是最新测评结果

  • [2024-06-26 13:08:30]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:11988kb
  • [2024-06-26 13:08:29]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n,q;
const int N=1e6+10;
int a[N],b[N];
char c[N];
set<int>s;
int tr[N],h[N],cf[N];
void ad(int x,int z){
    if(x==n+2)return;
    if(cf[x])s.erase(x);
    cf[x]+=z;
    if(cf[x])s.insert(x);
    for(;x<=n+1;x+=(x&-x))tr[x]+=z;
}
int ask(int x){int s=0;for(;x;x-=(x&-x))s+=tr[x];return s;}
int main(){
    scanf("%d%d",&n,&q);
    scanf("%s",c+2);for(int i=2;i<=n+1;i++)a[i]=c[i]-'0';
    scanf("%s",c+2);for(int i=2;i<=n+1;i++)b[i]=c[i]-'0';
    int t=0;
    for(int i=n+1;i;i--){
        h[i]=a[i]+b[i]+t;
        if(h[i]>=10)t=1,h[i]-=10;
        else t=0;
    }
    for(int i=1;i<=n+1;i++)printf("%d",h[i]);puts("");
    for(int i=1;i<=n+1;i++)if(h[i]!=h[i-1])ad(i,h[i]-h[i-1]);
    while(q--){
        int r,x,z;
        scanf("%d%d%d",&r,&x,&z),x++;
        int dt=z-((r==1)?a[x]:b[x]);
        ((r==1)?a[x]:b[x])=z;
        int e=ask(x);
        if(dt==0){printf("%d 0\n",e);continue;}
        if(dt>0){
            if(e+dt<10)ad(x,dt),ad(x+1,-dt),printf("%d %d\n",e+dt,2);
            else{
                int p1=cf[1];
                dt-=10;
                ad(x,dt),ad(x+1,-dt);int su=2;
                if(ask(x-1)!=9)ad(x-1,1),ad(x,-1);
                else{
                    auto it=s.lower_bound(x);
                    int p=*(--it);su+=x-p;
                    ad(p-1,1),ad(p,-1);
                    ad(p,-9),ad(x,9);
                    //[p,x)全都从9变成0,p-1再加上1
                    //记得判掉p-1=1.
                }
                if(p1!=cf[1])su--;
                printf("%d %d\n",e+dt,su+1);
            }
        }
        else{
            if(e>=-dt)ad(x,dt),ad(x+1,-dt),printf("%d %d\n",e+dt,2);
            else{
                int p1=cf[1];
                dt+=10;ad(x,dt),ad(x+1,-dt);int su=2;
                if(ask(x-1)!=0)ad(x-1,-1),ad(x,1);
                else{
                    auto it=s.lower_bound(x);
                    int p=*(--it);su+=x-p;
                    ad(p-1,-1),ad(p,1);
                    ad(p,9),ad(x,-9);
                }
                if(p1!=cf[1])p1--;
                printf("%d %d\n",e+dt,su+1);
            }
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 11988kb

input:

5 5
01234
56789
2 1 0
2 2 1
2 3 2
2 4 3
2 5 4

output:

058023
0 2
3 2
5 3
7 3
8 3

result:

wrong answer 1st lines differ - expected: '0 2', found: '058023'