QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#455391#6836. A Plus B Problemgrass8cow#WA 376ms14128kbC++172.1kb2024-06-26 13:09:062024-06-26 13:09:06

Judging History

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

  • [2024-06-26 13:09:06]
  • 评测
  • 测评结果:WA
  • 用时:376ms
  • 内存:14128kb
  • [2024-06-26 13:09:06]
  • 提交

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++)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: 100
Accepted
time: 2ms
memory: 13996kb

input:

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

output:

0 2
3 2
5 3
7 3
8 3

result:

ok 5 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 11948kb

input:

1 1
1
1
1 1 9

output:

0 2

result:

ok single line: '0 2'

Test #3:

score: -100
Wrong Answer
time: 376ms
memory: 14128kb

input:

10 1000000
6869373857
3130626142
1 9 2
1 10 0
2 7 6
1 1 0
1 7 6
2 10 4
2 3 9
2 4 2
2 4 4
2 7 0
1 2 4
1 9 8
1 3 7
1 7 1
1 1 5
2 1 6
1 3 5
2 5 8
2 6 5
1 6 3
1 3 8
2 4 2
2 6 3
2 2 6
1 10 9
2 1 1
2 5 4
1 1 8
2 4 0
1 9 1
1 1 8
2 4 2
2 9 2
1 10 3
1 8 9
1 4 6
2 3 0
1 1 6
1 7 1
1 10 9
2 4 4
2 5 9
2 1 8
1 9 ...

output:

6 2
2 2
9 0
3 2
2 8
4 2
6 2
2 2
4 2
6 5
6 3
2 4
7 2
2 2
8 2
1 2
5 2
1 3
2 3
8 3
8 2
2 2
6 2
1 3
3 3
7 3
7 3
0 2
9 3
6 4
0 0
1 3
4 2
7 3
0 3
8 3
8 3
8 3
2 0
3 3
0 3
2 3
5 2
9 2
4 2
8 2
3 3
5 3
3 2
5 0
4 2
3 2
1 2
4 2
7 3
0 2
5 2
6 2
0 3
4 2
4 2
3 2
5 3
6 3
3 0
8 2
9 3
9 3
1 2
1 4
7 2
5 2
5 2
4 0
0 2
...

result:

wrong answer 26th lines differ - expected: '7 2', found: '7 3'