QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#103409 | #4219. Insects | SolitaryDream# | TL | 117ms | 13944kb | C++20 | 2.8kb | 2023-05-05 18:24:54 | 2023-05-05 18:24:55 |
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(x)
build(y,x,1);
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);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 9876kb
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: 1ms
memory: 9804kb
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: 3ms
memory: 9804kb
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: 2ms
memory: 9720kb
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: 0ms
memory: 9748kb
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: 9808kb
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: 4ms
memory: 11860kb
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: 4ms
memory: 9824kb
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: 9816kb
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: 1ms
memory: 9728kb
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: 1ms
memory: 9848kb
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: 0ms
memory: 9840kb
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: 0ms
memory: 11868kb
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: 1ms
memory: 9872kb
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: 1ms
memory: 11796kb
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: 9808kb
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: 3ms
memory: 9760kb
input:
2 1 19 16 29 1 23 41
output:
1
result:
ok 1 number(s): "1"
Test #18:
score: 0
Accepted
time: 12ms
memory: 11868kb
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: 7ms
memory: 9768kb
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: 4ms
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: 2ms
memory: 11868kb
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: 0
Accepted
time: 6ms
memory: 11872kb
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 56 56 56 56 56 56 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:
ok 134 numbers
Test #23:
score: 0
Accepted
time: 2ms
memory: 11824kb
input:
161 21 22 33 27 10 39 41 22 4 27 47 45 28 17 23 9 8 15 44 7 9 46 3 25 18 18 18 46 19 27 43 38 31 2 38 14 3 25 33 16 31 11 40 33 9 20 42 31 12 19 40 13 39 37 44 16 4 44 5 29 27 34 33 7 23 23 7 37 35 12 35 1 29 23 30 17 45 28 16 9 18 36 26 49 7 24 25 35 4 6 48 2 34 5 0 13 34 34 1 1 7 13 40 14 13 43 47...
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 46 47 48 49 50 51 52 53 54 55 56
result:
ok 56 numbers
Test #24:
score: 0
Accepted
time: 4ms
memory: 9828kb
input:
28 35 19 39 7 20 39 42 43 33 5 49 20 26 43 40 3 9 3 37 39 33 19 10 45 13 24 16 49 30 30 27 31 8 34 13 7 21 33 42 19 27 19 28 27 1 9 31 16 18 26 48 13 38 4 49 46 67 28 46 21 25 35 38 39 1 29 14 43 9 14 13 48 28 25 2 45 22 35 27 14 30 21 50 49 8 6 11 50 22 10 12 4 35 22 3 39 43 4 49 17 46 33 20 3 30 4...
output:
1 2 3 3 4 5 6 7 7 8 9 10 11 12 12 13 13 13 13 14 14 15 16 16 17 18 18 19 19 20 21 22 23 23 23 23 24 24 25 25 26 26 26 27 27 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28 28
result:
ok 67 numbers
Test #25:
score: 0
Accepted
time: 3ms
memory: 13944kb
input:
114 28 46 26 6 35 33 39 9 46 29 18 38 49 44 20 12 36 36 21 5 13 46 6 29 32 46 29 5 32 39 9 32 39 14 32 22 8 13 43 24 12 2 23 2 6 31 30 39 17 1 34 31 29 40 21 19 8 15 12 0 31 49 50 41 12 23 24 17 8 37 37 33 45 1 42 3 23 33 27 40 27 9 19 0 32 28 11 48 46 45 49 41 2 45 8 45 5 32 12 21 18 2 34 18 5 38 3...
output:
1 2 3 4 4 5 6 7 8 9 9 10 11 11 11 12 13 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 28 29 30 31 32 33 34 34 35 36
result:
ok 43 numbers
Test #26:
score: 0
Accepted
time: 10ms
memory: 9816kb
input:
45 7 17 14 12 37 18 4 28 45 13 23 21 23 19 35 36 25 19 24 23 41 6 3 23 32 1 45 2 7 7 39 2 5 38 29 6 50 14 8 7 0 13 5 49 21 13 31 29 22 16 44 0 0 38 29 28 18 50 27 40 1 18 49 36 39 30 30 6 32 4 19 7 14 37 20 27 35 6 11 15 2 16 0 37 22 23 36 1 38 43 625 40 9 24 26 14 30 1 49 48 48 46 43 14 4 37 14 9 2...
output:
1 2 3 4 5 6 6 7 8 9 10 10 11 12 13 14 15 15 16 17 18 19 20 21 22 23 24 24 25 26 27 28 29 30 31 32 33 33 34 34 34 35 36 36 36 36 36 37 37 38 39 40 40 41 41 42 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 43 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 4...
result:
ok 625 numbers
Test #27:
score: 0
Accepted
time: 117ms
memory: 11968kb
input:
513 42 45 49 24 4 47 28 38 37 12 37 46 11 45 4 30 24 45 38 6 44 26 29 39 28 32 3 9 30 34 37 19 19 36 16 4 38 22 15 34 35 50 37 29 27 35 16 10 29 40 49 7 20 32 25 38 9 32 37 43 2 21 28 0 30 7 14 1 39 27 50 4 4 34 19 37 26 50 11 34 8 12 4 19 45 10 1 7 9 41 8 27 15 42 5 41 45 26 36 32 24 26 34 30 43 47...
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 ...
result:
ok 687 numbers
Test #28:
score: -100
Time Limit Exceeded
input:
4368 717 418 977 829 894 787 929 904 812 463 581 626 606 476 308 620 253 749 826 558 110 125 323 161 546 702 197 147 608 460 391 66 998 696 635 531 634 992 697 795 633 38 408 505 465 251 397 958 43 836 282 407 834 837 828 815 888 395 153 722 85 280 38 650 558 387 162 752 818 28 734 412 33 261 386 71...
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 ...