QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#103408 | #4219. Insects | SolitaryDream# | WA | 8ms | 11880kb | C++20 | 2.8kb | 2023-05-05 18:21:51 | 2023-05-05 18:21:54 |
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*300];
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)
{
build(y,x,1);
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: 11852kb
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: 11880kb
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: 2ms
memory: 11828kb
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: 1ms
memory: 9868kb
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: 9844kb
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: 9788kb
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: 0
Accepted
time: 2ms
memory: 11808kb
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 3 4 5 6 7 8 8 9 10 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 25 25 25 25 26 26 26 26
result:
ok 48 numbers
Test #8:
score: 0
Accepted
time: 0ms
memory: 9764kb
input:
38 13 24 34 6 36 39 31 36 25 23 32 37 20 37 34 18 38 22 37 11 42 50 30 44 1 2 7 41 17 14 31 25 31 37 7 32 46 12 18 46 22 36 18 20 21 9 46 44 39 26 24 34 42 17 38 22 16 35 0 50 24 28 8 45 44 40 2 46 37 35 28 20 22 29 31 32 2 45 4 27 6
output:
1 1
result:
ok 2 number(s): "1 1"
Test #9:
score: 0
Accepted
time: 3ms
memory: 9752kb
input:
8 20 46 34 26 11 23 40 29 21 9 48 13 10 47 4 28 30 22 34 8 23 21 9 31 1 44 27 9 12 48 17 43 24 17 15 48 8 22 5 27 26 46 27 42 0 14 28 9 34 5 2 8 29 26 7 13 3 44 19 50 7 40 29 43 31 49 31 50 26 20 19 2 10 39 25 41 0
output:
1 1 2 2 3 3 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6
result:
ok 30 numbers
Test #10:
score: 0
Accepted
time: 2ms
memory: 9748kb
input:
14 47 8 17 15 15 9 0 17 12 27 44 31 42 44 16 11 22 1 12 49 31 24 0 6 41 24 46 12 11 48 10 20 23 39 6 39 34 31 44 16 49 50 8 48 22 22 29 36 22 12 20
output:
1 2 3 4 5 6 7 8 9 10 11
result:
ok 11 numbers
Test #11:
score: 0
Accepted
time: 0ms
memory: 11852kb
input:
30 33 49 47 40 4 49 33 30 9 0 16 12 26 7 25 25 44 40 2 19 31 37 6 11 21 46 42 16 25 8 15 11 42 24 14 44 23 16 48 30 24 39 32 50 14 9 49 22 29 5 24 49 37 1 7 13 20 25 8 17 24 31 18 20 1 7 21 4 34 10 10 39 43 16 5 27 26 40 19 36 14 18 12 34 12 49 5 4 39 3 38 7 15 18 44 26 33 13 5 13 14 34 49 28 27 23 ...
output:
1 2 3 4 4 5 5 6 7 8 9 10 11 11 11 12 13 14 14 14 15 16 17 18
result:
ok 24 numbers
Test #12:
score: 0
Accepted
time: 3ms
memory: 9868kb
input:
15 16 10 40 44 4 27 29 24 47 11 37 9 28 19 21 47 47 49 34 4 1 20 28 32 42 28 28 3 46 33 30 8 14 36 37 4 13 6 26 2 23 33 43 0 6 27 34 0 0 17 38 50 35 7 28 7 0 33 49 23 0 45 29 47 5 23 42 45 14 25 1 5 40 35 37 32 35 12 1 16 32 32 26 47 32 15 25 40 40 20 34
output:
0 1 1 2 2 3 3 4 4 5 6 6 6 7 7 8 9 9 10 10 10 11 12 12 12 12 13 13 13 13
result:
ok 30 numbers
Test #13:
score: 0
Accepted
time: 2ms
memory: 9820kb
input:
44 23 10 13 27 7 41 45 48 10 39 36 44 39 8 46 4 25 43 21 14 16 25 15 1 14 0 35 49 28 38 29 45 48 39 24 4 49 21 29 12 15 5 26 7 30 21 12 30 39 26 23 20 40 28 45 33 46 41 4 11 21 18 38 28 45 3 21 10 38 18 10 49 36 15 30 7 43 2 23 36 2 18 17 16 48 13 6 25 4 33 10 42 43 42 3 16 37
output:
1 2 3 4
result:
ok 4 number(s): "1 2 3 4"
Test #14:
score: 0
Accepted
time: 2ms
memory: 9824kb
input:
19 4 15 35 35 46 16 16 24 34 28 35 8 42 46 44 16 27 46 19 2 5 17 44 25 22 23 49 3 44 20 49 49 49 39 1 47 22 5 31 31 34 33 34 37 43 4 20 32 17 0 34 6 40 12 44 46 6 24 43 47 2 23 18 35 32 32 1 1 11 40 49 23 40 27 14 16 17 13 36 42 42 19 9 47 34 10 17 12 26 6 1 45 43 15 50 16 24 48 44 42 18
output:
1 2 3 4 5 5 6 6 7 7 7 7 8 8 8 9 9 9 9 9 10 10 11 11 11 11 12 13 13 14 14
result:
ok 31 numbers
Test #15:
score: 0
Accepted
time: 4ms
memory: 11804kb
input:
14 17 30 17 44 41 19 29 4 1 3 46 35 46 36 10 14 1 21 36 42 43 47 16 35 30 44 29 25 29 31 28 8 33 47 24 1 7 34 32 20 47 20 32 33 24 25 33 40 0 34 14 28 31 10 16 22 50 43 0 43 39 14 31 36 39 38 31 11 48 11 5 5 21 49 48 15 5 47 3 43 9 26 14 10 12 29 47
output:
1 2 3 4 5 6 7 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 10 10 10 10 10 10 10
result:
ok 29 numbers
Test #16:
score: 0
Accepted
time: 4ms
memory: 9816kb
input:
18 39 23 25 29 18 20 33 50 26 7 33 27 29 35 21 29 4 18 3 21 40 15 19 15 40 4 6 33 39 12 1 48 18 46 32 12 164 8 27 46 18 1 44 48 35 17 32 8 29 20 33 37 4 35 34 6 13 10 0 48 50 22 36 46 46 5 9 44 27 40 24 0 39 13 13 41 24 18 8 37 19 34 18 41 44 45 47 6 3 23 39 35 47 28 18 21 29 25 29 26 15 34 29 3 6 3...
output:
1 2 2 3 4 4 5 5 6 6 6 7 8 9 9 10 11 11 11 12 12 13 14 15 16 16 17 17 17 17 17 17 17 17 17 17 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 ...
result:
ok 164 numbers
Test #17:
score: 0
Accepted
time: 0ms
memory: 9840kb
input:
2 1 19 16 29 1 23 41
output:
1
result:
ok 1 number(s): "1"
Test #18:
score: 0
Accepted
time: 8ms
memory: 9936kb
input:
177 7 4 20 40 39 13 35 7 42 45 1 9 49 40 39 36 7 47 50 10 12 37 8 27 3 3 4 28 48 39 48 14 36 22 27 38 39 37 23 38 14 41 42 8 49 28 43 6 45 23 34 25 41 42 25 43 5 32 26 10 5 36 16 34 8 8 28 44 6 16 0 47 7 19 2 24 7 21 18 49 4 27 33 27 26 44 20 24 46 45 42 39 15 40 50 17 23 11 7 14 16 0 8 27 46 14 10 ...
output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 49 50 51 51 52 53 54 55 56 57 58 58 59 60 60 60 61 61 62 63 64 65 66 67 68 69 70 70 71 72 73 74 75 76 77 78 79 80 81 81 82 83 84 85 86 86 87 87 88 89 90 90 91 ...
result:
ok 157 numbers
Test #19:
score: 0
Accepted
time: 1ms
memory: 9844kb
input:
79 25 43 36 48 12 47 1 39 14 41 24 17 43 5 27 4 50 19 14 1 39 46 19 20 50 17 8 37 43 40 30 23 8 44 27 13 43 31 23 48 33 5 15 22 3 6 47 21 18 21 22 9 6 47 43 2 15 45 2 2 0 18 43 35 5 20 43 6 48 9 24 3 29 37 29 45 28 42 28 41 29 20 50 3 48 13 31 33 15 16 4 43 34 4 1 49 2 29 5 35 4 5 28 32 31 25 45 5 4...
output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 32 33 34 35 36 37 38 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 58 59 60 61 62 62 63 63 63 63 63 63 64 65 66 66 66 66 66 67 68 68 68 68 68 68 68 69 70 70 71 71 71 72 72 72 73 73 73 73 73 73 73 ...
result:
ok 170 numbers
Test #20:
score: 0
Accepted
time: 2ms
memory: 11872kb
input:
97 31 36 0 29 1 36 36 45 24 37 48 24 48 28 27 17 47 34 43 32 25 5 50 24 46 28 20 35 15 39 49 44 49 40 43 11 36 36 29 41 21 10 12 41 2 8 17 16 12 42 36 4 9 3 1 7 36 37 12 50 9 21 10 33 28 45 47 31 26 23 11 26 39 31 40 33 47 48 1 37 48 8 18 17 0 3 1 24 34 1 29 22 9 9 36 18 26 23 23 45 36 2 40 24 21 22...
output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 21 22 23 24 25 26 27 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 47 48 49 49 50 51 51 52 53 54 55 56 56 57 57 58 59 60 61 62 63 64 65 66 67 67 68 68 68 68 69 70 71 71 71 72 72 73 73 73 74 75 76 77 77 77 78 78 79 80 81 82 83 84 ...
result:
ok 143 numbers
Test #21:
score: 0
Accepted
time: 1ms
memory: 9860kb
input:
108 35 22 15 20 36 28 19 9 16 30 35 39 12 7 23 3 34 38 35 39 4 14 12 7 3 13 18 28 4 35 5 48 19 14 31 10 22 27 0 6 40 31 12 22 48 7 25 45 8 6 30 21 34 35 48 41 10 1 18 35 44 32 13 16 38 32 33 35 45 50 2 41 24 9 4 41 28 21 6 8 12 0 31 35 28 28 46 26 48 49 18 28 12 41 48 22 37 26 27 3 32 5 5 19 46 6 39...
output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
result:
ok 45 numbers
Test #22:
score: -100
Wrong Answer
time: 0ms
memory: 11860kb
input:
70 14 11 23 24 9 10 30 37 19 6 5 41 24 49 21 3 50 33 19 27 8 5 50 39 19 0 20 23 35 40 24 10 46 44 20 36 17 48 16 17 36 11 6 50 42 0 41 7 33 24 14 24 30 4 10 22 41 38 0 17 34 26 41 49 13 21 46 1 47 29 13 27 8 15 1 4 14 25 30 10 25 31 6 14 11 32 10 20 19 27 36 45 42 7 46 15 10 36 21 44 13 31 13 8 20 4...
output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 47 48 48 49 50 51 51 52 53 54 55 55 55 55 55 55 55 56 56 56 56 57 58 58 58 58 58 58 58 58 58 59 59 59 59 59 59 59 59 59 59 60 60 61 61 61 61 61 62 62 62 62 62 62 62 ...
result:
wrong answer 60th numbers differ - expected: '56', found: '55'