QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#440718 | #7252. Airports | I_Love_Sonechka# | AC ✓ | 240ms | 10252kb | C++17 | 5.9kb | 2024-06-13 23:36:41 | 2024-06-13 23:36:41 |
Judging History
answer
//thatsramen
#include <bits/stdc++.h>
#define eb emplace_back
#define pb push_back
#define ft first
#define sd second
#define pi pair<int, int>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define dbg(...) dbg_out(__VA_ARGS__)
using ll = long long;
using ld = long double;
using namespace std;
//Constants
const ll INF = 5 * 1e18;
const int IINF = 2 * 1e9;
//const ll MOD = 1e9 + 7;
const ll MOD = 998244353;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ld PI = 3.14159265359;
//Templates
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) {return os << '(' << p.first << ", " << p.second << ')';}
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) {os << '['; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << ']';}
void dbg_out() {cerr << endl;}
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << H << ' '; dbg_out(T...); }
template<typename T> bool mins(T& x, T y) { if (x > y) { x = y; return true; } return false; }
template<typename T> bool maxs(T& x, T y) { if (x < y) { x = y; return true; } return false; }
//order_of_key(k): number of elements strictly less than k
//find_by_order(k): k-th element in the set
void setPrec() {cout << fixed << setprecision(15);}
void unsyncIO() {cin.tie(0)->sync_with_stdio(0);}
void setIn(string s) {freopen(s.c_str(), "r", stdin);}
void setOut(string s) {freopen(s.c_str(), "w", stdout);}
void setIO(string s = "") {
unsyncIO(); setPrec();
if(s.size()) setIn(s + ".in"), setOut(s + ".out");
}
// #define TEST_CASES
struct DSU {
vector<int> e;
vector<int> mn, mx;
DSU (int n) : e(n + 5, -1), mn(n + 5, IINF), mx(n + 5, -IINF) {}
int get(int x) { return e[x] <= -1 ? x : e[x] = get(e[x]); }
int sz(int x) { return -e[get(x)]; }
bool same(int x, int y) { return get(x) == get(y); }
bool unite(int x, int y) {
x = get(x), y = get(y);
if (x == y) return false;
if (-e[x] < -e[y]) swap(x, y);
e[x] += e[y]; e[y] = x;
mins(mn[x], mn[y]);
maxs(mx[x], mx[y]);
return true;
}
};
void solve() {
int n;
cin >> n;
vector<pi> ps(n), xs(n), ys(n);
for (int i = 0; i < n; i++) {
cin >> ps[i].ft >> ps[i].sd;
xs[i] = {ps[i].ft + ps[i].sd, i};
ys[i] = {ps[i].ft - ps[i].sd, i};
}
sort(all(xs)); sort(all(ys));
vector<int> l(n), r(n);
vector<DSU> dd(2, DSU(n + 5));
DSU dsu(n + 5);
vector<bool> vis(n + 5, false);
queue<int> que;
auto bfs = [&](int st, vector<pi> &ar, int par) {
que.push(st);
vis[st] = true;
while (!que.empty()) {
int v = que.front();
que.pop();
int i = l[v];
while (i >= 0) {
if (vis[i]) {
int nxt = dd[par].mn[dd[par].get(i)];
i = nxt - 1;
// dbg("nxt", min(dd[par].mn[dd[par].get(i)], i));
assert(i < 0 || !vis[i]);
} else {
vis[i] = true;
// dbg("new edge:", ar[v].sd, ar[i].sd);
dsu.unite(ar[v].sd, ar[i].sd);
if (i + 1 < n && vis[i + 1]) {
dd[par].unite(i, i + 1);
}
if (i - 1 >= 0 && vis[i - 1]) {
dd[par].unite(i, i - 1);
}
que.push(i);
i--;
}
}
i = r[v];
while (i < n) {
if (vis[i]) {
int nxt = dd[par].mx[dd[par].get(i)];
i = nxt + 1;
assert(i >= n || !vis[i]);
} else {
vis[i] = true;
// dbg("new edge:", ar[v].sd, ar[i].sd);
dsu.unite(ar[v].sd, ar[i].sd);
if (i + 1 < n && vis[i + 1]) {
dd[par].unite(i, i + 1);
}
if (i - 1 >= 0 && vis[i - 1]) {
dd[par].unite(i, i - 1);
}
que.push(i);
i++;
}
}
}
};
auto go = [&](ll d, vector<pi> &ar, int par) {
for (int i = 0, j = 0; i < n; i++) {
while (j < n && ar[i].ft - ar[j].ft >= d) {
j++;
}
l[i] = j - 1;
vis[i] = false;
}
for (int i = n - 1, j = n - 1; i >= 0; i--) {
while (j >= 0 && ar[j].ft - ar[i].ft >= d) {
j--;
}
r[i] = j + 1;
}
// dbg(ar);
for (int i = 0; i < n; i++) {
if (!vis[i]) {
bfs(i, ar, par);
}
}
};
auto ok = [&](ll d) -> bool {
for (int i = 0; i < n; i++) {
dd[0].e[i] = dd[1].e[i] = dsu.e[i] = -1;
}
iota(all(dd[0].mn), 0);
iota(all(dd[0].mx), 0);
iota(all(dd[1].mn), 0);
iota(all(dd[1].mx), 0);
// dbg("xs:");
go(d, xs, 0);
// dbg("ys:");
go(d, ys, 1);
return dsu.sz(0) == n;
};
ll lo = 1, hi = 2ll * 1000 * 1000 * 1000 + 5, res = 1;
// ll lo = 1, hi = 30, res = 1;
while (lo <= hi) {
ll mi = (lo + hi) / 2;
// dbg("here mi", mi);
if (ok(mi)) {
res = mi;
lo = mi + 1;
} else {
hi = mi - 1;
}
}
cout << res;
}
int main() {
setIO();
int tt = 1;
#ifdef TEST_CASES
cin >> tt;
#endif
while (tt--)
solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3828kb
input:
6 1 7 8 5 6 3 10 3 5 2 6 10
output:
9
result:
ok 1 number(s): "9"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3852kb
input:
6 9 8 8 8 6 5 3 7 2 6 9 10
output:
8
result:
ok 1 number(s): "8"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3796kb
input:
2 547865075 605997004 539239436 349306506
output:
265316137
result:
ok 1 number(s): "265316137"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3568kb
input:
3 213880975 632532642 285323416 211428413 590857173 560686330
output:
492546670
result:
ok 1 number(s): "492546670"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
4 498016553 595605750 392859783 24638536 296459007 395940406 91986808 848680263
output:
657212056
result:
ok 1 number(s): "657212056"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3572kb
input:
5 323798281 632723121 649236297 477797510 622267108 246753742 92114807 849551810 457347362 546838875
output:
667945490
result:
ok 1 number(s): "667945490"
Test #7:
score: 0
Accepted
time: 0ms
memory: 3572kb
input:
6 183313489 159760440 412103839 195282969 549206390 953546232 632512031 358532656 556492293 592048652 220046203 830257761
output:
805467016
result:
ok 1 number(s): "805467016"
Test #8:
score: 0
Accepted
time: 0ms
memory: 3664kb
input:
7 397017136 487639666 269089955 823076990 335456497 201424080 128460316 495332723 73308100 555111982 401618300 596357553 485264645 542006342
output:
461095276
result:
ok 1 number(s): "461095276"
Test #9:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
8 290225004 906869393 360663839 429014248 884515857 415891345 220720094 534003430 306677629 751365018 326022619 467400369 330561545 352226736 886683634 198858940
output:
709489885
result:
ok 1 number(s): "709489885"
Test #10:
score: 0
Accepted
time: 0ms
memory: 3660kb
input:
9 852207547 585789366 22150727 568204776 859724372 511177913 849202656 479276790 839410041 644464578 929482705 132508024 154916322 490323483 981372779 283079237 907256321 347316466
output:
847641410
result:
ok 1 number(s): "847641410"
Test #11:
score: 0
Accepted
time: 0ms
memory: 3864kb
input:
10 750989313 309415438 138577429 45795488 610037981 591819387 44962879 898836960 439537880 726383552 233697890 310659326 15088928 203192222 305191913 681609072 757170622 402127003 902968793 610858472
output:
817991034
result:
ok 1 number(s): "817991034"
Test #12:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
2 406158975 574643972 877380297 641954292
output:
538531642
result:
ok 1 number(s): "538531642"
Test #13:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
3 79795928 102307568 201443656 53825496 964913420 367284842
output:
1076929110
result:
ok 1 number(s): "1076929110"
Test #14:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
4 697889074 887290965 645381331 11633373 897597398 650144758 891818035 147708589
output:
890727452
result:
ok 1 number(s): "890727452"
Test #15:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
5 983727016 963538955 928178489 17889497 947811460 14423086 904832101 998341810 990897091 907788135
output:
952617240
result:
ok 1 number(s): "952617240"
Test #16:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
6 601108274 690231322 448785080 680224099 578634630 233632737 699701432 652931300 916702677 215105200 884267673 973291772
output:
654827345
result:
ok 1 number(s): "654827345"
Test #17:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
7 337087724 368755069 206531324 434573540 434230675 969475180 743067847 79880900 196248470 9212245 626007950 11995408 253980764 349858153
output:
697863062
result:
ok 1 number(s): "697863062"
Test #18:
score: 0
Accepted
time: 0ms
memory: 3572kb
input:
8 34020534 289437794 694680316 875772531 796444778 769817121 179238083 15032327 704663575 792131530 134194659 832586618 135998219 410907690 964444027 570065647
output:
1023546938
result:
ok 1 number(s): "1023546938"
Test #19:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
9 79332213 248326022 841274435 160501920 61568119 777397487 738899400 92765847 158359064 10648921 194448137 862400095 959532808 903464037 100099450 842288316 991536676 259021176
output:
1081549867
result:
ok 1 number(s): "1081549867"
Test #20:
score: 0
Accepted
time: 0ms
memory: 3868kb
input:
10 990731379 30981652 58361304 2085876 990734898 25331052 41418828 8074538 983323960 40717023 29477634 16545086 11262936 957163101 988280787 968577907 37848350 984362296 975557070 11823584
output:
1002789374
result:
ok 1 number(s): "1002789374"
Test #21:
score: 0
Accepted
time: 37ms
memory: 5152kb
input:
28254 20094578 419231303 472741164 517081572 407369494 517434068 113218189 473748976 45805389 114660060 427167383 465660456 105694350 470152521 53049472 509186700 435464917 76521304 19994572 95348209 438770088 9758702 24005587 50686103 521931388 132692803 460720506 65982956 2015838 156012236 6411404...
output:
707139018
result:
ok 1 number(s): "707139018"
Test #22:
score: 0
Accepted
time: 77ms
memory: 7196kb
input:
57316 101384737 1974288 95521403 100747051 100857630 94713368 93816918 101564186 2923940 3214606 95577563 1438253 1919355 5277707 2925235 98446624 1469154 3290946 97357150 2615319 1016343 99209360 97606563 100472416 4308884 98834778 2547882 3031506 3085193 1783528 96264603 99896483 101583264 9489175...
output:
110074573
result:
ok 1 number(s): "110074573"
Test #23:
score: 0
Accepted
time: 55ms
memory: 6308kb
input:
45014 349634375 330307397 364908178 270311387 323758197 57056969 4307919 105911520 18147069 29912148 345640459 286822445 370607087 331591509 366198639 267554863 91307094 16534646 18284079 334691862 78177103 18045790 46349435 5242887 333632225 32207856 98743201 370569334 279867221 353054014 99573013 ...
output:
503251251
result:
ok 1 number(s): "503251251"
Test #24:
score: 0
Accepted
time: 91ms
memory: 6480kb
input:
46870 221279629 646879690 619745140 193786471 724374355 276584962 166364513 123157614 578002984 528557321 262093353 834242858 620283197 684504067 807662359 367915109 343630104 499039857 512975690 40729056 47415209 137090894 811761738 115909442 817908230 157290296 103083131 710357125 796711937 258215...
output:
983415253
result:
ok 1 number(s): "983415253"
Test #25:
score: 0
Accepted
time: 59ms
memory: 6524kb
input:
47140 166300444 16776179 913489 173190765 11392393 21026071 1717412 136792135 158944859 10595561 173965768 142907308 157765670 151508306 13349088 6689386 16432098 10902178 156995215 151953426 17675252 7427107 172983293 141864952 147058080 7935771 12237303 12859545 19495441 12385834 27904260 17291057...
output:
214585411
result:
ok 1 number(s): "214585411"
Test #26:
score: 0
Accepted
time: 114ms
memory: 7600kb
input:
60601 313626540 603785462 707936321 618940338 343101660 878798025 750889040 89507092 475805944 861703335 317933342 509443770 750025775 425097451 745672918 889357140 638430854 777103869 421192299 265122961 922425183 635942031 433758900 400107511 952171441 735672887 235130463 5229945 80382107 20281080...
output:
1114819932
result:
ok 1 number(s): "1114819932"
Test #27:
score: 0
Accepted
time: 36ms
memory: 4888kb
input:
25266 234149264 49346058 318570562 1347263 201275394 97306433 66594237 160497452 363944828 164321370 452429750 76051368 61327151 131108622 29513407 116099593 397004135 337917988 100984304 72928491 27257113 272938188 348799488 471476385 441497408 340239158 310990192 460921029 18760533 279238989 35028...
output:
631755026
result:
ok 1 number(s): "631755026"
Test #28:
score: 0
Accepted
time: 4ms
memory: 4296kb
input:
6307 81600051 17219348 588683839 596808783 564957255 9018122 642541907 642016636 70315394 604691352 619300006 562212681 600388374 82025020 537927165 14402461 69105101 21132671 45585947 581372773 55143606 585422352 9390281 21727734 638478533 44590648 26629463 543608953 549475683 31647030 20410077 554...
output:
787010533
result:
ok 1 number(s): "787010533"
Test #29:
score: 0
Accepted
time: 132ms
memory: 8808kb
input:
79110 438823804 94736083 119405743 41974532 53352279 391725315 489546139 571706769 424737207 46780145 54966122 53504128 108818405 530223438 129795314 592287517 29407475 212298085 376205990 32569219 437318335 51115321 56446839 428753361 417826184 74372222 12635126 450789523 579229114 48040254 5163188...
output:
921100252
result:
ok 1 number(s): "921100252"
Test #30:
score: 0
Accepted
time: 108ms
memory: 7824kb
input:
64972 529420712 82423810 218638551 759096028 316518854 225719243 600648814 888735927 29537977 273988602 306026146 851912161 844487024 105886368 840028887 281737953 481145021 849621077 887255346 132560656 553649106 909660390 2379261 71892042 713350076 166962525 457379537 800928633 688725054 612150370...
output:
1256858981
result:
ok 1 number(s): "1256858981"
Test #31:
score: 0
Accepted
time: 146ms
memory: 10040kb
input:
100000 6089858 940271798 975532697 24349428 12645106 991628497 979865651 969182728 971239646 62456510 962214715 973324509 953283718 958352742 982032463 997587282 18499016 14624525 75782373 983553317 13406077 41962327 42744107 19808769 24329871 979211057 37038273 26142411 990854375 989424177 96670992...
output:
1099476597
result:
ok 1 number(s): "1099476597"
Test #32:
score: 0
Accepted
time: 145ms
memory: 10104kb
input:
100000 17259763 898012550 945583578 38836400 883811645 917303914 128373598 953772144 984284833 180720845 16849174 904667408 988897719 866744203 850506320 997524232 995652436 815894167 868256091 953272061 115498610 966354590 18823936 98161307 836922751 2521183 919249667 52760822 23446585 135339307 21...
output:
1198477010
result:
ok 1 number(s): "1198477010"
Test #33:
score: 0
Accepted
time: 146ms
memory: 10040kb
input:
100000 876545571 147231370 208553000 963541487 51866995 169036510 180009720 928077581 871336524 861901499 995760203 938167564 62899299 33779085 194045866 45145469 68096926 206125055 13922344 30798470 124817036 867210427 982905674 755462927 964748654 150178112 118201956 978514689 150831093 81572137 1...
output:
1296799942
result:
ok 1 number(s): "1296799942"
Test #34:
score: 0
Accepted
time: 168ms
memory: 10052kb
input:
100000 238623131 4881430 97019779 284457131 971310128 230049381 783935306 988371390 128898938 826829445 957057001 311117688 975566727 78865 183976083 818347060 338054866 963196636 629599767 989675481 55397401 876679417 791001776 90807765 332943005 57620417 912831710 270777613 996110471 722468353 272...
output:
1396852240
result:
ok 1 number(s): "1396852240"
Test #35:
score: 0
Accepted
time: 175ms
memory: 10248kb
input:
100000 55490051 721085911 75196942 207749209 127019600 140226993 562140385 33328779 820689907 790525962 106718336 208550312 4942263 858697874 878956410 37437528 960259730 365873725 987029180 389359581 102919882 827305814 74213988 272895262 883461540 864849485 598201387 908303945 435531090 9916187 87...
output:
1493309756
result:
ok 1 number(s): "1493309756"
Test #36:
score: 0
Accepted
time: 176ms
memory: 10028kb
input:
100000 314205127 262339362 953679982 501099485 59899012 559116661 848775342 671539240 367475633 101569988 424328735 10651349 143383359 634206702 616160213 85657237 962600989 280949446 67131588 836566245 728910766 249599134 946391158 586891707 116686890 445696893 900461122 534152112 893299852 5906032...
output:
1395523042
result:
ok 1 number(s): "1395523042"
Test #37:
score: 0
Accepted
time: 180ms
memory: 10136kb
input:
100000 643117429 26009243 628007917 959576816 726914199 737996252 122338680 761812710 36363045 200325011 347003934 766160473 475095071 793945248 973882977 310444781 838770547 310139981 823693079 371800029 736294029 747897949 865644042 868696621 321918680 673157161 812907119 445318268 50311204 403281...
output:
1295092739
result:
ok 1 number(s): "1295092739"
Test #38:
score: 0
Accepted
time: 189ms
memory: 10088kb
input:
100000 523916594 210006809 143993252 112990908 700754627 486960464 908635177 430578707 759823015 177824696 282695322 888245144 207708108 614993870 711843113 613422412 492706857 955271796 37655025 334136829 402993254 915006265 245850954 337577248 205927129 563521068 523730399 906949882 613373960 1914...
output:
1188927479
result:
ok 1 number(s): "1188927479"
Test #39:
score: 0
Accepted
time: 210ms
memory: 10028kb
input:
100000 769868625 246422285 445079456 710327163 286963219 551947429 644672726 772902771 219868496 492654141 307933577 936270443 199180812 702863170 674205770 285571177 846162351 627361562 558860353 390772580 129988124 769490455 518341612 218132944 855016212 796296199 209471036 857048469 616558694 481...
output:
1091503846
result:
ok 1 number(s): "1091503846"
Test #40:
score: 0
Accepted
time: 240ms
memory: 10252kb
input:
100000 731459752 865615575 874627164 273773489 635934549 176100509 276324343 961854363 458069139 958480186 762181723 781482682 432915216 517756898 292592409 69070319 540379798 195082025 925349208 508579778 388685170 867504684 594632392 756049168 151078269 690866016 825133118 964865053 418832629 6241...
output:
998799305
result:
ok 1 number(s): "998799305"
Test #41:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
2 0 0 1000000000 1000000000
output:
2000000000
result:
ok 1 number(s): "2000000000"