QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#409806 | #6836. A Plus B Problem | Kevin5307 | WA | 325ms | 3740kb | C++23 | 2.1kb | 2024-05-12 18:46:59 | 2024-05-12 18:47:36 |
Judging History
answer
//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
int n,q;
string s,t;
int val[1001000];
set<int> st[3];
int state(int x)
{
if(x==9) return 1;
if(x<9) return 0;
return 2;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>q>>s>>t;
for(int i=0;i<n;i++)
{
s[i]^=48;
t[i]^=48;
val[i]=s[i]+t[i];
st[state(val[i])].insert(i);
}
while(q--)
{
int r,c,d;
cin>>r>>c>>d;
c--;
int tmp=val[c];
st[state(val[c])].erase(c);
int st1=state(val[c]);
int ch=0;
if(r==1)
ch=(d!=s[c]);
else
ch=(d!=t[c]);
if(r==1)
s[c]=d;
else
t[c]=d;
val[c]=s[c]+t[c];
st[state(val[c])].insert(c);
int st2=state(val[c]);
int nxt0=n,nxt2=n+1;
if(st[0].lower_bound(c+1)!=st[0].end())
nxt0=*st[0].lower_bound(c+1);
if(st[2].lower_bound(c+1)!=st[2].end())
nxt2=*st[2].lower_bound(c+1);
if(nxt0<nxt2)
{
if(st1==1) st1=0;
if(st2==1) st2=0;
}
else
{
if(st1==1) st1=2;
if(st2==1) st2=2;
}
int prv=0;
if(st[0].lower_bound(c)!=st[0].begin())
prv=max(prv,*prev(st[0].lower_bound(c)));
if(st[2].lower_bound(c)!=st[2].begin())
prv=max(prv,*prev(st[2].lower_bound(c)));
int ans=(tmp!=val[c]);
if(st1!=st2)
ans+=c-prv;
int delta=0;
if(c!=n-1)
{
if(val[c+1]==0) delta=0;
else if(val[c+1]==2) delta=1;
else if(nxt0<nxt2) delta=0;
else delta=1;
}
cout<<(val[c]+delta)%10<<" "<<ans+ch<<'\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3740kb
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: 3736kb
input:
1 1 1 1 1 1 9
output:
0 2
result:
ok single line: '0 2'
Test #3:
score: -100
Wrong Answer
time: 325ms
memory: 3624kb
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 2 7 3 0 2 9 3 6 4 0 0 1 3 4 2 7 3 0 3 8 3 8 3 8 2 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 9 2 9 3 9 3 1 2 2 4 7 2 5 2 5 2 4 0 0 2 ...
result:
wrong answer 66th lines differ - expected: '8 2', found: '9 2'