QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#870155#9907. 最大匹配 2 C1942huangjiaxu0 646ms50936kbC++142.8kb2025-01-25 15:01:092025-01-25 15:01:20

Judging History

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

  • [2025-01-25 15:01:20]
  • 评测
  • 测评结果:0
  • 用时:646ms
  • 内存:50936kb
  • [2025-01-25 15:01:09]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5,M=N*100,inf=1e9;
typedef pair<int,int> pii;
int n,m,a[N],b[N];
struct DS{
int a[N],b[N],rt[N],ls[M],rs[M],mn[M],tg[M],tot,res,sum;	
void init(){
	for(int i=1;i<=n;++i)a[i]=::a[i],b[i]=::b[i];
}
void pushup(int k){
	mn[k]=min(mn[ls[k]],mn[rs[k]]);
}
void pushtg(int &k,int v){
	if(!k)k=++tot;
	mn[k]+=v,tg[k]+=v;
}
void pushdown(int k){
	if(tg[k]){
		pushtg(ls[k],tg[k]);
		pushtg(rs[k],tg[k]);
		tg[k]=0;
	}
}
void add(int &k,int l,int r,int x,int y,int v){
	if(x<=l&&r<=y)return pushtg(k,v);
	if(!k)k=++tot;
	pushdown(k);
	int mid=l+r>>1;
	if(x<=mid)add(ls[k],l,mid,x,y,v);
	if(y>mid)add(rs[k],mid+1,r,x,y,v);
	pushup(k);
}
int query(int k,int l,int r,int x,int y){
	if(!k)return 0;
	if(x<=l&&r<=y)return mn[k];
	pushdown(k);
	int mid=l+r>>1,ans=inf;
	if(x<=mid)ans=min(ans,query(ls[k],l,mid,x,y));
	else ans=min(ans,query(rs[k],mid+1,r,x,y));
	return ans;
}
int find(int k,int l,int r,int x,int v){
	if(!k||mn[k]>=v)return -1;
	if(l==r)return l;
	pushdown(k);
	int mid=l+r>>1;
	if(x<=mid){
		int p=find(ls[k],l,mid,x,v);
		if(~p)return p;
	}
	return find(rs[k],mid+1,r,x,v);
}
int Ins(int x,int c){
	add(rt[c],1,n,x,n,-1);
	int pr=min(0,x>1?query(rt[c],1,n,1,x-1):0);
	int p=find(rt[c],1,n,x,pr);
	if(~p)return ++res,p;
	return 0;
}
int Del(int x,int c){
	int pr=min(0,x>1?query(rt[c],1,n,1,x-1):0);
	int p=find(rt[c],1,n,x,pr);
	add(rt[c],1,n,x,n,1);
	if(~p)return --res,p;
	return 0;
}
int ins(int x,int v,int c){
	if(v==-1)return ++sum,-Ins(x,c);
	else return Del(x,c);
}
int del(int x,int v,int c){
	if(v==-1)return --sum,Del(x,c);
	else return -Ins(x,c);
}
}d1,d2;
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i)scanf("%d",&a[i]);
	for(int i=1;i<=n;++i){
		scanf("%d",&b[i]);
		if(!b[i])b[i]=1;
		else b[i]=-1;
	}
	d1.init();
	reverse(a+1,a+n+1);
	reverse(b+1,b+n+1);
	for(int i=1;i<=n;++i)b[i]=-b[i];
	d2.init();
	for(int i=1;i<=n;++i){
		int p=d1.ins(i,d1.b[i],d1.a[i]);
		if(p>0)d1.del(p,d1.b[p],0);
		else if(p<0)d1.ins(-p,d1.b[-p],0);
		p=d2.ins(i,d2.b[i],d2.a[i]);
		if(p>0)d1.del(n-p+1,-d2.b[p],0);
		else if(p<0)d1.ins(n+p+1,-d2.b[-p],0);
	}
	printf("%d\n",d1.sum-d1.res);
	for(int i=1,x,y,z;i<=m;++i){
		scanf("%d%d%d",&x,&y,&z);
		if(!z)z=1;
		else z=-1;
		int p=d1.del(x,d1.b[x],d1.a[x]);
		if(p>0)d1.del(p,d1.b[p],0);
		else if(p<0)d1.ins(-p,d1.b[-p],0);
		p=d2.del(n-x+1,d2.b[n-x+1],d2.a[n-x+1]);
		if(p>0)d1.del(n-p+1,-d2.b[p],0);
		else if(p<0)d1.ins(n+p+1,-d2.b[-p],0);
		d1.a[x]=y,d2.a[n-x+1]=y;
		d1.b[x]=z,d2.b[n-x+1]=-z;
		p=d1.ins(x,d1.b[x],d1.a[x]);
		if(p>0)d1.del(p,d1.b[p],0);
		else if(p<0)d1.ins(-p,d1.b[-p],0);
		p=d2.ins(n-x+1,d2.b[n-x+1],d2.a[n-x+1]);
		if(p>0)d1.del(n-p+1,-d2.b[p],0);
		else if(p<0)d1.ins(n+p+1,-d2.b[-p],0);
		printf("%d\n",d1.sum-d1.res);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 16228kb

input:

100 0
1 1 2 1 2 2 2 2 2 1 2 1 1 2 2 1 2 2 2 2 2 1 1 2 2 2 1 2 2 2 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 1 1 2 1 2 1 1 1 2 2 2 2 2 2 1 1 1 2 1 1 1 1 1 2 2 1 1 2 1 1 2 1 1 2 2 2 1 2 2 2 1 2 1 2 1 2 1 1 2 1 1 2
1 1 0 1 0 0 0 0 1 1 0 1 0 1 0 1 1 1 1 0 0 0 1 0 0 0 1 1 0 0 0 0 0 1 1 0 1 1 0 0 0 0 1 1 1 1 1 ...

output:

42

result:

wrong answer 1st words differ - expected: '45', found: '42'

Subtask #2:

score: 0
Wrong Answer

Test #11:

score: 0
Wrong Answer
time: 0ms
memory: 16376kb

input:

2000 0
2 2 1 1 2 1 2 2 2 1 1 1 2 1 2 2 1 2 2 1 2 1 2 1 1 2 1 2 2 1 2 2 2 1 1 1 1 1 1 2 1 1 2 2 1 2 1 2 2 2 1 1 2 1 1 1 2 2 2 2 2 2 1 1 2 1 1 2 2 1 2 1 1 1 1 2 1 1 1 1 1 2 2 2 2 1 2 2 1 2 2 2 2 2 1 2 1 2 1 1 2 1 1 2 2 1 1 1 1 1 1 1 1 2 2 1 2 2 2 2 2 1 1 2 2 2 2 1 2 2 2 1 1 1 2 1 2 1 1 1 2 2 1 2 1 1 1...

output:

818

result:

wrong answer 1st words differ - expected: '954', found: '818'

Subtask #3:

score: 0
Wrong Answer

Test #31:

score: 0
Wrong Answer
time: 86ms
memory: 40820kb

input:

200000 0
1 2 2 2 2 2 2 1 1 2 2 1 1 1 2 1 1 1 2 1 2 1 1 1 2 1 1 1 1 2 2 2 2 2 1 2 2 1 2 1 1 2 2 2 2 1 2 2 1 2 1 1 2 1 1 2 1 2 2 1 2 2 2 1 1 2 1 1 1 2 2 2 2 1 1 2 2 1 1 2 1 2 2 2 2 2 1 1 2 2 2 2 1 2 1 2 2 2 1 2 2 2 2 1 2 2 2 1 1 1 2 2 1 2 2 2 1 1 1 1 1 2 1 2 1 2 1 2 1 2 1 2 2 1 2 2 2 1 1 1 2 1 2 1 1 1...

output:

72884

result:

wrong answer 1st words differ - expected: '99478', found: '72884'

Subtask #4:

score: 0
Wrong Answer

Test #61:

score: 0
Wrong Answer
time: 646ms
memory: 47876kb

input:

200000 200000
1 2 1 2 2 1 2 1 2 1 1 2 1 1 2 1 1 2 1 2 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 1 1 2 1 1 2 2 2 1 1 2 2 1 2 1 2 1 1 2 1 2 2 2 1 2 1 2 1 1 1 1 2 1 1 1 1 1 1 1 2 2 2 2 2 2 2 1 1 2 2 1 2 2 2 2 2 1 1 1 2 2 2 1 1 1 1 1 1 1 2 2 1 2 2 1 1 1 1 1 2 2 2 2 2 2 1 1 2 2 2 1 2 2 2 2 1 1 1 2 2 1 2 2 2 1 1 1 2 ...

output:

64348
64348
64349
64348
64345
64343
64343
64344
64344
64344
64344
64344
64347
64346
64346
64344
64343
64343
64345
64345
64345
64345
64343
64343
64344
64345
64345
64346
64347
64345
64343
64343
64343
64342
64342
64341
64342
64340
64340
64340
64341
64341
64340
64341
64340
64340
64340
64342
64341
64341
...

result:

wrong answer 1st words differ - expected: '99575', found: '64348'

Subtask #5:

score: 0
Wrong Answer

Test #71:

score: 0
Wrong Answer
time: 244ms
memory: 31516kb

input:

100000 100000
2 1 1 1 1 1 1 2 2 2 2 1 2 1 1 1 2 2 1 2 1 2 2 2 2 2 2 2 1 2 2 2 1 1 1 1 1 2 2 2 2 1 1 2 2 2 1 2 2 1 2 1 2 2 2 2 1 2 1 1 1 2 2 2 1 1 2 1 1 1 2 1 2 2 2 1 1 2 1 1 2 1 1 1 1 1 1 1 2 2 1 1 2 1 2 1 2 1 2 2 2 2 2 2 2 1 1 1 1 2 1 2 1 1 1 1 2 2 2 1 2 1 1 1 2 2 2 1 1 2 1 2 2 2 2 2 1 1 2 1 1 1 1 ...

output:

45989
45988
45988
45988
45988
45988
45988
45988
45988
45988
45987
45988
45988
45987
45986
45985
45984
45984
45984
45984
45984
45984
45984
45984
45983
45983
45984
45984
45985
45985
45984
45984
45984
45983
45983
45983
45983
45982
45982
45983
45983
45982
45981
45980
45980
45980
45980
45979
45979
45979
...

result:

wrong answer 1st words differ - expected: '49860', found: '45989'

Subtask #6:

score: 0
Wrong Answer

Test #101:

score: 0
Wrong Answer
time: 624ms
memory: 50936kb

input:

200000 200000
1 2 1 1 2 1 1 1 2 1 2 2 2 1 2 1 1 2 2 2 1 2 2 2 2 1 2 1 1 1 1 2 1 2 2 1 2 2 2 2 1 1 1 2 1 1 1 2 2 1 1 1 2 1 1 2 1 1 2 2 1 1 2 2 2 1 1 1 1 1 1 2 1 1 2 1 2 2 1 2 2 2 1 2 2 1 2 2 1 1 1 1 1 2 2 2 1 1 2 2 1 1 1 2 2 1 1 2 2 2 2 2 2 1 2 1 1 2 2 2 1 1 1 2 1 2 1 1 1 1 1 2 1 1 2 2 1 1 2 2 1 2 1 ...

output:

88378
88378
88378
88379
88380
88379
88379
88379
88379
88379
88379
88379
88379
88379
88380
88380
88380
88380
88381
88381
88382
88382
88383
88384
88384
88384
88384
88385
88385
88385
88385
88386
88387
88387
88387
88386
88385
88385
88386
88385
88386
88386
88386
88386
88385
88385
88385
88385
88385
88385
...

result:

wrong answer 1st words differ - expected: '99491', found: '88378'