QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#944188 | #10181. 안전 지대 | thomaswmy# | 3 ✓ | 622ms | 81064kb | C++14 | 3.0kb | 2025-03-20 11:12:32 | 2025-03-20 11:12:35 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int NN=5e5+10;
int n;
int b[NN<<1],btot;
int id[NN],tot;
struct DSU{
int fa[NN];
void init() {
for(int i=1;i<=n;i++) fa[i]=i;
}
int get(int x) {
if(fa[x]==x) return x;
return fa[x]=get(fa[x]);
}
void mg(int u,int v) {
u=get(u),v=get(v);
if(u==v) return ;
fa[u]=v;
}
}dsu;
void calc(vector<pair<pair<pair<int,int>,pair<int,int> >,int> > arr1,vector<pair<pair<pair<int,int>,pair<int,int> >,int> > arr2) {
vector<pair<pair<int,int>,int> > arr;
pair<pair<int,int>,int> lst={{-2e9,-2e9},0};
for(auto i:arr1) {
int l=i.first.first.first,r=i.first.first.second,id=i.second;
if(l<=lst.first.second) dsu.mg(lst.second,id),lst.first.second=max(lst.first.second,r);
else {
if(lst.second) arr.push_back(lst);
lst={{l,r},id};
}
}
if(lst.second) arr.push_back(lst);
vector<pair<pair<int,int>,int> > stk;
reverse(arr.begin(),arr.end());
reverse(arr2.begin(),arr2.end());
int now=0;
for(auto i:arr2) {
int l=i.first.first.first,r=i.first.first.second,id=i.second;
while(now<arr.size() && arr[now].first.second>=l) stk.push_back(arr[now++]);
if(!stk.size() || stk.back().first.first>r) continue;
pair<pair<int,int>,int> lst=stk.back();
lst.first.second=max(lst.first.second,r);
dsu.mg(id,lst.second);
stk.pop_back();
while(!stk.empty() && stk.back().first.first<=lst.first.second) {
dsu.mg(lst.second,stk.back().second);
lst.first.second=max(lst.first.second,stk.back().first.second);
stk.pop_back();
}
stk.push_back(lst);
}
}
void solve(int L,int R,vector<pair<pair<pair<int,int>,pair<int,int> >,int> > arr) {
if(arr.size()<=1) return ;
int mid=L+R>>1;
vector<pair<pair<pair<int,int>,pair<int,int> >,int> > arrl,arrr,now;
for(auto i:arr) {
int l=i.first.second.first,r=i.first.second.second;
if(L>=l && R<=r) now.push_back(i);
else {
if(mid>=l) arrl.push_back(i);
if(mid+1<=r) arrr.push_back(i);
}
}
calc(now,arr);
if(L==R) return ;
solve(L,mid,arrl);
solve(mid+1,R,arrr);
}
vector<int> find_union(int N,vector<int> A,vector<int> B,vector<int> C,vector<int> D) {
n=N;
for(int i:A) b[++btot]=i;
for(int i:C) b[++btot]=i;
sort(b+1,b+1+btot),btot=unique(b+1,b+1+btot)-b-1;
for(int i=0;i<n;i++) A[i]=lower_bound(b+1,b+1+btot,A[i])-b,C[i]=lower_bound(b+1,b+1+btot,C[i])-b;
dsu.init();
vector<pair<pair<pair<int,int>,pair<int,int> >,int> > arr;
for(int i=0;i<n;i++) {
arr.push_back({{{B[i],D[i]},{A[i],C[i]}},i+1});
}
sort(arr.begin(),arr.end());
solve(1,btot,arr);
vector<int> ans;
tot=0;
for(int i=1;i<=n;i++) if(!id[dsu.get(i)]) id[dsu.get(i)]=++tot;
for(int i=1;i<=n;i++) ans.push_back(id[dsu.get(i)]-1);
return ans;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 3
Accepted
Test #1:
score: 3
Accepted
time: 0ms
memory: 5972kb
input:
15 0 -62020 0 82718 1 -92844 1 59311 2 -44093 2 91841 3 -38281 3 42638 4 -19638 4 87825 5 -81191 5 58428 6 -5974 6 32491 7 -48100 7 52183 8 -1733 8 54140 9 -45703 9 9825 10 -16984 10 86340 11 -70319 11 18089 12 -90130 12 8538 13 -90265 13 41100 14 -46303 14 52159
output:
15 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
result:
ok 2 lines
Test #2:
score: 3
Accepted
time: 0ms
memory: 3840kb
input:
15 0 -84086 0 39890 0 -83763 2 45746 1 -28747 3 22732 2 -78660 3 1482 4 -18035 5 1905 5 -71900 5 44051 5 -76516 7 34646 6 -94224 8 29828 8 -14618 9 84080 8 -77427 9 76143 10 -99586 10 25519 11 -41242 12 24837 11 -41857 13 34523 13 -77827 13 84438 13 -60929 15 69871
output:
15 0 0 0 0 1 1 1 1 1 1 2 3 3 3 3
result:
ok 2 lines
Test #3:
score: 3
Accepted
time: 0ms
memory: 5976kb
input:
15 0 -17045 0 86168 -1 -99028 3 7835 0 -53815 4 40171 3 -29932 5 35980 4 -56844 6 5093 4 -97849 6 89263 5 -82298 8 1559 7 -16000 8 31819 6 -87091 9 3124 8 -68739 11 42460 10 -71294 12 16006 9 -28230 13 96344 11 -80133 13 36161 11 -65389 14 52122 14 -64661 14 63237
output:
15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
result:
ok 2 lines
Test #4:
score: 3
Accepted
time: 5ms
memory: 6656kb
input:
5000 0 -13042474 1 473280891 1 -960271121 1 137031294 2 -1267609 3 265241066 3 -526017037 3 831947342 4 -100561422 4 653747031 5 -380891036 5 379183708 6 -117885124 6 840783142 6 -386461363 8 867654325 7 -190287732 8 724025110 8 -757751626 10 677155323 10 -502973632 10 638290028 11 -753240036 12 768...
output:
5000 0 0 1 1 2 3 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 6 6 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 8 8 8 9 10 10 10 10 10 11 11 11 11 11 11 11 11 11 11 11 12 12 12 12 12 12 12 12 12 12 12 13 13 13 13 13 13 13 13 14 14 14 14 14 14 14 14 15 16 16 16 17 17 18 18 18 19 19 19 19 20 21 22 22 23 23 23 24 24 24 25 26 27 27 2...
result:
ok 2 lines
Test #5:
score: 3
Accepted
time: 5ms
memory: 4736kb
input:
5000 -1 -379657485 1 26551384 1 -887322283 3 139899938 1 -712701663 4 816392465 2 -734514569 5 250970078 4 -815751019 4 999871493 5 -72735914 7 490331417 6 -678916241 8 117046714 7 -350955889 9 237727579 6 -793265401 8 358861982 7 -745586817 10 22314889 10 -777922685 12 21649627 11 -55126884 13 1792...
output:
5000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5...
result:
ok 2 lines
Test #6:
score: 3
Accepted
time: 5ms
memory: 6832kb
input:
5000 -2 -451305204 2 874789169 1 -477936955 2 437735874 2 -424135716 5 998947645 3 -606575612 3 743621744 4 -235973322 4 51028661 5 -764580793 8 232882905 3 -18608992 9 688277578 7 -979013927 7 271364346 5 -396243069 11 362295075 7 -733422009 12 998878238 7 -52871737 13 405009227 9 -357013732 14 811...
output:
5000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
result:
ok 2 lines
Test #7:
score: 3
Accepted
time: 540ms
memory: 78532kb
input:
500000 -1 -123139265 0 99101346 0 -295651607 2 798130605 1 -583839059 3 216881454 2 -268283406 3 580693410 4 -532988152 4 708251547 5 -315218149 5 72593596 5 -762860767 6 509539375 7 -421165720 8 927443581 7 -425516201 9 335062871 9 -730508472 10 584534235 9 -942101642 10 781907442 11 -365993245 11 ...
output:
500000 0 0 0 0 1 2 2 3 3 3 3 4 5 6 7 8 8 8 9 9 9 9 9 9 9 9 10 11 11 11 11 11 11 11 11 12 12 13 13 13 13 13 13 14 14 14 14 14 14 14 14 15 15 15 15 15 15 16 16 17 17 18 19 20 20 20 21 21 22 22 22 22 23 24 24 25 25 25 26 26 26 26 26 27 27 27 27 28 29 29 29 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 3...
result:
ok 2 lines
Test #8:
score: 3
Accepted
time: 578ms
memory: 78920kb
input:
500000 -1 -194786984 1 947339132 -1 -591298988 1 800999249 0 -590240404 2 104469341 3 -140344449 5 368312366 3 -248177747 5 54376008 5 -7063027 7 520177794 6 -28924591 8 417206727 5 -459289174 7 592484128 7 -733526579 8 338495964 9 -718343664 11 929693803 9 -512017986 11 91638113 10 -962847385 13 57...
output:
500000 0 0 0 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7 7 7...
result:
ok 2 lines
Test #9:
score: 3
Accepted
time: 599ms
memory: 76900kb
input:
500000 -1 -266434703 2 426980696 1 -813317441 3 98835185 -1 -301674457 3 655620741 1 -348841981 6 787335104 2 -668400052 5 400500470 5 -403940614 5 926292794 3 -663584635 6 988437591 7 -423783700 10 962557383 5 -410133175 8 973332838 8 -337582635 10 979886078 8 -786967039 11 474997713 8 -969766942 1...
output:
500000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3...
result:
ok 2 lines
Test #10:
score: 3
Accepted
time: 610ms
memory: 81064kb
input:
500000 -4 -338082422 2 980251190 0 -740368603 5 396671121 0 -644512291 3 838175920 1 -220903024 6 206357840 1 -14993428 4 451657640 5 -22156564 9 37440501 5 -929648460 6 559668454 5 -756874446 9 627597930 7 -718143552 11 976765931 8 -620385119 11 956449426 9 -61916091 10 153324604 8 -198024861 12 61...
output:
500000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
result:
ok 2 lines
Test #11:
score: 3
Accepted
time: 622ms
memory: 79600kb
input:
500000 -4 -704697433 1 828488974 -3 -962387056 2 30943545 -2 -355946344 5 389327318 1 -429400557 4 699009506 1 -435215733 9 797782102 4 -714001443 5 779991991 4 -564308503 7 835932027 6 -721368972 9 292638477 3 -321121221 13 316635511 5 -608220310 11 301608993 7 -631832436 12 536684204 6 -794879001 ...
output:
500000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
result:
ok 2 lines
Subtask #2:
score: 0
Wrong Answer
Test #12:
score: 4
Accepted
time: 0ms
memory: 5976kb
input:
15 7 -461 8 676 -928 -468 -923 1 41 -537 48 951 -97 -918 -97 937 -629 -768 -619 173 -250 -46 -249 991 -139 -584 -138 322 69 -557 77 750 -828 -183 -828 228 -528 -145 -526 360 920 -452 926 475 390 -886 397 536 -885 -421 -880 620 211 -583 220 252 -311 -8 -307 558
output:
15 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
result:
ok 2 lines
Test #13:
score: 0
Wrong Answer
time: 0ms
memory: 5920kb
input:
15 372 -696 422 780 -693 -687 -661 240 -28 -94 16 586 -52 -470 -39 40 46 -522 127 280 782 -371 859 880 -142 -651 -70 356 145 -995 244 785 250 -99 344 351 -30 -404 22 367 -124 -850 -99 133 489 -741 553 352 -536 -659 -522 560 127 -360 205 60 58 -506 77 519
output:
15 0 1 2 3 4 5 6 4 7 2 6 8 9 4 4
result:
wrong answer 2nd lines differ - expected: '0 1 2 3 5 4 7 5 6 2 7 8 9 5 5', found: '0 1 2 3 4 5 6 4 7 2 6 8 9 4 4 '
Subtask #3:
score: 0
Wrong Answer
Test #29:
score: 0
Wrong Answer
time: 5ms
memory: 6784kb
input:
5000 327551 703202 327551 706216 -477590 -222763 -477393 -222763 -108969 489665 -103419 489665 -987300 620986 -978736 620986 -53772 -342878 -46404 -342878 320821 41196 320821 41516 720586 287526 723717 287526 221676 -766454 227184 -766454 477555 -283970 479467 -283970 674710 487256 682052 487256 973...
output:
5000 0 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 1...
result:
wrong answer 2nd lines differ - expected: '0 1 2 3 4 5 6 7 8 9 10 11 12 1...4 4955 4956 4957 4958 4959 4960', found: '0 1 2 3 4 5 6 7 8 9 10 11 12 1... 4955 4956 4957 4958 4959 4960 '
Subtask #4:
score: 0
Wrong Answer
Test #45:
score: 0
Wrong Answer
time: 146ms
memory: 19744kb
input:
100000 103428039 -722246120 105615051 -722246120 914973242 54361467 915866405 54361467 -442819027 -830287465 -441590532 -830287465 525993022 -949943053 526311265 -949943053 512218459 -432804473 515125546 -432804473 -653503066 496860319 -653503066 499792486 595698580 10165375 598628999 10165375 -2589...
output:
100000 0 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...
result:
wrong answer 2nd lines differ - expected: '0 1 2 3 88214 4 5 6 7 8 9 10 1...9 98560 98561 98562 98563 98564', found: '0 1 2 3 4 5 6 7 8 9 10 11 12 1... 98560 98561 98562 98563 98564 '
Subtask #5:
score: 0
Wrong Answer
Test #63:
score: 0
Wrong Answer
time: 168ms
memory: 18956kb
input:
100000 830040 -312425 830397 -311881 -76262 864793 -75378 865309 -735828 457459 -735621 458444 -450970 -613101 -450468 -612462 -232761 -549051 -232293 -548657 450789 210557 450914 211150 44963 -384017 45357 -383662 513241 217720 514225 218054 720669 17075 721664 17089 754152 -982768 755080 -982493 -...
output:
100000 0 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...
result:
wrong answer 2nd lines differ - expected: '0 1 2 3 4 5 6 7 8 9 10 11 12 1...2 98753 98754 98755 98756 98757', found: '0 1 2 3 4 5 6 7 8 9 10 11 12 1... 98753 98754 98755 98756 98757 '
Subtask #6:
score: 0
Wrong Answer
Test #79:
score: 0
Wrong Answer
time: 457ms
memory: 77316kb
input:
500000 6798 -77 6799 -76 4833 3421 4834 3421 812 4014 812 4014 -4917 -7758 -4917 -7758 -6850 26 -6850 26 3942 -8805 3943 -8804 -6932 6095 -6932 6095 3035 8626 3035 8627 7649 -6682 7649 -6681 7122 -8880 7122 -8880 -9307 664 -9306 665 -5355 -4147 -5355 -4146 -5599 -2529 -5599 -2528 9356 7619 9357 7619...
output:
500000 0 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...
result:
wrong answer 2nd lines differ - expected: '0 1 2 3 4 5 6 7 8 9 10 11 12 1...732 498733 498734 498735 498736', found: '0 1 2 3 4 5 6 7 8 9 10 11 12 1...32 498733 498734 498735 498736 '