QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#149407 | #6836. A Plus B Problem | qzez# | WA | 207ms | 13940kb | C++14 | 2.9kb | 2023-08-24 15:54:01 | 2023-08-24 15:54:03 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<typename T>
ostream& operator << (ostream &out,const vector<T>&x){
if(x.empty())return out<<"[]";
out<<'['<<x[0];
for(int len=x.size(),i=1;i<len;i++)out<<','<<x[i];
return out<<']';
}
template<typename T>
vector<T> ary(const T *a,int l,int r){
return vector<T>{a+l,a+1+r};
}
template<typename T>
void debug(T x){
cerr<<x<<'\n';
}
template<typename T,typename ...S>
void debug(T x,S ...y){
cerr<<x<<' ',debug(y...);
}
const int N=1e6+10;
int n,m,a[2][N],b[N];
char s[2][N];
int t[N<<2],laz[N<<2];
void pushup(int rt){
t[rt]=t[rt<<1]|t[rt<<1|1];
}
void pushcov(int rt,int x){
t[rt]=1<<x,laz[rt]=x;
}
void pushdown(int rt){
if(~laz[rt]){
pushcov(rt<<1,laz[rt]);
pushcov(rt<<1|1,laz[rt]);
laz[rt]=-1;
}
}
void build(int l=1,int r=n,int rt=1){
laz[rt]=-1;
if(l==r){
t[rt]=1<<b[l];return;
}
int mid=(l+r)>>1;
build(l,mid,rt<<1);
build(mid+1,r,rt<<1|1);
pushup(rt);
}
void cover(int L,int R,int x,int l=1,int r=n,int rt=1){
if(L<=l&&r<=R)return pushcov(rt,x);
int mid=(l+r)>>1;
pushdown(rt);
if(L<=mid)cover(L,R,x,l,mid,rt<<1);
if(mid<R)cover(L,R,x,mid+1,r,rt<<1|1);
pushup(rt);
}
void update(int x,int y,int l=1,int r=n,int rt=1){
if(l==r){
if(y>0)t[rt]<<=y;
else t[rt]>>=-y;
return;
}
int mid=(l+r)>>1;
pushdown(rt);
if(x<=mid)update(x,y,l,mid,rt<<1);
else update(x,y,mid+1,r,rt<<1|1);
pushup(rt);
}
int query(int x,int l=1,int r=n,int rt=1){
if(l==r)return __lg(t[rt]);
int mid=(l+r)>>1;
pushdown(rt);
if(x<=mid)return query(x,l,mid,rt<<1);
else return query(x,mid+1,r,rt<<1|1);
}
int findlast(int L,int R,int S,int l=1,int r=n,int rt=1){
if(!(t[rt]&S))return 0;
if(l==r)return l;
int mid=(l+r)>>1,s=0;
pushdown(rt);
if(mid<R)s=findlast(L,R,S,mid+1,r,rt<<1|1);
if(s)return s;
return findlast(L,R,S,l,mid,rt<<1);
}
void add(int x,int y){
int d=query(x);
cover(x,x,(d+y)%10);
if(d+y<=9){
printf("%d %d\n",d+y,2);
return;
}
int id=x>1?findlast(1,x-1,0xff):0,cnt=2;
if(id+1<x)cover(id+1,x-1,0),cnt+=x-id-1;
if(id)update(id,1),cnt++;
printf("%d %d\n",(d+y)%10,cnt);
}
void sub(int x,int y){
int d=query(x);
cover(x,x,(d-y+10)%10);
if(d>=y){
printf("%d %d\n",d-y,2);
return;
}
int id=x>1?findlast(1,x-1,0x1fe):0,cnt=2;
if(id+1<x)cover(id+1,x-1,9),cnt+=x-id-1;
if(id)update(id,-1),cnt++;
printf("%d %d\n",(d-y+10)%10,cnt);
}
void print(){
vector<int>a;
for(int i=1;i<=n;i++)a.push_back(query(i));
debug(a);
}
int main(){
scanf("%d%d%s%s",&n,&m,s[0]+1,s[1]+1);
for(int i=n;i>=1;i--){
for(int j=0;j<2;j++)a[j][i]=s[j][i]-'0';
b[i]+=a[0][i]+a[1][i];
if(i>1)b[i-1]+=b[i]/10;
b[i]%=10;
}
// debug(ary(b,1,n));
build();
for(int r,c,x;m--;){
scanf("%d%d%d",&r,&c,&x);
int las=a[--r][c];
if(las==x){
printf("%d 0\n",x);continue;
}
a[r][c]=x;
if(las<x)add(c,x-las);
else sub(c,las-x);
// print();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 13940kb
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: 3ms
memory: 11964kb
input:
1 1 1 1 1 1 9
output:
0 2
result:
ok single line: '0 2'
Test #3:
score: -100
Wrong Answer
time: 207ms
memory: 11908kb
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 6 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 8 0 1 3 4 2 7 3 0 3 8 3 8 3 8 2 1 0 3 3 0 4 2 3 5 2 9 2 4 2 8 2 4 2 5 3 3 2 6 0 5 2 3 2 2 2 4 2 8 3 0 2 5 2 6 2 1 3 4 2 4 2 4 2 5 3 7 3 1 0 8 2 9 3 9 3 1 2 1 4 7 2 6 2 5 2 7 0 0 2 ...
result:
wrong answer 3rd lines differ - expected: '9 0', found: '6 0'