QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#608259 | #6836. A Plus B Problem | Dixiky_215 | WA | 3ms | 15976kb | C++20 | 4.3kb | 2024-10-03 20:12:03 | 2024-10-03 20:12:04 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAXN=1e6+7;
int n,q;
int l[MAXN*4],r[MAXN*4],maxl[MAXN],minl[MAXN];
int lazy[MAXN];
int a[MAXN][3];
string bb;
int s[MAXN];
void push_down(int x)
{
if(lazy[x]!=-1)
{
lazy[x*2]=lazy[x];
lazy[2*x+1]=lazy[x];
lazy[x]=-1;
}
return;
}
void push_up(int x)
{
int s1,s2;
if(lazy[x*2]!=-1) s1=lazy[x*2];
else s1=maxl[x*2];
if(lazy[2*x+1]!=-1) s2=lazy[2*x+1];
else s2=maxl[2*x+1];
maxl[x]=max(s1,s2);
if(lazy[x*2]!=-1) s1=lazy[x*2];
else s1=minl[x*2];
if(lazy[2*x+1]!=-1) s2=lazy[2*x+1];
else s2=minl[2*x+1];
minl[x]=min(s1,s2);
}
void build(int x,int li,int ri)
{
int mid=(li+ri)>>1;
l[x]=li;r[x]=ri;
maxl[x]=-1e9;minl[x]=1e9;
lazy[x]=-1;
if(li==ri)
{
maxl[x]=s[li];
minl[x]=s[li];
return;
}
build(2*x,li,mid);
build(2*x+1,mid+1,ri);
push_up(x);
return;
}
void modify(int x,int li,int ri,int y)
{
int mid=(l[x]+r[x])>>1;
if(l[x]==li&&r[x]==ri)
{
lazy[x]=y;
return;
}
push_down(x);
push_up(x);
if(ri<=mid) modify(2*x,li,ri,y);
else if(li>mid) modify(2*x+1,li,ri,y);
else modify(2*x,li,mid,y),modify(2*x+1,mid+1,ri,y);
push_up(x);
return;
}
int ask_val(int x,int loc)
{
int mid=(l[x]+r[x])>>1;
if(l[x]==r[x])
{
if(lazy[x]!=-1) return lazy[x];
return maxl[x];
}
push_down(x);
push_up(x);
if(loc<=mid) return ask_val(2*x,loc);
else return ask_val(2*x+1,loc);
}
int ask_max(int x,int li,int ri)
{
int mid=(l[x]+r[x])>>1;
if(l[x]==li&&r[x]==ri)
{
if(lazy[x]!=-1) return lazy[x];
return maxl[x];
}
push_down(x);
push_up(x);
if(ri<=mid) return ask_max(2*x,li,ri);
else if(li>mid) return ask_max(2*x+1,li,ri);
else return max(ask_max(2*x,li,mid),ask_max(2*x+1,mid+1,ri));
}
int ask_min(int x,int li,int ri)
{
int mid=(l[x]+r[x])>>1;
if(l[x]==li&&r[x]==ri)
{
if(lazy[x]!=-1) return lazy[x];
return minl[x];
}
push_down(x);
push_up(x);
if(ri<=mid) return ask_min(2*x,li,ri);
else if(li>mid) return ask_min(2*x+1,li,ri);
else return min(ask_min(2*x,li,mid),ask_min(2*x+1,mid+1,ri));
}
int main() {
cin.tie(nullptr) -> sync_with_stdio(false);
cin>>n>>q;
cin>>bb;
for(int i=2;i<=n+1;i++) a[i][1]=bb[i-2]-'0';
cin>>bb;
for(int i=2;i<=n+1;i++) a[i][2]=bb[i-2]-'0';
for(int i=n+1;i>=2;i--)
{
s[i-1]+=(s[i]+a[i][1]+a[i][2])/10;
s[i]=(s[i]+a[i][1]+a[i][2])%10;
}
build(1,1,n+1);
int kkk=0;
while(q--)
{
kkk++;
int opt,id,sss;
cin>>opt>>id>>sss;
id++;
int nowl=ask_val(1,id);
int cha=sss-a[id][opt];
// cerr<<nowl<<" "<<cha<<" asd"<<endl;
if(cha==0)
{
cout<<ask_val(1,id)<<" 0\n";
continue;
}
int ans=1;
if(nowl+cha<0)
{
int aim=nowl+cha+10;
modify(1,id,id,aim);
ans++;
int l=2,r=id-1,loc=-1,mid;
while(l<=r)
{
mid=(l+r)>>1;
int maxk=ask_max(1,mid,id-1);
int mink=ask_min(1,mid,id-1);
if(maxk==0&&mink==0) loc=mid,r=mid-1;
else l=mid+1;
}
if(loc!=-1)
{
ans+=id-loc;
modify(1,loc,id-1,9);
}
else loc=id;
ans++;
int sk=ask_val(1,loc-1);
modify(1,loc-1,loc-1,sk-1);
}
else if(nowl+cha>10)
{
int aim=nowl+cha-10;
modify(1,id,id,aim);
ans++;
int l=2,r=id-1,loc=-1,mid;
while(l<=r)
{
mid=(l+r)>>1;
int maxk=ask_max(1,mid,id-1);
int mink=ask_min(1,mid,id-1);
if(maxk==9&&mink==9) loc=mid,r=mid-1;
else l=mid+1;
}
if(loc!=-1)
{
ans+=id-loc;
modify(1,loc,id-1,0);
}
else loc=id;
ans++;
int sk=ask_val(1,loc-1);
modify(1,loc-1,loc-1,sk+1);
}
else
{
// if(kkk==3) cerr<<" asd"<<endl;
int aim=nowl+cha;
modify(1,id,id,aim);
ans++;
}
cout<<ask_val(1,id)<<' '<<ans<<'\n';
a[id][opt]=sss;
}
return 0;
}
/*
5 5
01234
56789
2 1 0
2 2 1
2 3 2
2 4 3
2 5 4
5 1
01234
56789
2 1 0
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 15976kb
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: 0ms
memory: 15908kb
input:
1 1 1 1 1 1 9
output:
10 2
result:
wrong answer 1st lines differ - expected: '0 2', found: '10 2'