QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#743697 | #9424. Stop the Castle 2 | Nana7 | RE | 398ms | 63076kb | C++14 | 5.0kb | 2024-11-13 19:50:03 | 2024-11-13 19:50:03 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<queue>
#define I inline
#define inf (int)(1e9)
#define it set<int>::iterator
using namespace std;
const int N = 100010;
struct node {
int x,y;
}c[N],o[N];
int n,m,K,L[N],U[N],D[N],R[N],ans[N],del[N<<1];
set<int> stx[N<<1],sty[N<<1];
const int MAXM = 1200010;
const int MAXN = 200010;
int S=200009,T=200008;
int head[MAXN],cur[MAXN],dis[MAXN],vis[MAXN];
int ver[MAXM],mf[MAXM],Next[MAXM],id[MAXM];
int tot=1;
queue<int> jr;
I void add(int x,int y,int nf,int nid) {
ver[++tot]=y; mf[tot]=nf; Next[tot]=head[x]; head[x]=tot; id[tot]=nid;
ver[++tot]=x; mf[tot]=0; Next[tot]=head[y]; head[y]=tot; id[tot]=nid;
}
I bool spfa() {
while(!jr.empty()) jr.pop();
for(int i=1;i<=n*2;++i) dis[i]=inf,vis[i]=0;
vis[S]=1; dis[S]=0; vis[T]=0; dis[T]=inf; jr.push(S);
while(!jr.empty()) {
int k=jr.front(); jr.pop(); vis[k]=0;
for(int i=head[k];i;i=Next[i]) {
int to=ver[i];
if(!mf[i]) continue;
if(dis[k]+1<dis[to]) {
dis[to]=dis[k]+1;
if(!vis[to]) vis[to]=1,jr.push(to);
}
}
}
if(dis[T]==inf) return false;
return true;
}
I int dfs(int x,int limit) {
if(!limit) return 0;
if(x==T) return limit;
vis[x]=1;
int nowflow=0;
for(int i=cur[x];i;i=Next[i]) {
if(!(limit-nowflow)) continue;
int to=ver[i];
cur[x]=i;
if(vis[to]||(!mf[i])||dis[to]!=dis[x]+1) continue;
int f=dfs(to,min(limit-nowflow,mf[i]));
if(!f) continue;
mf[i]-=f; mf[i^1]+=f;
nowflow+=f;
}
vis[x]=0;
return nowflow;
}
#define mkp make_pair
#define pii pair<int,int>
map<pii,int> mp;
int cx[N],cy[N];
I void lsh() {
vector<int> vx,vy;
for(int i=1;i<=n;++i) vx.push_back(c[i].x),vy.push_back(c[i].y);
for(int i=1;i<=m;++i) vx.push_back(o[i].x),vy.push_back(o[i].y);
sort(vx.begin(),vx.end()); sort(vy.begin(),vy.end());
int lenx=unique(vx.begin(),vx.end())-vx.begin(),leny=unique(vy.begin(),vy.end())-vy.begin();
for(int i=1;i<=n;++i) c[i].x=lower_bound(vx.begin(),vx.begin()+lenx,c[i].x)-vx.begin()+1;
for(int i=1;i<=n;++i) c[i].y=lower_bound(vy.begin(),vy.begin()+leny,c[i].y)-vy.begin()+1;
for(int i=1;i<=m;++i) o[i].x=lower_bound(vx.begin(),vx.begin()+lenx,o[i].x)-vx.begin()+1;
for(int i=1;i<=m;++i) o[i].y=lower_bound(vy.begin(),vy.begin()+leny,o[i].y)-vy.begin()+1;
// for(int i=1;i<=n;++i) cout<<"c"<<c[i].x<<' '<<c[i].y<<endl;
// for(int i=1;i<=m;++i) cout<<"o"<<o[i].x<<' '<<o[i].y<<endl;
}
I void solve() {
cin>>n>>m>>K; K=m-K;
for(int i=1;i<=n;++i) cin>>c[i].x>>c[i].y;
for(int i=1;i<=m;++i) cin>>o[i].x>>o[i].y;
lsh();
for(int i=1;i<=n;++i) mp[mkp(c[i].x,c[i].y)]=i;
for(int i=1;i<=n;++i) stx[c[i].x].insert(c[i].y);
for(int i=1;i<=n;++i) sty[c[i].y].insert(c[i].x);
int atk=0;
for(int i=1;i<=n;++i) {
if(cx[c[i].x]==0) {
cx[c[i].x]=1;
} else atk++;
if(cy[c[i].y]==0) {
cy[c[i].y]=1;
} else atk++;
}
for(int i=1;i<=n;++i) cx[c[i].x]=cy[c[i].y]=0;
for(int i=1;i<=n;++i) add(S,i,1,-1),add(i+n,T,1,-1);
for(int i=1;i<=m;++i) {
it nL,nR,nU,nD;
nR=stx[o[i].x].lower_bound(o[i].y);
nL=stx[o[i].x].lower_bound(o[i].y);
nD=sty[o[i].y].lower_bound(o[i].x);
nU=sty[o[i].y].lower_bound(o[i].x);
int cnt=0;
if(nR!=stx[o[i].x].end()) {
R[i]=mp[mkp(o[i].x,*nR)];
cnt++;
}
if(nR!=stx[o[i].x].begin()) {
nL--;
L[i]=mp[mkp(o[i].x,*nL)];
cnt++;
}
if(nD!=sty[o[i].y].end()) {
D[i]=mp[mkp(*nD,o[i].y)];
cnt++;
}
if(nD!=sty[o[i].y].begin()) {
nU--;
U[i]=mp[mkp(*nU,o[i].y)];
cnt++;
}
if(cnt!=4) continue;
add(R[i],D[i]+n,inf,i);
}
//ck1();
int nc=0;
while(spfa()) {
// memcpy(cur,head,sizeof(cur));
for(int i=1;i<=n*2;++i) cur[i]=head[i];
cur[S]=head[S]; cur[T]=head[T];
nc+=dfs(S,inf);
}
int cnt=0;
for(int i=1;i<=n;++i) {
if(cnt==K) break;
for(int j=head[i];j;j=Next[j]) {
int c=mf[j],u=ver[j];
if(u<=n*2&&c!=inf&&mf[j^1]!=0) {
cnt++;
atk-=2;
ans[id[j]]=1;
del[u]=del[i]=1;
break;
}
}
}
for(int i=1;i<=m;++i) {
if(cnt==K) break;
if(ans[i]) continue;
if(L[i]&&R[i]&&!del[R[i]]) ans[i]=1,cnt++,atk--,del[R[i]]=1;
if(U[i]&&D[i]&&!del[D[i]+n]) ans[i]=1,cnt++,atk--,del[D[i]+n]=1;
}
for(int i=1;i<=m;++i) {
if(!ans[i]&&cnt<K) cnt++,ans[i]=1;
}
cout<<atk<<endl;
for(int i=1;i<=m;++i) {
if(!ans[i]) cout<<i<<' ';
} cout<<endl;
}
I void clear() {
for(int i=1;i<=tot;++i) mf[i]=ver[i]=id[i]=Next[i]=0;
tot=1; mp.clear();
for(int i=1;i<=n*2;++i) head[i]=cur[i]=0; head[S]=head[T]=cur[S]=cur[T]=0;
for(int i=1;i<=n;++i) stx[c[i].x].clear(),sty[c[i].y].clear();
for(int i=1;i<=m;++i) ans[i]=L[i]=U[i]=D[i]=R[i]=0;
for(int i=1;i<=n*2;++i) del[i]=0;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int TT; cin>>TT;
while(TT--) {
solve();
clear();
}
}
/*
1
8 6 4
1 3
2 1
2 6
4 1
4 7
6 1
6 3
6 6
2 3
3 1
4 3
4 6
5 2
6 4
1
3 2 1
10 12
10 10
10 11
1 4
1 5
*/
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 34252kb
input:
3 8 6 4 1 3 2 1 2 6 4 1 4 7 6 1 6 3 6 6 2 3 3 1 4 3 4 6 5 2 6 4 3 2 1 10 12 10 10 10 11 1 4 1 5 1 3 2 1 1 2 1 2 2 2 3
output:
4 2 3 5 6 2 2 0 2 3
result:
ok ok 3 cases (3 test cases)
Test #2:
score: 0
Accepted
time: 113ms
memory: 42212kb
input:
1224 11 17 14 7 3 4 2 8 13 3 15 3 4 5 11 10 2 3 3 8 6 7 11 2 3 10 4 1 3 12 1 2 5 11 9 11 6 11 10 8 15 1 5 9 14 4 11 1 6 10 7 7 6 11 4 8 4 1 11 18 3 2 14 8 2 14 13 13 9 12 14 12 5 6 8 1 10 5 8 6 8 9 6 6 7 5 12 11 6 11 13 5 1 10 7 6 14 5 6 15 2 4 11 1 1 6 4 14 14 13 9 9 3 10 12 7 5 8 13 9 14 1 9 8 4 9...
output:
7 3 4 5 6 7 8 9 10 11 12 13 15 16 17 15 2 3 0 3 4 5 6 0 2 3 4 5 6 7 8 9 11 1 3 8 1 2 3 0 1 2 3 4 5 6 7 8 9 10 11 12 1 5 6 7 9 10 11 12 8 17 18 19 1 1 2 3 4 5 6 7 8 7 6 8 10 13 14 15 1 10 11 12 13 14 15 16 17 18 19 20 0 1 1 2 3 0 5 6 7 7 8 12 13 14 15 2 10 11 12 13 14 4 3 4 5 6 7 8 ...
result:
ok ok 1224 cases (1224 test cases)
Test #3:
score: 0
Accepted
time: 343ms
memory: 59876kb
input:
1 86289 95092 40401 911 152 1 270 135 731 347 451 283 224 338 348 166 346 12 385 590 763 939 176 232 405 122 946 397 576 795 823 546 392 33 718 444 598 954 852 185 662 732 539 172 681 386 148 76 495 163 323 711 201 278 363 531 275 66 122 823 983 234 792 102 188 985 423 804 712 419 636 318 331 693 68...
output:
81531 5271 5272 5275 5276 5277 5280 5281 5283 5285 5289 5290 5295 5298 5300 5302 5303 5304 5305 5310 5311 5312 5315 5317 5321 5323 5330 5331 5332 5334 5335 5336 5341 5345 5346 5350 5355 5359 5360 5361 5365 5367 5370 5371 5372 5374 5375 5376 5378 5379 5380 5381 5382 5385 5386 5387 5389 5391 5392 5395...
result:
ok ok 1 cases (1 test case)
Test #4:
score: 0
Accepted
time: 258ms
memory: 63076kb
input:
1 99057 99722 73893 190482185 274379837 466851670 641324039 993028302 128875937 102891466 286559847 526771097 794238060 565736409 328262657 190329865 598878250 790626887 595298790 308031819 470646878 341575785 374318107 257299536 280924175 64420619 591124604 323023069 811512407 428956686 719615923 2...
output:
82045 1 2 6 9 10 11 13 15 16 18 19 20 21 22 24 25 28 29 30 33 34 35 36 37 38 39 43 45 49 50 51 52 54 55 59 60 61 62 67 69 70 71 79 81 82 83 87 90 91 93 94 95 96 99 100 101 102 104 105 107 109 110 111 112 113 114 119 120 128 129 131 133 135 136 137 138 142 143 147 148 149 151 152 153 154 155 156 159 ...
result:
ok ok 1 cases (1 test case)
Test #5:
score: 0
Accepted
time: 398ms
memory: 62708kb
input:
1 100000 99990 27662 913840909 999962982 690565691 31053 780601566 31053 54745498 31053 5383 859704869 538124857 999962982 5383 66851413 1444277 31053 119603839 999962982 999833258 543197820 999833258 349576387 999833258 759855830 999833258 124692224 266093388 999962982 5383 100041707 999833258 2843...
output:
100891 60364 60365 60366 60367 60368 60369 60370 60371 60372 60373 60374 60376 60377 60378 60379 60381 60383 60388 60389 60390 60392 60395 60396 60397 60401 60402 60403 60404 60405 60406 60407 60408 60409 60410 60412 60413 60414 60415 60416 60417 60419 60420 60421 60422 60423 60424 60426 60427 60428...
result:
ok ok 1 cases (1 test case)
Test #6:
score: 0
Accepted
time: 139ms
memory: 63076kb
input:
1 100000 49997 21428 9380 4333 9380 999999628 49202 4333 49202 999999628 50841 4333 50841 999999628 77418 4333 77418 999999628 95722 4333 95722 999999628 144002 4333 144002 999999628 234359 4333 234359 999999628 268942 4333 268942 999999628 288956 4333 288956 999999628 415094 4333 415094 999999628 4...
output:
100000 7099 7100 7102 7103 7104 7105 7106 7108 7110 7113 7114 7117 7119 7120 7122 7123 7126 7130 7131 7134 7135 7136 7140 7145 7149 7151 7154 7157 7158 7160 7162 7163 7167 7170 7172 7173 7174 7176 7178 7182 7183 7184 7188 7190 7197 7199 7201 7204 7205 7206 7208 7209 7211 7212 7213 7215 7216 7221 722...
result:
ok ok 1 cases (1 test case)
Test #7:
score: -100
Runtime Error
input:
1 100000 100000 76259 931427170 7 367311884 7 646435086 7 925372747 7 371054451 7 284185575 7 695090232 7 889183241 7 615617158 7 44230096 7 293281406 7 758261641 7 685549291 7 679471071 7 723138327 7 901136691 7 49281635 7 256352978 7 320188290 7 78730802 7 788131872 7 234735044 7 664906524 7 79430...