QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#237051 | #6836. A Plus B Problem | Andy# | WA | 2ms | 9544kb | C++20 | 2.1kb | 2023-11-04 12:54:00 | 2023-11-04 12:54:00 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read(){
char c=getchar();
int f=1,x=0;
for(;c<'0'||c>'9';c=getchar()) if(c=='-') f=-1;
for(;c>='0'&&c<='9';c=getchar()) x=x*10+c-'0';
return f*x;
}
const int N=1e6+5;
int n,q;
int num[4][N];
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n>>q;
string s;
cin>>s;
for(int i=0;i<s.length();i++)
num[1][i+1]=s[i]-'0';
cin>>s;
for(int i=0;i<s.length();i++)
num[2][i+1]=s[i]-'0';
int res=0;
set<int> v;
for(int i=n;i>=1;i--)
{
if(num[2][i]+num[1][i]!=9)
v.insert(i);
if(num[1][i]+num[2][i]+res>=10)
{
num[3][i]=(num[1][i]+num[2][i]+res)%10;
res=1;
}
else
{
num[3][i]=num[1][i]+num[2][i]+res;
res=0;
}
//cout<<num[3][i]<<' ';
}
v.insert(0);
int r,c,d;
int ans=0;
while(q--)
{
cin>>r>>c>>d;
auto u=v.upper_bound(c);
bool flag=0;
if(u!=v.end())
{
if(num[1][*u]+num[2][*u]>9)flag=1;
}
if(num[r][c]==d)
{
cout<<(num[1][c]+num[2][c]+flag)%10<<" 0\n";
}
if(num[1][c]+num[2][c]+flag<=9)
{
if(num[3-r][c]+d+flag<=9)
{
num[3][c]=num[3-r][c]+d+flag;
num[r][c]=d;
cout<<num[3][c]<<" 2\n";
if(num[1][c]+num[2][c]==9)v.erase(c);
else v.insert(c);
continue;
}
else
{
ans=2;
num[3][c]=(num[3-r][c]+d+flag)%10;
num[r][c]=d;
if(num[1][c]+num[2][c]==9)v.erase(c);
auto bef=v.lower_bound(c);
bef--;
if(*bef)
ans+=c-*bef;
else ans+=c-(*bef+1);
cout<<num[r][c]<<' '<<ans<<'\n';
continue;
}
}
else
{
if(num[3-r][c]+d+flag<=9)
{
ans=2;
num[3][c]=num[3-r][c]+d+flag;
num[r][c]=d;
if(num[1][c]+num[2][c]==9)
v.erase(c);
else v.insert(c);
auto bef=v.lower_bound(c);
bef--;
if(*bef)
ans+=c-*bef;
else ans+=c-*bef-1;
cout<<num[3][c]<<' '<<ans<<'\n';
continue;
}
else
{
ans=2;
num[r][c]=d;
num[3][c]=(num[1][c]+num[2][c]+flag)%10;
cout<<num[3][c]<<' '<<ans<<'\n';
}
}
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 9544kb
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: -100
Wrong Answer
time: 1ms
memory: 9536kb
input:
1 1 1 1 1 1 9
output:
9 2
result:
wrong answer 1st lines differ - expected: '0 2', found: '9 2'