QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#511420 | #5451. 树据结构 | Antekb | 64 | 1409ms | 127224kb | C++14 | 3.6kb | 2024-08-09 20:56:08 | 2024-08-09 20:56:08 |
Judging History
answer
#include "bits/stdc++.h" /** keep-include */
using namespace std;
#define per(i, b, e) for(int i = (e); i >= (b); i--)
#define FOR(i, b, e) rep(i, b, (e) - 1)
#define SZ(x) int(x.size())
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define st first
#define nd second
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
auto &operator<<(auto &o, pair<auto, auto> p) {
return o << "(" << p.st << ", " << p.nd << ")"; }
auto operator<<(auto &o, auto x)->decltype(end(x), o) {
o << "{"; int i=0; for(auto e: x) o << ", " + 2*!i++ << e;
return o << "}"; }
#ifdef LOCAL
#define deb(x...) cerr << "[" #x "]: ", [](auto...$) { \
((cerr << $ << "; "),...) << endl; }(x)
#else
#define deb(...)
#endif
#include "ds.h"
mt19937 rng(1235432);
vector<pii> changed;
void change(int x, int y){
//deb("change: ", x, y);
exchange(x, y);
changed.pb(mp(x, y));
}
int ask(int v){
int t=query(v);
//deb("query:",v, t);
return t;
}
int tidy_path(int v, int start, int q_val){
for(int i=start; ;i++){
int t=q_val;
if(i!=start)t=ask(v);
if(t<=i || t<start)return t;
change(t, i);
}
}
//sortuje wierzcholki sciezki i ustawia ich krawedzi w dobrej kolejnosci
vector<int> sort_on_path(vector<int> V, int start, int end){//ostatni w V jest ostatnim na sciezce
if(V.size()==1){
return V;
}
int v=V[rng()%(V.size()-1)];
int mid=tidy_path(v, start, ask(v))+1;
vector<int> L, R;
for(int i:V){
if(i==v)continue;
else if(i==V.back())R.pb(i);
else{
int d=ask(i);
if(d<mid)L.pb(i);
else R.pb(i);
}
}
deb(v, L, R);
L.pb(v);
L=sort_on_path(L, start, mid);
R=sort_on_path(R, mid, end);
for(int i:R)L.pb(i);
return L;
}
vector<int> sort_on_path2(vector<int> V, int start, int end){//ostatni w V jest ostatnim na sciezce
if(V.size()==1){
return V;
}
shuffle(V.begin(), V.end()-1, rng);
set<int> S;
S.insert(start);
vector<int> ans(V.size());
ans.back()=V.back();
for(int v:V){
if(v==V.back())break;
int t=ask(v);
int u=*(--S.upper_bound(t));
deb(v, u, t);
int ord=tidy_path(v, u, t);
ans[ord-start]=v;
S.insert(ord+1);
}
deb(V);
deb(ans);
return ans;
}
void solve(int n, int lim1, int lim2) {
for(int i=2; i<n; i++){
int t=rng()%(i-1);
if(t)change(i, t);
}
int wsk=1;
vector<int> beg;
vector<int> rep;
vector<vector<int> > who;
for(int i=2; i<=n; i++){
int t=tidy_path(i, wsk, ask(i));
if(t<wsk){
int k=lower_bound(all(beg), t)-beg.begin();
who[k].pb(i);
}
else{
wsk=t+1;
beg.pb(t);
rep.pb(i);
who.pb({i});
}
}
deb(beg, rep, who);
vector<int> kol;
std::vector<int> par(n+1), val(n+1);
for(int i=0; i<beg.size(); i++){
reverse(all(who[i]));
who[i]=sort_on_path2(who[i], beg[i]+1-who[i].size(), beg[i]+1);
for(int j:who[i]){
kol.pb(j);
}
for(int j=1; j<who[i].size(); j++){
par[who[i][j]]=who[i][j-1];
}
}
deb(kol);
vector<int> whose_edge(n);
whose_edge[1]=1;
for(int i=0; i<kol.size(); i++){
int v=kol[i];
whose_edge[i+1]=v;
if(i){
swap(whose_edge[1], whose_edge[i+1]);
change(1, i+1);
}
if(!par[v]){
int t=ask(v);
par[v]=whose_edge[t];
if(t==1)par[v]=1;
}
}
deb(whose_edge);
deb(kol);
while(changed.size()){
swap(whose_edge[changed.back().st], whose_edge[changed.back().nd]);
changed.pop_back();
}
for(int i=1; i<n; i++){
val[whose_edge[i]]=i;
}
deb(par, val);
reverse(all(par));
par.pop_back();
par.pop_back();
reverse(all(par));
reverse(all(val));
val.pop_back();
val.pop_back();
reverse(all(val));
answer(par, val);
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 6
Accepted
Test #1:
score: 6
Accepted
time: 3ms
memory: 34608kb
input:
sfdjklasl2335n1j;llksaet35GTwejtklwrklakrjlt 50 1000001 1000001 2351tgsaldjkgakldfjtkjl;3136sajdflkjasdf135bbbwq 28 2 18 36 14 34 37 5 44 1 21 29 46 16 43 31 33 30 23 50 17 8 26 41 3 24 40 11 35 10 27 45 39 13 42 19 4 47 7 49 32 48 15 6 20 22 12 38 25 3 36 9 26 32 4 43 29 47 31 14 11 27 39 49 5 8 42...
output:
6640196347516987400
result:
ok single line: '6640196347516987400'
Test #2:
score: 6
Accepted
time: 2ms
memory: 32504kb
input:
sfdjklasl2335n1j;llksaet35GTwejtklwrklakrjlt 50 1000001 1000001 2351tgsaldjkgakldfjtkjl;3136sajdflkjasdf135bbbwq 44 41 43 3 28 37 32 36 16 6 23 4 2 13 5 45 26 30 22 50 7 33 15 17 20 42 39 38 47 14 31 1 27 21 11 8 49 19 24 18 35 10 9 29 12 25 46 34 48 1 3 36 27 15 19 39 16 5 12 33 28 32 9 7 37 29 11 ...
output:
9195104755648076998
result:
ok single line: '9195104755648076998'
Test #3:
score: 6
Accepted
time: 4ms
memory: 32476kb
input:
sfdjklasl2335n1j;llksaet35GTwejtklwrklakrjlt 50 1000001 1000001 2351tgsaldjkgakldfjtkjl;3136sajdflkjasdf135bbbwq 31 7 50 35 36 38 23 21 28 4 2 19 11 32 45 14 47 6 30 27 26 22 9 5 16 20 1 41 48 42 29 18 15 12 17 46 49 24 34 8 33 37 10 25 13 43 3 44 39 36 1 13 38 26 44 22 28 41 3 24 23 25 45 17 42 37 ...
output:
12239100023551140712
result:
ok single line: '12239100023551140712'
Test #4:
score: 6
Accepted
time: 0ms
memory: 34600kb
input:
sfdjklasl2335n1j;llksaet35GTwejtklwrklakrjlt 50 1000001 1000001 2351tgsaldjkgakldfjtkjl;3136sajdflkjasdf135bbbwq 42 44 36 4 19 25 16 41 38 37 17 39 27 3 5 33 13 34 24 8 15 50 45 43 21 11 47 28 26 30 23 6 48 20 14 9 18 40 46 7 49 10 2 22 29 1 31 32 12 37 6 10 44 43 42 8 4 38 15 9 48 12 26 35 31 27 46...
output:
14494350283792382446
result:
ok single line: '14494350283792382446'
Test #5:
score: 6
Accepted
time: 0ms
memory: 32476kb
input:
sfdjklasl2335n1j;llksaet35GTwejtklwrklakrjlt 50 1000001 1000001 2351tgsaldjkgakldfjtkjl;3136sajdflkjasdf135bbbwq 18 8 42 34 41 43 2 20 30 15 21 45 17 29 1 5 48 16 44 26 14 32 10 12 40 4 33 22 9 49 24 27 46 50 6 11 7 36 38 28 47 35 31 23 25 37 19 3 13 26 47 49 46 9 23 5 42 35 37 31 11 10 38 4 18 45 1...
output:
4462608412883436222
result:
ok single line: '4462608412883436222'
Subtask #2:
score: 9
Accepted
Dependency #1:
100%
Accepted
Test #6:
score: 9
Accepted
time: 3ms
memory: 34784kb
input:
sfdjklasl2335n1j;llksaet35GTwejtklwrklakrjlt 1000 1100002 2200002 2351tgsaldjkgakldfjtkjl;3136sajdflkjasdf135bbbwq 619 804 82 356 408 877 20 754 750 1000 584 529 754 501 589 653 359 643 653 855 601 287 448 53 145 479 693 151 754 274 261 46 347 362 431 721 289 893 754 203 976 206 754 58 551 967 754 6...
output:
7269721258820694274
result:
ok single line: '7269721258820694274'
Test #7:
score: 9
Accepted
time: 5ms
memory: 32924kb
input:
sfdjklasl2335n1j;llksaet35GTwejtklwrklakrjlt 1000 1100002 2200002 2351tgsaldjkgakldfjtkjl;3136sajdflkjasdf135bbbwq 982 335 345 883 975 622 335 556 510 868 335 477 85 420 786 335 941 335 897 571 25 49 79 583 133 850 330 938 232 79 953 599 732 335 335 335 969 783 567 335 640 335 378 386 681 14 765 561...
output:
13563802364143397128
result:
ok single line: '13563802364143397128'
Test #8:
score: 9
Accepted
time: 2ms
memory: 32736kb
input:
sfdjklasl2335n1j;llksaet35GTwejtklwrklakrjlt 1000 1100002 2200002 2351tgsaldjkgakldfjtkjl;3136sajdflkjasdf135bbbwq 940 897 832 953 700 333 978 796 177 810 526 296 419 143 776 526 368 564 388 589 478 586 494 809 615 981 837 804 161 286 290 6 53 213 385 208 336 545 432 890 424 830 960 691 37 163 155 3...
output:
4887279593788419428
result:
ok single line: '4887279593788419428'
Test #9:
score: 9
Accepted
time: 2ms
memory: 34724kb
input:
sfdjklasl2335n1j;llksaet35GTwejtklwrklakrjlt 1000 1100002 2200002 2351tgsaldjkgakldfjtkjl;3136sajdflkjasdf135bbbwq 708 482 101 884 260 319 123 361 55 688 449 350 424 154 362 92 53 723 844 4 156 334 156 136 786 718 327 875 834 365 410 221 105 311 403 340 425 437 430 156 156 117 740 662 838 518 299 75...
output:
5351759003231494
result:
ok single line: '5351759003231494'
Test #10:
score: 9
Accepted
time: 0ms
memory: 32752kb
input:
sfdjklasl2335n1j;llksaet35GTwejtklwrklakrjlt 1000 1100002 2200002 2351tgsaldjkgakldfjtkjl;3136sajdflkjasdf135bbbwq 695 260 505 653 473 386 59 363 453 861 505 91 669 479 505 970 354 504 108 759 550 880 517 505 683 7 127 513 173 332 751 951 708 495 444 534 527 879 980 240 764 798 476 350 371 581 195 8...
output:
12843885044920323912
result:
ok single line: '12843885044920323912'
Subtask #3:
score: 14
Accepted
Dependency #1:
100%
Accepted
Test #11:
score: 14
Accepted
time: 308ms
memory: 65976kb
input:
sfdjklasl2335n1j;llksaet35GTwejtklwrklakrjlt 100000 3000003 3000003 2351tgsaldjkgakldfjtkjl;3136sajdflkjasdf135bbbwq 33827 33123 16694 34094 71288 81667 48390 39245 82618 91807 17432 97045 21453 82461 61723 90007 16117 70765 93244 85769 54977 36918 22087 99387 88251 7593 13647 3087 74182 39589 89432...
output:
13911087176570347776
result:
ok single line: '13911087176570347776'
Test #12:
score: 14
Accepted
time: 294ms
memory: 63828kb
input:
sfdjklasl2335n1j;llksaet35GTwejtklwrklakrjlt 100000 3000003 3000003 2351tgsaldjkgakldfjtkjl;3136sajdflkjasdf135bbbwq 18132 96819 4888 19118 61063 8216 74382 43346 75767 26957 79573 94152 54129 45707 71102 69506 8461 20628 48443 68471 13821 27728 30935 99166 99169 81574 32977 47676 96808 57378 82388 ...
output:
15329642941023629260
result:
ok single line: '15329642941023629260'
Test #13:
score: 14
Accepted
time: 278ms
memory: 66860kb
input:
sfdjklasl2335n1j;llksaet35GTwejtklwrklakrjlt 100000 3000003 3000003 2351tgsaldjkgakldfjtkjl;3136sajdflkjasdf135bbbwq 65942 56974 33336 83232 82510 79931 80979 55182 64464 58370 99316 49841 56993 92754 56332 84857 3031 87809 37116 93092 14744 30446 42360 27308 26688 31340 86070 75832 46795 37242 1394...
output:
17969492568206842748
result:
ok single line: '17969492568206842748'
Test #14:
score: 14
Accepted
time: 299ms
memory: 63420kb
input:
sfdjklasl2335n1j;llksaet35GTwejtklwrklakrjlt 100000 3000003 3000003 2351tgsaldjkgakldfjtkjl;3136sajdflkjasdf135bbbwq 22927 31086 80416 69932 53151 4981 73728 37725 93260 80751 75939 16927 54560 15805 62642 91628 20774 28987 81328 10183 38231 45283 34431 9391 81489 15308 6744 29394 89142 9177 61468 4...
output:
8606904430482983974
result:
ok single line: '8606904430482983974'
Test #15:
score: 14
Accepted
time: 301ms
memory: 62640kb
input:
sfdjklasl2335n1j;llksaet35GTwejtklwrklakrjlt 100000 3000003 3000003 2351tgsaldjkgakldfjtkjl;3136sajdflkjasdf135bbbwq 32255 8751 93362 62560 24833 50648 86023 30267 62565 68871 94883 65360 59516 26919 33992 53547 55506 70571 78365 65635 65192 34778 69386 29059 61486 81560 61653 79052 39699 91166 5714...
output:
10853853962941559604
result:
ok single line: '10853853962941559604'
Subtask #4:
score: 14
Accepted
Test #16:
score: 14
Accepted
time: 11ms
memory: 36576kb
input:
sfdjklasl2335n1j;llksaet35GTwejtklwrklakrjlt 20000 3000004 3000004 2351tgsaldjkgakldfjtkjl;3136sajdflkjasdf135bbbwq 4879 6169 1969 17706 4213 18093 4963 18252 19119 2557 12571 19437 17865 6637 7288 13247 12644 15689 13894 5948 4474 12271 18580 6962 20000 8024 17921 15238 125 4044 14282 297 2126 1468...
output:
11411519532273973792
result:
ok single line: '11411519532273973792'
Test #17:
score: 14
Accepted
time: 15ms
memory: 34592kb
input:
sfdjklasl2335n1j;llksaet35GTwejtklwrklakrjlt 20000 3000004 3000004 2351tgsaldjkgakldfjtkjl;3136sajdflkjasdf135bbbwq 11442 8046 8871 15874 7054 18168 2689 2989 19245 16959 5240 18708 11741 4352 10473 19755 14138 1236 5155 9103 7349 18489 12014 19411 11271 19115 4042 7435 18742 16759 9725 10437 15876 ...
output:
13007494526468997570
result:
ok single line: '13007494526468997570'
Test #18:
score: 14
Accepted
time: 11ms
memory: 36536kb
input:
sfdjklasl2335n1j;llksaet35GTwejtklwrklakrjlt 20000 3000004 3000004 2351tgsaldjkgakldfjtkjl;3136sajdflkjasdf135bbbwq 10234 2672 12910 10671 3612 9257 844 12702 8905 18871 5306 12046 5980 9597 8276 12435 15386 8534 10624 1250 12097 2650 16093 10958 9051 9776 18690 6179 7074 1550 17282 17412 2247 17695...
output:
9022476061623111334
result:
ok single line: '9022476061623111334'
Test #19:
score: 14
Accepted
time: 14ms
memory: 36520kb
input:
sfdjklasl2335n1j;llksaet35GTwejtklwrklakrjlt 20000 3000004 3000004 2351tgsaldjkgakldfjtkjl;3136sajdflkjasdf135bbbwq 1738 14533 7685 2443 13595 15548 8901 1553 1204 10037 613 11106 8304 7620 6601 19595 12229 1821 18545 10128 12936 11278 16138 19999 17658 12903 3248 18766 18973 4411 9009 2026 14291 12...
output:
8203015790467333898
result:
ok single line: '8203015790467333898'
Test #20:
score: 14
Accepted
time: 10ms
memory: 34512kb
input:
sfdjklasl2335n1j;llksaet35GTwejtklwrklakrjlt 20000 3000004 3000004 2351tgsaldjkgakldfjtkjl;3136sajdflkjasdf135bbbwq 3902 1011 18956 8298 14368 4018 3435 18758 1744 16062 5214 2724 19869 11623 8465 16513 3421 8260 15842 11831 10344 13588 19878 14319 5944 11860 13532 13724 19300 18196 2041 7900 1225 1...
output:
6674755131752742784
result:
ok single line: '6674755131752742784'
Subtask #5:
score: 21
Accepted
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Dependency #4:
100%
Accepted
Test #21:
score: 21
Accepted
time: 233ms
memory: 56064kb
input:
sfdjklasl2335n1j;llksaet35GTwejtklwrklakrjlt 100000 3000005 3000005 2351tgsaldjkgakldfjtkjl;3136sajdflkjasdf135bbbwq 50489 30328 30328 14413 95751 83441 64066 63793 15360 19512 49707 91143 21075 67461 76942 89915 30328 31599 80089 70159 30328 57094 72973 58638 14648 47250 21663 30328 30328 57034 113...
output:
15907926973871234502
result:
ok single line: '15907926973871234502'
Test #22:
score: 21
Accepted
time: 250ms
memory: 63000kb
input:
sfdjklasl2335n1j;llksaet35GTwejtklwrklakrjlt 100000 3000005 3000005 2351tgsaldjkgakldfjtkjl;3136sajdflkjasdf135bbbwq 86516 86191 74181 56966 17785 4660 84255 56877 2774 42152 14788 42758 97886 81198 74181 74181 14011 83091 51340 92922 74181 9518 24952 96862 65149 45573 96182 38443 74181 94822 45775 ...
output:
4389117705824820768
result:
ok single line: '4389117705824820768'
Test #23:
score: 21
Accepted
time: 240ms
memory: 55196kb
input:
sfdjklasl2335n1j;llksaet35GTwejtklwrklakrjlt 100000 3000005 3000005 2351tgsaldjkgakldfjtkjl;3136sajdflkjasdf135bbbwq 80275 90990 57234 75266 73212 51536 21244 77454 82037 64456 35136 4939 26967 73877 80634 77454 66907 38745 44223 46942 35279 64981 85036 56548 62340 73386 50808 63867 81867 77454 9666...
output:
11561670284866444424
result:
ok single line: '11561670284866444424'
Test #24:
score: 21
Accepted
time: 261ms
memory: 64300kb
input:
sfdjklasl2335n1j;llksaet35GTwejtklwrklakrjlt 100000 3000005 3000005 2351tgsaldjkgakldfjtkjl;3136sajdflkjasdf135bbbwq 57475 13952 72172 28910 96251 33386 8619 34070 12839 32148 590 32838 44633 68189 24283 8619 53139 50616 58783 8619 30813 93283 66005 11787 8619 70976 23790 21742 93375 42871 52654 897...
output:
10569756925624445992
result:
ok single line: '10569756925624445992'
Test #25:
score: 21
Accepted
time: 257ms
memory: 62920kb
input:
sfdjklasl2335n1j;llksaet35GTwejtklwrklakrjlt 100000 3000005 3000005 2351tgsaldjkgakldfjtkjl;3136sajdflkjasdf135bbbwq 65378 64848 91175 70893 86312 19979 84748 55810 19979 47025 16637 97051 17890 91148 93197 19979 27969 21898 99821 31618 19979 93579 3771 45339 34260 33454 52388 31934 22956 86853 3012...
output:
7356413175316706600
result:
ok single line: '7356413175316706600'
Subtask #6:
score: 0
Wrong Answer
Dependency #1:
100%
Accepted
Dependency #3:
100%
Accepted
Test #26:
score: 0
Wrong Answer
time: 1409ms
memory: 127224kb
input:
sfdjklasl2335n1j;llksaet35GTwejtklwrklakrjlt 500000 3500006 3500006 2351tgsaldjkgakldfjtkjl;3136sajdflkjasdf135bbbwq 460684 50662 402759 348828 39765 243335 264918 486782 349512 6488 307879 428164 316732 93952 179037 37692 398136 359968 237375 197968 479670 246003 258655 130159 380414 339706 342955 ...
output:
result:
wrong answer 1st lines differ - expected: '11685763537789029324', found: ''
Subtask #7:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Dependency #4:
100%
Accepted
Dependency #5:
100%
Accepted
Dependency #6:
0%