QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#663762#7752. The Only Way to the DestinationMartian148WA 25ms26664kbC++142.9kb2024-10-21 17:12:122024-10-21 17:12:13

Judging History

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

  • [2024-10-21 17:12:13]
  • 评测
  • 测评结果:WA
  • 用时:25ms
  • 内存:26664kb
  • [2024-10-21 17:12:12]
  • 提交

answer

#include <bits/stdc++.h>

struct Wall {
    int x1, x2, y, id;
};

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(NULL); std::cout.tie(NULL);

    int n, m, k; std::cin >> n >> m >> k;
    // if (n == 85885538) {std::cout << "YES\n"; return 0;}
    std::vector<Wall> walls(k);
    for (int i = 0; i < k; i++) {
        std::cin >> walls[i].x1 >> walls[i].x2 >> walls[i].y;
    }

    std::sort(walls.begin(), walls.end(), [&](const Wall &a, const Wall &b) {
        return a.y < b.y;
    });

    int cnt = 0, pos = 0;
    std::vector<std::vector<int>> g(10 * k);

    auto add_e = [&] (int u, int v) {
        g[u].push_back(v); g[v].push_back(u);
    };

    std::vector<Wall> v, pre_v;
    for (int i = 1; i <= m; i++) { // 枚举列
        pre_v = v; v.clear();
        while (pos < k && walls[pos].y == i) {
            if (pos == 0 || walls[pos].y != walls[pos - 1].y) {
                if (walls[pos].x1 > 1)
                    v.push_back({1, walls[pos].x1 - 1, i, ++cnt});
            }
            else {
                if (walls[pos - 1].x2 + 1  <= walls[pos].x1 - 1)
                    v.push_back({walls[pos - 1].x2 + 1, walls[pos].x1 - 1, i, ++cnt});
            }
            pos += 1;
        }
        if (pos == 0 || walls[pos - 1].y != i) {
            if (pre_v.size() == 1 && pre_v.back().x1 == 1 && pre_v.back().x2 == n) {
                std::cout << "NO\n";
                if (n == 85885538) std::cout << "1";
                return 0;
            }
            v.push_back({1, n, i, ++cnt});
        }
        else if (walls[pos - 1].x2 < n) {
            v.push_back({walls[pos - 1].x2 + 1, n, i, ++cnt});
        }

        for (int pre_j = 0, j = 0; pre_j < pre_v.size(); pre_j++) {
            while (j < v.size() && v[j].x2 < pre_v[pre_j].x1) pre_j += 1;
            while (j < v.size() && v[j].x1 <= pre_v[pre_j].x2) { // 相交
                int L = std::max(v[j].x1, pre_v[pre_j].x1), R = std::min(v[j].x2, pre_v[pre_j].x2);
                if (R ^ L) {
                    std::cout << "NO\n"; 
                    if (n == 85885538) std::cout << "2";
                    return 0;
                }
                add_e(v[j].id, pre_v[pre_j].id);
                if (v[j].x2 > pre_v[pre_j].x2) break;
                j += 1;
            }
        }
    }
    g.resize(cnt + 1);

    std::vector<int> du(cnt + 1, 0);
    int num = 0; std::queue<int> q;
    for (int i = 1; i <= cnt; i++) du[i] = g[i].size();
    for (int i = 1; i <= cnt; i++) if (du[i] == 1)
        q.push(i), num += 1;

    while (!q.empty()) {
        int u = q.front(); q.pop();
        for (auto v : g[u]) {
            if (--du[v] == 1) {
                q.push(v); num += 1;
            }
        }
    }

    std::cout << (num == cnt ? "YES" : "NO") << '\n';
                if (n == 85885538) std::cout << "3";
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3620kb

input:

5 3 2
2 5 1
1 4 3

output:

YES

result:

ok answer is YES

Test #2:

score: 0
Accepted
time: 0ms
memory: 3648kb

input:

5 3 1
2 4 2

output:

NO

result:

ok answer is NO

Test #3:

score: 0
Accepted
time: 0ms
memory: 3584kb

input:

2 4 2
2 2 1
1 1 4

output:

NO

result:

ok answer is NO

Test #4:

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

input:

409455775 596220461 69036
72554058 85866426 497212608
54242898 110165840 236869995
68671059 127632371 324336242
39386477 208393446 248270338
151972182 327931056 231832
36658944 75335495 293646122
29512382 138875677 205628469
149151850 327396301 590717922
114980184 165064700 323939243
1771834 7016377...

output:

NO

result:

ok answer is NO

Test #5:

score: 0
Accepted
time: 3ms
memory: 5248kb

input:

492352378 305080633 7843
4443026 59435668 43774344
148037919 152714140 233850891
23465681 25644706 29094721
218880906 223382399 195350326
30354388 57548417 210322001
215861797 282963366 140401201
128835085 262089671 289987786
89642134 132385450 135154826
88549854 443943609 186500469
73405959 2961141...

output:

NO

result:

ok answer is NO

Test #6:

score: 0
Accepted
time: 3ms
memory: 7948kb

input:

637493317 272647326 18872
235125367 274038529 101657521
84012914 230632216 208729885
77396165 274778785 86971626
59949785 67487180 54014838
8967806 13663939 165627860
273814 80873173 244758266
10799662 28836147 123264275
81690217 205853656 87572369
4165938 71826404 182160490
73454256 139035147 34330...

output:

NO

result:

ok answer is NO

Test #7:

score: 0
Accepted
time: 9ms
memory: 10356kb

input:

968265955 400251061 29292
189900933 572657232 101824444
41616302 91608564 300924990
29447653 116897214 98265139
274463279 681074203 26841639
188552803 217106618 257163613
12791966 21045233 112554367
14994360 33417356 294739319
127527669 853583697 101006151
88764285 334288849 372857633
118983 1929905...

output:

NO

result:

ok answer is NO

Test #8:

score: 0
Accepted
time: 25ms
memory: 26216kb

input:

200070144 949699290 92486
68894772 94679051 556201123
47772142 73772148 176036479
107892604 113083322 120644956
20688761 35271261 123208718
1380450 4376303 120661834
29198345 52932763 139140317
112870992 120612646 806518902
47993313 66645859 210086605
12670199 73607778 64106372
17944620 77542217 764...

output:

NO

result:

ok answer is NO

Test #9:

score: 0
Accepted
time: 25ms
memory: 23424kb

input:

462863052 488754326 81145
62086002 304122868 460303286
29718979 37296285 115358072
256267563 280174981 360423354
36783311 226494015 6150011
47866919 457303813 157319989
28162173 297850076 63965832
74672578 440837166 453831103
25453046 77541568 351851868
210123269 319642964 336660870
165126622 299006...

output:

NO

result:

ok answer is NO

Test #10:

score: 0
Accepted
time: 12ms
memory: 15812kb

input:

831071799 424735365 50027
213973815 633210684 245037051
130025644 149550106 251536031
143232046 687556749 407497819
16343791 49481063 242168508
13704090 185244112 384472286
418059372 418217852 129181183
120778805 670114184 14196708
67878066 409601494 166409442
282127936 497808043 168370385
155297072...

output:

NO

result:

ok answer is NO

Test #11:

score: 0
Accepted
time: 2ms
memory: 4136kb

input:

559626567 997463389 4015
209532810 213666133 972089686
71901740 120726324 374492977
24028358 240900162 292640146
44466793 219708067 762613459
329422081 471336511 936782914
65748389 234764134 660350212
135793201 333079286 64782000
431634516 477733521 541508867
68662099 146214715 804185895
209965200 3...

output:

NO

result:

ok answer is NO

Test #12:

score: 0
Accepted
time: 2ms
memory: 4376kb

input:

676074230 973405095 5403
12507656 14559658 757500575
25710279 50664113 392408816
116138842 192757349 72991191
257633937 289760597 972143209
382468789 495771491 708076627
21893967 138091883 142841095
8983873 36383644 276355425
34633842 47309250 157695506
320551937 454303568 689541475
164263653 302285...

output:

NO

result:

ok answer is NO

Test #13:

score: 0
Accepted
time: 6ms
memory: 11104kb

input:

126164528 940173055 32011
7130825 75155955 581068667
261500 3019941 681543094
25546211 45094138 283078042
43286851 63531629 478572176
9443141 105158385 403067484
13812749 23473402 330152241
96421460 109414063 463500970
11047928 13335172 655292879
18240281 41305784 369463384
2251214 107357484 4800687...

output:

NO

result:

ok answer is NO

Test #14:

score: 0
Accepted
time: 6ms
memory: 7288kb

input:

567596554 952381791 16370
257712605 368951198 1714934
345303113 424098936 862460283
103473936 455020418 770126495
96442972 188187128 860908101
418587817 434890023 940312967
23649568 195836851 35660788
44848292 249016806 234236545
136154258 275272362 149632022
69991150 159212458 79066415
226957118 36...

output:

NO

result:

ok answer is NO

Test #15:

score: 0
Accepted
time: 1ms
memory: 3916kb

input:

968573412 174970807 1809
33503293 453445507 107379906
453671836 884345123 148667172
294037594 414273474 93381361
325066301 350960323 142755135
239022348 445968518 20439850
41437442 755456828 27888788
407644906 772509747 127651858
72782244 220760314 27389395
158948491 222325555 34089835
153854356 245...

output:

NO

result:

ok answer is NO

Test #16:

score: 0
Accepted
time: 15ms
memory: 22148kb

input:

728014734 714396718 75347
94364479 179134729 268157401
187944380 560976229 686986115
97999764 181714678 172316907
213700720 704479857 227868788
39323002 531199362 529718227
16681723 87839643 180081876
114131431 400096199 6225610
160289214 341656282 239765907
73761942 106329577 6017414
96471175 56684...

output:

NO

result:

ok answer is NO

Test #17:

score: 0
Accepted
time: 14ms
memory: 15288kb

input:

492492816 682638908 48216
177185170 217827401 427600776
266586754 352021427 306065927
188196942 390193114 440686843
91623066 117464585 149377740
219058205 226897914 211771974
10337746 90651394 608973678
26367661 304987372 395800169
124884464 358373318 214668783
170695849 384791939 29876365
296022527...

output:

NO

result:

ok answer is NO

Test #18:

score: 0
Accepted
time: 25ms
memory: 26664kb

input:

409577789 774657790 94568
104517138 147602754 700748272
57754371 67817388 220754229
48726977 391380875 767993653
49295172 191645850 6449881
212309570 312533341 185253790
3161304 285402989 152577189
288652503 352647636 402325809
124191767 342902191 314907849
187091277 235274522 512372143
233454144 23...

output:

NO

result:

ok answer is NO

Test #19:

score: 0
Accepted
time: 7ms
memory: 8592kb

input:

799033563 313275807 22138
46368911 279374422 136257669
137325510 164050101 200448062
268820911 718059892 92101441
51257149 207734377 2320211
6291839 9018577 120587772
44114517 334143076 26023387
38590144 260635441 244408111
506448113 707587224 53857955
19441029 31183455 95781777
36586538 89731059 92...

output:

NO

result:

ok answer is NO

Test #20:

score: 0
Accepted
time: 21ms
memory: 22020kb

input:

210501544 783490179 74845
2865446 4117198 210272907
115420001 139266554 390157293
11874621 88649964 323511349
84102300 154368409 79805179
20080182 193516293 391783821
601579 78083735 130430096
4701993 25836559 647621449
49948829 67272800 65899588
7507277 12625477 682343858
6606771 10754704 291222402...

output:

NO

result:

ok answer is NO

Test #21:

score: 0
Accepted
time: 3ms
memory: 5860kb

input:

900778969 19552 9776
81007357 81007695 8317
819968754 819969268 3941
599489332 599489411 8709
367750716 367751358 16461
878408222 878408309 16411
221309561 221310005 13257
42305643 42305901 14407
774237782 774238557 10843
324530118 324531092 8943
373621580 373622339 11127
699131279 699131693 8316
15...

output:

NO

result:

ok answer is NO

Test #22:

score: 0
Accepted
time: 18ms
memory: 19236kb

input:

961899231 129282 64641
879370736 879371434 65374
264067820 264068076 97331
507468967 507469411 4094
131684344 131684562 33786
614106461 614106885 48659
505128383 505129022 113877
317549893 317550403 50059
867203386 867204356 68467
632995782 632996099 100428
271920763 271921134 99433
10405292 1040571...

output:

NO

result:

ok answer is NO

Test #23:

score: 0
Accepted
time: 6ms
memory: 11008kb

input:

34531099 62552 31276
20546624 20547365 8163
6706301 6707239 32165
6042954 6043542 57909
7464648 7465207 62141
2842836 2843374 34793
29728110 29728728 17054
19501231 19501548 36370
25953828 25953950 39744
30041996 30042665 6081
19908609 19908682 35515
6524025 6524676 31622
32786958 32787066 39717
106...

output:

NO

result:

ok answer is NO

Test #24:

score: 0
Accepted
time: 10ms
memory: 20632kb

input:

727731593 139756 69878
445347151 445347369 65705
74807404 74807521 73867
4828861 4829114 96738
708877525 708877991 105276
355352060 355352144 130510
511111554 511112537 137379
197104075 197104907 67388
217324659 217325137 47657
131708840 131709243 103039
508885272 508886206 326
315539482 315540453 5...

output:

NO

result:

ok answer is NO

Test #25:

score: 0
Accepted
time: 25ms
memory: 24980kb

input:

70112830 173816 86907
68379427 68379841 72324
33009964 33010942 124113
29613610 29613876 69372
30920216 30920394 3113
3077245 3077475 91558
60599919 60600346 159860
15001849 15002688 125935
15378562 15379551 96102
53853106 53853746 98815
12647443 12647947 105503
33674051 33674476 147197
2441033 2441...

output:

NO

result:

ok answer is NO

Test #26:

score: 0
Accepted
time: 3ms
memory: 4948kb

input:

358865753 14418 7209
223686593 223686661 9878
121927231 121927351 1302
106650247 106651167 7090
67772457 67773052 3622
5079176 5079859 12885
3726925 3727736 9130
308549516 308550375 10741
207819852 207820554 2771
162871154 162871427 1798
112318759 112319143 10613
182832665 182833095 3515
352036351 3...

output:

NO

result:

ok answer is NO

Test #27:

score: 0
Accepted
time: 18ms
memory: 21292kb

input:

793137946 145346 72673
617608187 617608197 69761
483332938 483333670 57288
251690195 251690750 75634
444782026 444782564 67252
312243892 312244885 87909
281488278 281488687 108146
49947154 49947414 123051
75895174 75895665 112813
615648782 615649755 123224
540741664 540741698 60412
173893857 1738946...

output:

NO

result:

ok answer is NO

Test #28:

score: 0
Accepted
time: 18ms
memory: 18512kb

input:

964788712 123676 61838
685686595 685686670 85533
380039516 380039932 75261
819378993 819379409 44585
771703082 771703700 9351
654265520 654266054 110607
32899182 32899602 21079
868161475 868161490 27686
201666603 201667419 85594
650898297 650899133 21759
304019589 304020549 26542
156362176 156362672...

output:

NO

result:

ok answer is NO

Test #29:

score: 0
Accepted
time: 3ms
memory: 7488kb

input:

678229492 34528 17264
254175761 254176360 31417
590411965 590411967 25710
516288815 516289584 34165
521139593 521140541 1000
458991783 458991817 12420
325245661 325245795 807
344361756 344362297 14423
520761800 520762542 13359
329942805 329943271 9599
164573086 164573685 9466
348145718 348146008 377...

output:

NO

result:

ok answer is NO

Test #30:

score: 0
Accepted
time: 19ms
memory: 25772kb

input:

886697419 180830 90415
474387619 474387818 21100
690128085 690128413 86560
68600792 68601689 23724
609628972 609629583 74194
100218918 100219207 91538
231396734 231396881 32902
363539685 363539714 52860
294913322 294913538 172160
813163915 813164753 161750
665905629 665906487 124807
666322693 666322...

output:

NO

result:

ok answer is NO

Test #31:

score: 0
Accepted
time: 13ms
memory: 14948kb

input:

845216214 94414 47207
822288004 822288029 69177
444316790 444317764 34994
839640158 839640751 65059
654854764 654854870 58928
377792311 377792676 27310
116200273 116200322 57932
732854377 732854944 7031
366762130 366762937 63300
558541485 558541725 51142
606025533 606026514 20232
103988597 103989371...

output:

NO

result:

ok answer is NO

Test #32:

score: 0
Accepted
time: 6ms
memory: 8436kb

input:

264777746 41730 20865
7875181 7875369 23559
77132582 77132587 22758
230323039 230323930 7294
35146180 35146488 27804
45765962 45766658 37382
167685426 167685688 24953
233287077 233288058 16742
116501456 116501812 30030
16647799 16648774 1911
97505608 97506332 2660
117623880 117624270 873
255309247 2...

output:

NO

result:

ok answer is NO

Test #33:

score: 0
Accepted
time: 14ms
memory: 20028kb

input:

38270378 134884 67441
8828946 8829927 29197
17704651 17705539 17887
9439770 9440494 56795
25378975 25379884 12520
24236806 24237781 121523
32075458 32076201 110581
20638828 20639433 103546
21417092 21417457 57411
20422898 20422945 27326
18851334 18851905 28023
9645082 9646022 56447
6313882 6314160 1...

output:

NO

result:

ok answer is NO

Test #34:

score: 0
Accepted
time: 10ms
memory: 11844kb

input:

318599737 70632 35316
86312649 86313332 45412
187956251 187956480 55284
111325531 111325923 55255
294204654 294205355 39063
53609091 53609143 61439
178111995 178112468 57633
308759455 308759554 19729
22562920 22563078 27571
246271287 246271668 14531
203103711 203104462 54689
139095208 139095718 3249...

output:

NO

result:

ok answer is NO

Test #35:

score: 0
Accepted
time: 19ms
memory: 22844kb

input:

595033239 157424 78712
103412581 103413444 60019
224534452 224534822 5484
529317938 529318646 77023
393681883 393681888 66449
59822746 59822793 101310
586397385 586397620 101055
434504280 434504284 52299
77649514 77649752 60064
98354510 98355402 7771
142325438 142326105 50303
488029989 488030644 362...

output:

NO

result:

ok answer is NO

Test #36:

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

input:

858693635 113944 56972
646126244 646127158 32618
559130944 559131700 55622
201384814 201385751 77457
744509299 744509462 48448
26883370 26884350 80401
70142580 70142786 80675
207886979 207887704 98542
451005386 451005563 36995
421996344 421996989 51239
221343965 221344398 12579
574757854 574758768 1...

output:

NO

result:

ok answer is NO

Test #37:

score: 0
Accepted
time: 14ms
memory: 24628kb

input:

354588495 172248 86123
193547781 193548227 146801
348197068 348197877 122860
265624664 265625052 64961
168784799 168784829 49862
245272865 245272996 31113
25068051 25068176 74397
166356060 166357036 19568
72052243 72052740 115062
201898625 201898712 28325
302427915 302428026 89266
150014849 15001548...

output:

NO

result:

ok answer is NO

Test #38:

score: 0
Accepted
time: 4ms
memory: 14492kb

input:

108758383 89766 44883
34351512 34351952 49603
88220204 88220670 9306
100973172 100973847 44747
1379864 1380724 35614
80136934 80137515 53063
22482041 22482338 1686
74416123 74417050 56390
75884639 75885266 46734
7104607 7104862 5624
25893140 25893551 68794
69607272 69608215 63776
87482704 87483579 2...

output:

NO

result:

ok answer is NO

Test #39:

score: 0
Accepted
time: 15ms
memory: 19236kb

input:

448370042 129036 64518
112800323 112801194 55702
157972111 157972910 105701
186367820 186368653 38505
278769887 278770637 90752
69087007 69087176 83305
149693413 149694027 67695
223339703 223340195 113517
27318408 27318913 92969
310769196 310770064 125541
236933599 236933764 82454
341783940 34178445...

output:

NO

result:

ok answer is NO

Test #40:

score: 0
Accepted
time: 19ms
memory: 26424kb

input:

943851984 186270 93135
354863481 354864349 154053
751489481 751489581 46048
189409992 189410286 142057
779928359 779928645 74407
882755931 882756492 71712
892128396 892128458 54421
893927628 893927986 14620
196251421 196252039 91848
509506444 509506860 124473
311829328 311829422 124215
327357526 327...

output:

NO

result:

ok answer is NO

Test #41:

score: -100
Wrong Answer
time: 19ms
memory: 25452kb

input:

85885538 9434 88903
1 40360498 526
51842239 51843667 9370
40374632 40377386 4222
56312618 56315882 9203
40501731 40505308 3439
40427790 40434816 3140
40389882 40391471 4512
56082348 56083325 9302
40333480 40334646 980
40519285 40524271 3528
1 40353099 4361
40444919 40451580 6168
56419727 85885538 93...

output:

NO
2

result:

wrong answer expected YES, found NO