QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#822787 | #9907. 最大匹配 2 | Andy_Lin | 0 | 946ms | 35588kb | C++17 | 3.6kb | 2024-12-20 16:31:31 | 2024-12-20 16:31:31 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define N 200001
int n,m,a[N],b[N];
int lc[N*80],rc[N*80],tag[N*80],mi[N*80],tot;
vector<int>is,dl;
struct ddl{
int rt;
void pushup(int p){
mi[p]=min(mi[lc[p]],mi[rc[p]]);
}
void pushdown(int p){
if(!tag[p])return;
if(!lc[p])lc[p]=++tot;
if(!rc[p])rc[p]=++tot;
mi[lc[p]]+=tag[p];mi[rc[p]]+=tag[p];
tag[lc[p]]+=tag[p];tag[rc[p]]+=tag[p];
tag[p]=0;
}
void add(int &p,int l,int r,int L,int R,int x){
if(L>R)return;
if(!p)p=++tot;
if(L<=l&&r<=R){
tag[p]+=x;mi[p]+=x;return;
}
pushdown(p);
int mid=(l+r>>1);
if(L<=mid)add(lc[p],l,mid,L,R,x);
if(R>mid)add(rc[p],mid+1,r,L,R,x);
pushup(p);
}
int gtl(int p,int l,int r,int L,int R){
// printf("%d %d %d %d %d %d %d %d\n",p,l,r,L,R,mi[p],mi[lc[p]],mi[rc[p]]);
if(L>R)return 0;
int mid=(l+r>>1);
if(L<=l&&r<=R){
if(mi[p])return 0;
if(!p||l==r)return r;
pushdown(p);
if(!mi[rc[p]])return gtl(rc[p],mid+1,r,L,R);
return gtl(lc[p],l,mid,L,R);
}
pushdown(p);
if(R>mid){
int x=gtl(rc[p],mid+1,r,L,R);
if(x)return x;
}
return gtl(lc[p],l,mid,L,R);
}
int gtr(int p,int l,int r,int L,int R){
int mid=(l+r>>1);
if(L<=l&&r<=R){
if(mi[p])return 0;
if(!p||l==r)return l;
pushdown(p);
if(!mi[lc[p]])return gtr(lc[p],l,mid,L,R);
return gtr(rc[p],mid+1,r,L,R);
}
pushdown(p);
if(L<=mid){
int x=gtr(lc[p],l,mid,L,R);
if(x)return x;
}
return gtr(rc[p],mid+1,r,L,R);
}
void print(int p,int l,int r){
if(l==r){printf("%d ",mi[p]);return;}
pushdown(p);
int mid=(l+r>>1);
print(lc[p],l,mid);print(rc[p],mid+1,r);
pushup(p);
}
set<int>wp;
void il(int x,int op){
auto it=wp.lower_bound(x);
if(it!=wp.end()&&b[*it]==1){
add(rt,1,n,x,*it-1,1);
if(op)dl.push_back(*it);
wp.erase(it);return;
}
int y=gtl(rt,1,n,1,x-1);++y;
add(rt,1,n,y,x-1,-1);
if(op)is.push_back(y);
wp.insert(y);
}
void ir(int x,int op){
auto it=wp.upper_bound(x);
if(it!=wp.begin()&&b[*(--it)]==0){
add(rt,1,n,*it,x-1,1);
if(op)dl.push_back(*it);
wp.erase(it);return;
}
int y=gtr(rt,1,n,x,n);
add(rt,1,n,x,y-1,-1);
if(op)is.push_back(y);
wp.insert(y);
}
void del(int x,int op){
if(wp.find(x)!=wp.end()){
if(op)dl.push_back(x);wp.erase(x);return;
}
int y=gtr(rt,1,n,x,n);
add(rt,1,n,x,y-1,-1);
if(op)is.push_back(y);
wp.insert(y);
}
void der(int x,int op){
if(wp.find(x)!=wp.end()){
if(op)dl.push_back(x);wp.erase(x);return;
}
int y=gtl(rt,1,n,1,x-1);++y;
add(rt,1,n,y,x-1,-1);
if(op)is.push_back(y);
wp.insert(y);
}
}T[N];
void deal(){
for(auto i:is){
if(b[i]==0)T[0].il(i,0);
else T[0].ir(i,0);
}
for(auto i:dl){
if(b[i]==0)T[0].del(i,0);
else T[0].der(i,0);
}
is.clear();dl.clear();
}
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);
for(int i=1;i<=n;++i){
if(b[i]==0)T[a[i]].il(i,1);
else T[a[i]].ir(i,1);
deal();
}
printf("%d\n",(n-(int)T[0].wp.size())>>1);
while(m--){
int i,x,y;scanf("%d%d%d",&i,&x,&y);
if(b[i]==0)T[a[i]].del(i,1);
else T[a[i]].der(i,1);
deal();
a[i]=x;b[i]=y;
if(y==0)T[x].il(i,1);
else T[x].ir(i,1);
deal();
printf("%d\n",(n-(int)T[0].wp.size())>>1);
}
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 17628kb
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:
43
result:
wrong answer 1st words differ - expected: '45', found: '43'
Subtask #2:
score: 0
Wrong Answer
Test #11:
score: 0
Wrong Answer
time: 3ms
memory: 17392kb
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:
940
result:
wrong answer 1st words differ - expected: '954', found: '940'
Subtask #3:
score: 0
Wrong Answer
Test #31:
score: 0
Wrong Answer
time: 67ms
memory: 25980kb
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:
99466
result:
wrong answer 1st words differ - expected: '99478', found: '99466'
Subtask #4:
score: 0
Wrong Answer
Test #61:
score: 0
Wrong Answer
time: 939ms
memory: 34720kb
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:
99553 99553 99554 99554 99554 99555 99555 99556 99556 99556 99555 99555 99555 99554 99554 99553 99554 99554 99554 99554 99554 99553 99553 99552 99553 99554 99554 99555 99554 99555 99556 99556 99556 99555 99555 99555 99555 99556 99556 99556 99557 99557 99556 99557 99557 99557 99557 99557 99556 99556 ...
result:
wrong answer 1st words differ - expected: '99575', found: '99553'
Subtask #5:
score: 0
Wrong Answer
Test #71:
score: 0
Wrong Answer
time: 354ms
memory: 28092kb
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:
49748 49749 49749 49749 49749 49749 49749 49748 49749 49750 49750 49749 49749 49749 49749 49750 49750 49749 49749 49749 49749 49749 49749 49748 49748 49748 49748 49747 49746 49746 49746 49746 49746 49745 49746 49746 49746 49746 49746 49746 49746 49745 49744 49745 49745 49745 49745 49746 49746 49746 ...
result:
wrong answer 1st words differ - expected: '49860', found: '49748'
Subtask #6:
score: 0
Wrong Answer
Test #101:
score: 0
Wrong Answer
time: 946ms
memory: 35588kb
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:
99346 99347 99348 99349 99350 99349 99349 99350 99350 99350 99351 99351 99352 99353 99353 99352 99352 99351 99352 99352 99353 99353 99353 99354 99354 99354 99353 99353 99353 99353 99353 99353 99354 99354 99354 99353 99352 99352 99353 99352 99353 99353 99352 99352 99352 99352 99351 99350 99350 99350 ...
result:
wrong answer 1st words differ - expected: '99491', found: '99346'