QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#103406 | #4219. Insects | SolitaryDream# | WA | 3ms | 11872kb | C++20 | 2.8kb | 2023-05-05 18:15:00 | 2023-05-05 18:15:01 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+1e3+7;
int n,m;
int head[N*31],cnt=1,hd[N*31];
struct Edge{
int ne,to,w;
}edg[N*200];
void build(int u,int v,int w)
{
++cnt;
edg[cnt].to=v;
edg[cnt].ne=head[u];
head[u]=cnt;
edg[cnt].w=w;
++cnt;
edg[cnt].to=u;
edg[cnt].ne=head[v];
head[v]=cnt;
edg[cnt].w=0;
}
int d[N*100],S,T;
int rt[N],tot;
struct T{
int ls,rs;
}t[N*31];
queue<int>q;
bool bfs()
{
fill(d+S,d+T+1,-1);
d[S]=0;
q.push(S);
for(int i=S;i<=T;i++)
hd[i]=head[i];
while(!q.empty())
{
int x=q.front();
q.pop();
for(int tmp=head[x];tmp;tmp=edg[tmp].ne)
{
int v=edg[tmp].to;
if(d[v]!=-1||!edg[tmp].w)
continue;
d[v]=d[x]+1;
q.push(v);
}
}
return d[T]!=-1;
}
int dinic(int x,int mn)
{
if(!mn||x==T)
return mn;
int tmpf,flow=0;
for(int &tmp=hd[x];tmp;tmp=edg[tmp].ne)
{
int v=edg[tmp].to;
if(d[v]==d[x]+1&&(tmpf=dinic(v,min(mn,edg[tmp].w)))>0)
{
flow+=tmpf;
mn-=tmpf;
edg[tmp].w-=tmpf;
edg[tmp^1].w+=tmpf;
}
if(!mn)
break;
}
if(!flow)
d[x]=-1;
return flow;
}
vector<int>pt;
void ins(int x,int &y,int l,int r,int p)
{
y=++tot;
t[y]=t[x];
if(l==r)
{
pt.push_back(y);
return;
}
int mid=(l+r)>>1;
if(p<=mid)
ins(t[x].ls,t[y].ls,l,mid,p);
else
ins(t[x].rs,t[y].rs,mid+1,r,p);
}
using pii=pair<int,int>;
pii blk[N];
void adde(int x,int l,int r,int L,int R,int f)
{
if(!x)
return;
if(L<=l&&r<=R)
{
build(f,x,1e9);
return;
}
int mid=(l+r)>>1;
if(L<=mid)
adde(t[x].ls,l,mid,L,R,f);
if(R>mid)
adde(t[x].rs,mid+1,r,L,R,f);
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d%d",&blk[i].first,&blk[i].second);
sort(blk+1,blk+n+1);
S=0;
for(int i=1;i<=n;i++)
ins(rt[i-1],rt[i],0,1e5,blk[i].second);
for(int i=1;i<=tot;i++)
{
if(t[i].ls)
build(i,t[i].ls,1e9);
if(t[i].rs)
build(i,t[i].rs,1e9);
}
scanf("%d",&m);
T=tot+m+1;
for(auto x:pt)
build(x,T,1);
int ans=0;
for(int i=1;i<=m;i++)
{
pii u;
scanf("%d%d",&u.first,&u.second);
build(S,tot+i,1);
int p=upper_bound(blk+1,blk+n+1,u)-blk-1;
adde(rt[p],0,1e5,0,u.second,tot+i);
while(bfs())
ans+=dinic(S,1e9);
printf("%d\n",ans);
}
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 11812kb
input:
3 0 0 1 1 2 2 4 0 0 1 1 0 0 3 3
output:
1 2 2 3
result:
ok 4 number(s): "1 2 2 3"
Test #2:
score: 0
Accepted
time: 0ms
memory: 9760kb
input:
9 22 44 7 6 10 48 46 20 21 35 33 16 36 41 29 4 45 22 7 46 39 44 32 1 48 43 19 28 34 8 48 15 18
output:
1 2 2 3 4 4 4
result:
ok 7 numbers
Test #3:
score: 0
Accepted
time: 0ms
memory: 9752kb
input:
7 25 13 38 45 30 28 28 29 16 34 45 4 47 13 8 24 16 10 18 8 28 40 47 28 35 5 25 29 0 41 17
output:
0 0 0 1 2 2 2 3
result:
ok 8 numbers
Test #4:
score: 0
Accepted
time: 0ms
memory: 11796kb
input:
10 47 32 0 16 18 11 17 19 40 49 36 24 3 26 15 45 23 29 42 3 5 42 18 22 3 30 13 35 19 43 29
output:
1 1 2 3 4
result:
ok 5 number(s): "1 1 2 3 4"
Test #5:
score: 0
Accepted
time: 3ms
memory: 9804kb
input:
6 2 5 22 3 28 41 41 36 9 8 8 17 2 24 7 49 35
output:
1 2
result:
ok 2 number(s): "1 2"
Test #6:
score: 0
Accepted
time: 1ms
memory: 11872kb
input:
2 27 36 5 39 6 47 22 45 4 44 2 24 2 29 11 21 37
output:
0 0 0 0 0 0
result:
ok 6 numbers
Test #7:
score: -100
Wrong Answer
time: 2ms
memory: 9768kb
input:
30 35 14 26 38 50 17 21 0 14 0 39 2 5 45 1 18 22 50 5 49 35 16 37 43 15 11 22 16 4 9 44 36 1 23 42 19 33 44 2 44 35 16 21 36 23 46 39 1 15 29 9 17 31 27 37 50 15 24 30 38 48 10 38 28 0 33 5 33 11 36 27 4 30 4 18 23 28 4 8 16 20 24 47 14 34 30 45 47 10 4 48 36 2 10 20 11 39 49 39 11 50 48 36 28 41 23...
output:
1 2 2 3 4 5 6 7 7 8 9 10 11 12 13 13 13 13 14 15 16 17 17 17 18 18 19 20 21 22 23 23 23 23 23 23 24 24 24 24 24 24 24 24 25 25 25 25
result:
wrong answer 3rd numbers differ - expected: '3', found: '2'