QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#129180#5029. 在路上pandapythoner30 3352ms86840kbC++205.4kb2023-07-22 05:08:242023-07-22 05:08:26

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-22 05:08:26]
  • 评测
  • 测评结果:30
  • 用时:3352ms
  • 内存:86840kb
  • [2023-07-22 05:08:24]
  • 提交

answer

#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define flt double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

mt19937 rnd(234);
const ll inf = 1e18;

#include "path.h"

int solve_a(vector<int> a, int lsz, int rsz, int lt, int rt) {
    int sz = a.size();
    if (sz == 1) {
        return a[0];
    }
    int v = a[rnd() % sz];
    int u = lt;
    bool swp = false;
    if (u == -1) {
        u = rt;
        swp = true;
    }
    vector<int> al, ar;
    if (u == -1) {
        u = a[rnd() % sz];
        while (u == v) {
            u = a[rnd() % sz];
        }
        swp = false;
    }
    for (auto x : a) {
        if (x == u || x == v) {
            if (x == u) {
                al.push_back(x);
            }
            continue;
        }
        if (ask(u, v, x) == v) {
            ar.push_back(x);
        } else {
            al.push_back(x);
        }
    }
    if (swp) {
        swap(al, ar);
    }
    if (lsz + (int)al.size() == rsz + (int)ar.size()) {
        return v;
    }
    if (lsz + (int)al.size() > rsz + (int)ar.size()) {
        return solve_a(al, lsz, rsz + (int)ar.size() + 1, lt, v);
    }
    return solve_a(ar, lsz + (int)al.size() + 1, rsz, v, rt);
}

int solve_a(int id, int n, int M) {
    vector<int> a(n);
    for (int i = 0; i < n; i += 1) {
        a[i] = i + 1;
    }
    shuffle(all(a), rnd);
    return solve_a(a, 0, 0, -1, -1);
}

int solve_slow(int id, int n, int M) {
    if (n == 1) {
        return 1;
    }
    pair<int, int> rs = {n, 1};
    vector<vector<int>> d(n + 1, vector<int>(n + 1));
    for (int v = 2; v <= n; v += 1) {
        int cnt = 1;
        for (int u = 2; u <= n; u += 1) {
            if (u == v) {
                continue;
            }
            int t;
            if (u < v) {
                t = d[u][v];
            } else {
                t = ask(1, v, u);
            }
            d[v][u] = d[u][v] = t;
            if (t == v) {
                cnt += 1;
            }
        }
        if (n - cnt <= n / 2) {
            rs = min(rs, make_pair(cnt, v));
        }
    }
    return rs.second;
}

vector<int> sort(vector<int> a, int tl) {
    if ((int)a.size() <= 1) {
        return a;
    }
    int sz = a.size();
    int u = a[rnd() % sz];
    int v = a[rnd() % sz];
    while (v == u) {
        v = a[rnd() % sz];
    }
    if (ask(tl, u, v) == v) {
        swap(u, v);
    }
    vector<int> al, am, ar;
    for (auto x : a) {
        if (x == u || x == v) {
            continue;
        }
        int t = ask(u, x, v);
        if (t == u) {
            al.push_back(x);
        } else if (t == x) {
            am.push_back(x);
        } else {
            ar.push_back(x);
        }
    }
    al = sort(al, tl);
    am = sort(am, u);
    ar = sort(ar, v);
    vector<int> rs;
    for (auto x : al) {
        rs.push_back(x);
    }
    rs.push_back(u);
    for (auto x : am) {
        rs.push_back(x);
    }
    rs.push_back(v);
    for (auto x : ar) {
        rs.push_back(x);
    }
    return rs;
}

int find_pos(vector<int> w, int v) {
    int tl = 0;
    int tr = (int)w.size();
    while (tl + 1 < tr) {
        int tm1 = (tl + tl + tr) / 3;
        int tm2 = (tl + tr + tr) / 3;
        int x = w[tm1];
        int y = w[tm2];
        int t = ask(x, y, v);
        if (t == x) {
            tr = tm1 + 1;
        } else if (t == 0) {
            tl = tm1 + 1;
            tr = tm2 - 1;
        } else {
            tl = tm2;
        }
    }
    return tl;
}

int n;

int solve(int rt, vector<int> a, int itr) {
    if (a.empty()) {
        return rt;
    }
    if (itr >= 50) {
        return rt;
    }
    int v = a[rnd() % (int)a.size()];
    vector<int> al, aw, ar, abd;
    for (auto x : a) {
        if (x == v) {
            continue;
        }
        int t = ask(rt, v, x);
        if (t == 0) {
            abd.push_back(x);
        } else if (t == v) {
            al.push_back(x);
        } else if (t == rt) {
            ar.push_back(x);
        } else {
            aw.push_back(x);
        }
    }
    if ((int)al.size() + 1 > n / 2) {
        return solve(rt, a, itr + 1);
    }
    if ((int)ar.size() + 1 > n / 2) {
        return solve(rt, a, itr + 1);
    }
    aw = sort(aw, v);
    int ln = aw.size();
    vector<vector<int>> b(ln);
    for (auto x : abd) {
        int pos = find_pos(aw, x);
        b[pos].push_back(x);
    }
    b.insert(b.begin(), al);
    aw.insert(aw.begin(), v);
    b.insert(b.end(), ar);
    aw.insert(aw.end(), rt);
    vector<int> f;
    ln += 2;
    for (int i = 0; i < ln; i += 1) {
        for (auto x : b[i]) {
            f.push_back(x);
        }
        f.push_back(aw[i]);
        if ((int)f.size() > n / 2) {
            break;
        }
    }
    int nrt = f.back();
    f.pop_back();
    int rs = solve(nrt, f, itr + 1);
    return rs;
}

int solve(int id, int N, int M) {
    n = N;
    int rt = 1;
    vector<int> a;
    for (int i = 1; i <= n; i += 1) {
        if (i != rt) {
            a.push_back(i);
        }
    }
    shuffle(all(a), rnd);
    int rs = solve(rt, a, 0);
    return rs;
}

int centroid(int id, int N, int M) {
    if (id == 3 || id == 5) {
        return solve_a(id, N, M);
    }
    return solve(id, N, M);
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 4ms
memory: 9708kb

input:

1 100 100
3
1 2
3
1 2
3
3 1
3
1 2
3
1 2
3
3 1
3
1 2
3
3 1
3
1 2
3
3 1
3
3 1
3
3 1
3
3 1
3
3 1
3
3 1
3
3 1
3
3 1
3
1 2
3
1 2
3
3 1
3
3 1
3
1 2
3
3 1
3
3 1
3
1 2
3
3 1
3
3 1
3
1 2
3
3 1
3
3 1
3
3 1
3
1 2
3
1 2
3
3 1
3
3 1
3
1 2
3
1 2
3
1 2
3
1 2
3
3 1
3
3 1
3
3 1
3
1 2
3
1 2
3
1 2
3
3 1
3
3 1
3
3 1
3
...

result:

wrong answer too many queries

Subtask #2:

score: 0
Wrong Answer

Test #2:

score: 8
Accepted
time: 83ms
memory: 14024kb

input:

2 10 10000000
999
60 112 98 509 586 175 588 875 861 516 920 370 781 249 999 649 292 308 934 949 437 92 506 752 547 866 869 510 984 228 104 612 202 630 360 809 56 107 566 448 940 726 146 299 941 50 319 794 670 603 365 492 728 872 829 942 451 632 373 106 909 25 306 995 735 99 568 673 75 573 383 407 56...

result:

ok correct

Test #3:

score: 0
Accepted
time: 84ms
memory: 14032kb

input:

2 10 10000000
999
60 112 98 509 586 175 588 875 861 516 920 370 781 249 999 649 292 308 934 949 437 92 506 752 547 866 869 510 984 228 104 612 202 630 360 809 56 107 566 448 940 726 146 299 941 50 319 794 670 603 365 492 728 872 829 942 451 632 373 106 909 25 306 995 735 99 568 673 75 573 383 407 56...

result:

ok correct

Test #4:

score: -8
Wrong Answer
time: 64ms
memory: 13500kb

input:

2 10 10000000
999
60 112 959 68 586 835 91 836 634 516 272 912 781 249 655 11 466 103 934 816 904 92 576 83 687 435 871 510 758 519 842 882 339 221 2 917 5 605 477 448 323 723 744 494 941 50 668 751 670 336 365 95 877 159 829 957 451 632 591 616 909 83 452 607 735 99 22 570 755 354 172 711 742 870 3...

result:

wrong answer 

Subtask #3:

score: 12
Accepted

Test #22:

score: 12
Accepted
time: 22ms
memory: 14124kb

input:

3 100 10000000
999
328 852 537 953 554 506 483 192 443 912 989 346 935 232 652 528 261 899 131 531 81 686 815 543 991 810 576 639 670 572 604 842 546 322 916 97 510 160 238 696 882 214 212 194 102 964 719 255 416 260 687 148 225 664 105 100 913 600 921 203 571 406 752 189 929 716 523 809 666 589 235...

result:

ok correct

Test #23:

score: 0
Accepted
time: 22ms
memory: 12140kb

input:

3 100 10000000
999
603 168 694 35 890 839 431 506 172 225 322 14 231 221 387 802 768 786 858 954 214 929 553 795 917 554 453 983 112 196 5 428 421 149 960 294 875 380 900 914 135 141 398 480 716 377 693 832 582 629 59 975 998 513 351 193 293 328 677 96 338 39 569 236 243 849 254 418 877 413 7 675 69...

result:

ok correct

Test #24:

score: 0
Accepted
time: 22ms
memory: 14256kb

input:

3 100 10000000
999
232 191 603 626 730 411 104 65 39 494 691 185 208 192 567 818 210 162 385 511 733 860 72 765 262 635 485 516 768 426 641 477 334 92 555 520 173 296 621 80 312 695 168 760 182 556 716 457 123 718 147 474 246 9 221 369 266 912 365 247 575 86 120 584 755 525 527 276 623 323 572 550 1...

result:

ok correct

Test #25:

score: 0
Accepted
time: 17ms
memory: 12156kb

input:

3 100 10000000
999
37 333 429 430 950 395 199 67 394 239 625 725 586 176 839 401 226 14 898 931 541 738 560 638 302 457 846 468 193 423 215 692 746 262 722 43 869 984 510 181 977 809 805 327 22 444 208 768 47 372 946 20 958 863 147 409 224 95 466 694 837 167 195 949 778 24 126 953 852 480 730 365 13...

result:

ok correct

Test #26:

score: 0
Accepted
time: 22ms
memory: 16188kb

input:

3 100 10000000
999
289 402 626 749 480 763 773 565 829 569 200 303 980 734 514 539 440 769 674 130 102 117 798 994 919 493 149 456 109 121 587 835 386 851 657 268 67 382 612 792 541 883 742 436 403 968 872 60 983 260 76 550 571 158 635 428 877 807 681 604 513 598 459 218 173 599 683 308 727 221 733 ...

result:

ok correct

Subtask #4:

score: 0
Wrong Answer

Test #27:

score: 17
Accepted
time: 786ms
memory: 14004kb

input:

4 100 10000000
999
710 227 715 954 623 585 538 236 363 913 540 3 897 998 726 919 976 843 796 69 415 705 647 707 201 696 993 545 325 375 47 260 490 385 828 162 29 278 867 593 395 219 178 518 999 685 307 772 224 187 557 89 575 524 1 157 230 341 708 978 473 995 15 179 743 416 263 640 4 851 520 719 679 ...

result:

ok correct

Test #28:

score: 0
Accepted
time: 797ms
memory: 13976kb

input:

4 100 10000000
999
714 793 831 566 274 202 861 272 583 533 805 725 138 636 832 242 737 219 191 168 939 364 439 770 290 84 581 419 991 431 892 387 487 753 368 627 900 476 934 316 854 802 898 48 741 182 950 684 121 881 996 120 917 311 386 63 377 300 734 333 789 257 797 134 668 490 649 843 795 198 462 ...

result:

ok correct

Test #29:

score: -17
Wrong Answer
time: 558ms
memory: 13184kb

input:

4 100 10000000
999
118 434 443 62 975 789 284 936 885 652 937 50 912 733 854 532 772 709 407 312 535 589 419 247 190 474 469 905 165 889 13 159 189 746 837 603 181 335 880 513 496 897 887 442 498 656 838 342 522 93 771 816 178 541 788 215 586 794 267 297 938 853 244 255 640 654 101 470 621 232 162 8...

result:

wrong answer too many queries

Subtask #5:

score: 18
Accepted

Test #47:

score: 18
Accepted
time: 1211ms
memory: 51108kb

input:

5 100 25000000
49999
3753 28650 36024 8322 47241 9061 43764 6338 45160 16765 40294 43358 37214 37535 38561 1997 7478 9543 11661 1953 7391 41171 43559 9981 24218 13155 22152 45216 30123 1843 20703 23601 42707 6449 40356 3761 32284 34584 32674 44391 41031 324 14845 6935 37071 38330 48041 1824 41182 46...

result:

ok correct

Test #48:

score: 0
Accepted
time: 1201ms
memory: 51920kb

input:

5 100 25000000
49999
4355 37348 38321 35425 21214 5083 45595 40224 33795 7313 23253 7272 29677 28728 35487 1991 44807 19910 7658 37652 35455 2514 34837 45354 38770 33373 22354 33923 553 32137 13158 39583 34278 32253 41652 2024 4250 27447 26990 40809 10542 48821 40099 43201 16468 13915 18394 17223 14...

result:

ok correct

Test #49:

score: 0
Accepted
time: 1246ms
memory: 51880kb

input:

5 100 25000000
49999
35421 12483 27611 26116 3078 41676 32102 20450 46565 7259 31701 39279 7716 18095 574 6832 14245 45403 7403 28959 10895 7192 24221 15536 28096 37220 49443 18168 43803 27863 7445 1555 2310 26797 44390 32627 34653 10091 41373 19105 11758 6420 21895 2662 5651 5357 8564 30178 47283 3...

result:

ok correct

Test #50:

score: 0
Accepted
time: 1213ms
memory: 52156kb

input:

5 100 25000000
49999
42046 19387 33162 23626 9528 41604 26357 27547 18587 20216 43658 5642 12752 36928 460 17925 6866 9380 29791 10256 12103 24116 39054 21861 14347 21118 23852 31261 10246 23316 46935 39281 41944 47820 43306 25162 42713 17257 29474 32926 12743 18125 14549 23818 22784 22008 37108 364...

result:

ok correct

Test #51:

score: 0
Accepted
time: 1213ms
memory: 52172kb

input:

5 100 25000000
49999
47176 35953 43451 38072 40586 17234 18319 28218 37190 15923 25135 40310 27316 17131 2164 26393 41753 47710 22396 27790 22627 49297 10917 11986 44920 27629 27944 14780 16282 11016 36590 34850 43230 85 27951 1338 3203 33927 49761 49552 16274 3167 49305 34706 25494 47457 14679 2608...

result:

ok correct

Subtask #6:

score: 0
Wrong Answer

Test #52:

score: 0
Wrong Answer
time: 2837ms
memory: 40236kb

input:

6 100 40000000
9999
3929 7460 4617 7377 498 7572 4628 3661 2404 9179 755 4076 8531 6581 1929 9419 1498 4402 6412 712 4918 2628 798 6283 9427 9775 1472 5554 2146 9972 5228 5459 8417 6778 3121 7649 1031 7691 6270 2238 4885 6121 2099 3435 4615 9962 6384 8809 9169 4553 66 1939 8589 2029 4897 7334 2867 8...

result:

wrong answer too many queries

Subtask #7:

score: 0
Wrong Answer

Test #72:

score: 0
Wrong Answer
time: 2682ms
memory: 73252kb

input:

7 50 40000000
29999
12447 18709 13054 17585 8337 14953 7985 1930 24383 1787 2543 26860 12198 2842 14256 8665 17034 6429 14773 8646 27093 6362 29357 18001 10667 8445 6671 21435 27163 14604 19875 745 20772 6696 16391 15560 16789 10983 6199 23133 13 13688 14547 8390 4398 21653 14460 690 24385 5358 2213...

result:

wrong answer too many queries

Subtask #8:

score: 0
Wrong Answer

Test #92:

score: 0
Wrong Answer
time: 3352ms
memory: 86840kb

input:

8 100 50000000
29999
8375 16777 16700 20953 11899 14682 20874 25860 28858 23241 5089 8044 25448 17746 5605 3087 9145 20179 1080 22944 27383 8384 19943 15371 27572 7882 23028 10474 18744 20202 15687 17001 7543 18709 23165 15713 17032 29011 22353 17455 26045 3484 20330 15159 21274 382 23927 20114 6303...

result:

wrong answer too many queries