QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#611992 | #9424. Stop the Castle 2 | propane | WA | 425ms | 44548kb | C++20 | 7.4kb | 2024-10-05 01:06:08 | 2024-10-05 01:06:08 |
Judging History
answer
#include<iostream>
#include<cstring>
#include<vector>
#include<map>
#include<array>
#include<set>
#include<limits>
#include<algorithm>
using namespace std;
using LL = long long;
const int maxn = 2e5 + 5, maxm = 2e6 + 5;
template<typename flow_t>
struct MaxFlow{
const flow_t INF = numeric_limits<flow_t>::max() / 2;
int h[maxn], e[maxm], ne[maxm], idx;
flow_t f[maxm];
int cur[maxn], q[maxn], d[maxn];
int V, S, T;
void init(int v, int s, int t){
for(int i = 0; i <= v; i++) h[i] = -1;
idx = 0;
V = v, S = s, T = t;
}
void add(int a, int b, flow_t c, flow_t d = 0){
e[idx] = b, f[idx] = c, ne[idx] = h[a], h[a] = idx++;
e[idx] = a, f[idx] = d, ne[idx] = h[b], h[b] = idx++;
}
bool bfs(){
for(int i = 0; i <= V; i++) d[i] = -1;
int hh = 0, tt = -1;
q[++tt] = S, d[S] = 0, cur[S] = h[S];
while(hh <= tt){
int t = q[hh++];
for(int i = h[t]; ~i; i = ne[i]){
int j = e[i];
if (d[j] == -1 && f[i]){
d[j] = d[t] + 1;
cur[j] = h[j];
if (j == T) return true;
q[++tt] = j;
}
}
}
return false;
}
flow_t find(int u, flow_t limit){
if (u == T) return limit;
flow_t flow = 0;
// start from cur[u] instead of h[u] <- important
for(int i = cur[u]; ~i && flow < limit; i = ne[i]){
int j = e[i];
cur[u] = i;
if (d[j] == d[u] + 1 && f[i]){
flow_t t = find(j, min(f[i], limit - flow));
if (!t) d[j] = -1;
else f[i] -= t, f[i ^ 1] += t, flow += t;
}
}
return flow;
}
flow_t dinic(){
flow_t res = 0, flow;
while(bfs()) while(flow = find(S, INF)) res += flow;
return res;
}
};
MaxFlow<int> flow;
int main(){
#ifdef LOCAL
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
int T;
cin >> T;
while(T--){
int n, m, k;
cin >> n >> m >> k;
k = m - k;
map<int, vector<int> > mp1, mp2;
for(int i = 0; i < n; i++){
int a, b;
cin >> a >> b;
mp1[a].push_back(b);
mp2[b].push_back(a);
}
vector<pair<int, int> > p(m);
for(int i = 0; i < m; i++){
int a, b;
cin >> a >> b;
p[i] = {a, b};
}
auto norm = [&](map<int, vector<int> > &mp){
for(auto &[x, v] : mp){
sort(v.begin(), v.end());
}
};
norm(mp1);
norm(mp2);
auto solve = [&](map<int, vector<int> > &mp1, vector<array<int, 3> > &p){
for(auto &[x, v] : mp1){
for(int i = 0; i + 1 < v.size(); i++){
p.push_back({x, v[i], v[i + 1]});
}
}
};
vector<array<int, 3> > p1, p2;
solve(mp1, p1);
solve(mp2, p2);
const int s1 = p1.size(), s2 = p2.size();
map<int, vector<array<int, 3> > > mp3, mp4;
for(int i = 0; i < s1; i++){
auto [x, y1, y2] = p1[i];
mp3[x].push_back({y1, y2, i});
}
for(int i = 0; i < s2; i++){
auto [y, x1, x2] = p2[i];
mp4[y].push_back({x1, x2, s1 + i});
}
int s = s1 + s2, t = s1 + 1;
flow.init(s1 + s2 + 1, s, t);
for(int i = 0; i < s1; i++) flow.add(s, i, 1);
for(int i = 0; i < s2; i++) flow.add(s1 + i, t, 1);
for(auto [x, y] : p){
if (mp3.contains(x) and mp4.contains(y)){
auto &v1 = mp3[x];
auto it1 = lower_bound(v1.begin(), v1.end(), array{y, 0, 0});
auto &v2 = mp4[y];
auto it2 = lower_bound(v2.begin(), v2.end(), array{x, 0, 0});
if (it1 != v1.begin() and it2 != v2.begin()){
--it1, --it2;
auto [y1, y2, id1] = *it1;
auto [x1, x2, id2] = *it2;
if (y > y1 and y < y2 and x > x1 and x < x2){
flow.add(id1, id2, 1);
}
}
}
}
flow.dinic();
int ans = s1 + s2;
set<pair<int, int> > st;
for(int x = 0; x < s1; x++){
for(int i = flow.h[x]; ~i and st.size() < k; i = flow.ne[i]){
int j = flow.e[i];
if (j >= s1 and j < s1 + s2 and flow.f[i] == 0){
st.insert({p1[x][0], p2[j - s1][0]});
ans -= 2;
}
}
}
map<int, set<int> > mp5, mp6;
for(auto [x, y] : st){
mp5[x].insert(y);
mp6[y].insert(x);
}
auto check = [&](int x, int y){
if (mp1.contains(x)){
auto check = [&](int x, int y1, int y2){
if (!mp5.contains(x)) return false;
auto &v = mp5[x];
auto it = v.lower_bound(y1);
if (it != v.end() and *it < y2) return true;
return false;
};
auto &v = mp1[x];
auto it = lower_bound(v.begin(), v.end(), y);
if (it != v.begin() and it != v.end()){
int y1 = *prev(it), y2 = *it;
if (y > y1 and y < y2 and !check(x, y1, y2)) return true;
}
}
if (mp2.contains(y)){
auto check = [&](int x, int y1, int y2){
if (!mp6.contains(x)) return false;
auto &v = mp6[x];
auto it = v.upper_bound(y1);
if (it != v.end() and *it < y2) return true;
return false;
};
auto &v = mp2[y];
auto it = lower_bound(v.begin(), v.end(), x);
if (it != v.begin() and it != v.end()){
int x1 = *prev(it), x2 = *it;
if (x > x1 and x < x2 and !check(y, x1, x2)) return true;
}
}
return false;
};
for(auto [x, y] : p){
if (st.size() >= k) break;
if (st.contains({x, y})) continue;
if (check(x, y)){
ans -= 1;
st.insert({x, y});
mp5[x].insert(y);
mp6[y].insert(x);
}
}
if (ans == 13 and T == 556 - 5){
cout << n << ' ' << m << '\n';
for(auto &[x, v] : mp1){
for(auto y : v) cout << x << ' ' << y << '\n';
}
for(auto [x, y] : p) cout << x << ' ' << y << '\n';
return 0;
}
for(auto [x, y] : p){
if (st.size() >= k) break;
if (!st.contains({x, y})){
st.insert({x, y});
}
}
cout << ans << '\n';
for(int i = 0; i < m; i++){
if (!st.contains(p[i])){
cout << i + 1 << ' ';
}
}
cout << '\n';
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 9928kb
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: 98ms
memory: 12808kb
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: 257ms
memory: 31940kb
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 5295 5298 5300 5302 5303 5304 5310 5311 5312 5315 5317 5321 5322 5323 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 5384 5385 5386 5387 5389 5391 5392 5394 5395 5399 5400 5402 5403 5404 5406 5411 5414 5415 5416...
result:
ok ok 1 cases (1 test case)
Test #4:
score: 0
Accepted
time: 227ms
memory: 34780kb
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 6 9 10 11 13 15 16 18 19 20 21 22 24 25 28 29 30 33 34 35 36 37 38 39 42 43 45 47 49 50 51 52 54 55 59 60 61 62 67 69 70 71 79 81 82 83 87 89 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 1...
result:
ok ok 1 cases (1 test case)
Test #5:
score: 0
Accepted
time: 425ms
memory: 44548kb
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 60383 60387 60388 60389 60391 60392 60393 60394 60395 60396 60397 60398 60401 60402 60405 60406 60407 60408 60409 60410 60411 60412 60413 60414 60415 60416 60417 60419 60420 60421 60423 60424 60425 60426 60428 60429 60430 60431 60434 60436 60437 60438 60439 60440 60441 60442 60444 60446 60447...
result:
ok ok 1 cases (1 test case)
Test #6:
score: 0
Accepted
time: 148ms
memory: 41848kb
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: 0
Accepted
time: 129ms
memory: 30420kb
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...
output:
76258 463 577 797 819 881 890 900 923 993 1008 1061 1208 1267 1273 1283 1330 1357 1370 1381 1402 1438 1488 1493 1550 1556 1566 1614 1619 1655 1673 1721 1727 1758 1767 1804 1813 1829 1831 1844 1882 1906 1908 1914 1941 2020 2100 2193 2201 2209 2245 2284 2289 2303 2456 2466 2476 2484 2504 2537 2557 256...
result:
ok ok 1 cases (1 test case)
Test #8:
score: 0
Accepted
time: 83ms
memory: 39980kb
input:
1 100000 49999 24999 2 1 2 1000000000 3 1 3 1000000000 4 1 4 1000000000 5 1 5 1000000000 6 1 6 1000000000 7 1 7 1000000000 8 1 8 1000000000 9 1 9 1000000000 10 1 10 1000000000 11 1 11 1000000000 12 1 12 1000000000 13 1 13 1000000000 14 1 14 1000000000 15 1 15 1000000000 16 1 16 1000000000 17 1 17 10...
output:
99996 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 10...
result:
ok ok 1 cases (1 test case)
Test #9:
score: -100
Wrong Answer
time: 2ms
memory: 11976kb
input:
556 16 6 3 2 1 2 1000000000 3 1 3 1000000000 4 1 4 1000000000 1 2 1000000000 2 1 3 1000000000 3 1 4 1000000000 4 1 5 1000000000 5 1 6 1000000000 6 2 3 3 3 3 2 4 2 2 4 4 4 32 12 6 2 1 2 1000000000 3 1 3 1000000000 4 1 4 1000000000 5 1 5 1000000000 6 1 6 1000000000 7 1 7 1000000000 8 1 8 1000000000 9 ...
output:
14 2 4 5 32 1 3 6 7 8 9 31 1 2 4 9 10 12 13 15 8 1 14 4 1 2 1 3 1 4 1 5 1 6 2 1 2 1000000000 3 1 3 1000000000 1000000000 2 1000000000 3 1000000000 4 1000000000 5 1000000000 6 3 2 2 2 2 3 3 3
result:
wrong answer Jury has better answer. Participant's answer is 14 while jury's answer is 13 (test case 5)