QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#474787#8594. Fieldnhuang685#30 185ms4716kbC++203.7kb2024-07-13 04:05:182024-07-13 04:05:18

Judging History

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

  • [2024-07-13 04:05:18]
  • 评测
  • 测评结果:30
  • 用时:185ms
  • 内存:4716kb
  • [2024-07-13 04:05:18]
  • 提交

answer

#include <bits/stdc++.h>

constexpr std::array<int, 4> dx{-1, 0, 1, 0}, dy{0, 1, 0, -1};
constexpr int64_t INF = 0x3f3f3f3f3f3f3f3f;

template <class T> struct CC {
  std::vector<T> val;
  void insert(T v) {
    val.push_back(v);
  }
  void init() {
    std::ranges::sort(val);
    val.erase(std::unique(val.begin(), val.end()), val.end());
  }
  int cc(T v) {
    return static_cast<int>(std::lower_bound(val.begin(), val.end(), v) -
                            val.begin());
  }
};

void solve1(int n, int q) {
  CC<int> cx, cy;
  std::vector<int> a(n), b(n), c(n), d(n);
  cx.insert(0);
  cy.insert(0);
  for (int i = 0; i < n; ++i) {
    std::cin >> a[i] >> b[i] >> c[i] >> d[i];
    cx.insert(a[i]);
    cx.insert(b[i]);
    cy.insert(c[i]);
    cy.insert(d[i]);
    cx.insert(a[i] - 1);
    cx.insert(b[i] + 1);
    cy.insert(c[i] - 1);
    cy.insert(d[i] + 1);
  }
  cx.init();
  cy.init();
  for (int &i : a) {
    i = cx.cc(i);
  }
  for (int &i : b) {
    i = cx.cc(i);
  }
  for (int &i : c) {
    i = cy.cc(i);
  }
  for (int &i : d) {
    i = cy.cc(i);
  }
  int sx = static_cast<int>(cx.val.size());
  int sy = static_cast<int>(cy.val.size());
  auto good = [&](int nx, int ny) -> bool {
    if (nx < 0 || nx >= sx || ny < 0 || ny >= sy) {
      return false;
    }
    for (int i = 0; i < n; ++i) {
      if (a[i] <= nx && nx <= b[i] && c[i] <= ny && ny <= d[i]) {
        return false;
      }
    }
    return true;
  };
  auto comp = [](int64_t lx, int64_t ly, int64_t rx, int64_t ry) {
    return std::abs(lx - rx) + std::abs(ly - ry);
  };
  std::vector dist(sx, std::vector<int64_t>(sy, INF));
  dist[cx.cc(0)][cy.cc(0)] = 0;
  using T = std::pair<int64_t, std::pair<int, int>>;
  std::priority_queue<T, std::vector<T>, std::greater<>> pq;
  pq.emplace(0, std::pair{cx.cc(0), cy.cc(0)});
  while (!pq.empty()) {
    auto [dd, loc] = pq.top();
    pq.pop();
    auto [lx, ly] = loc;
    if (dd != dist[lx][ly]) {
      continue;
    }
    for (int diff = 0; diff < 4; ++diff) {
      int nx = lx + dx[diff];
      int ny = ly + dy[diff];
      if (!good(nx, ny)) {
        continue;
      }
      int64_t nd = static_cast<int64_t>(std::abs(cx.val[lx] - cx.val[nx])) +
          std::abs(cy.val[ly] - cy.val[ny]);
      if (dist[nx][ny] > dist[lx][ly] + nd) {
        dist[nx][ny] = dist[lx][ly] + nd;
        pq.emplace(dist[nx][ny], std::pair{nx, ny});
      }
    }
  }
  while ((q--) != 0) {
    int x, y;
    std::cin >> x >> y;
    bool g = true;
    for (int i = 0; i < n; ++i) {
      if (cx.val[a[i]] <= x && x <= cx.val[b[i]] &&
          cy.val[c[i]] <= y && y <= cy.val[d[i]]) {
        g = false;
        break;
      }
    }
    if (!g) {
      std::cout << "-1\n";
      continue;
    }
    std::vector<int> px, py;
    int id = cx.cc(x);
    if (id == sx) {
      px.push_back(id - 1);
    } else if (id == 0 || cx.val[id] == x) {
      px.push_back(id);
    } else {
      px.push_back(id - 1);
      px.push_back(id);
    }
    id = cy.cc(y);
    if (id == sy) {
      py.push_back(id - 1);
    } else if (id == 0 || cy.val[id] == y) {
      py.push_back(id);
    } else {
      py.push_back(id - 1);
      py.push_back(id);
    }
    int64_t ans = INF;
    for (int i : px) {
      for (int j : py) {
        ans = std::min(ans, dist[i][j] + comp(cx.val[i], cy.val[j], x, y));
      }
    }
    if (ans == INF) {
      std::cout << "-1\n";
    } else {
      std::cout << ans << '\n';
    }
  }
}
void solve2(int n, int q) {

}

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

  int n, t, q;
  std::cin >> n >> t >> q;
  if (t == 1) {
    solve1(n, q);
  } else {
    solve2(n, q);
  }
}

详细

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 83ms
memory: 3768kb

input:

100 1 200000
387 400 -379 -369
383 396 -400 -387
325 394 365 391
386 390 -356 -347
-384 -373 -400 -337
381 396 -382 -363
-397 -346 -392 -348
370 370 -378 -350
-391 -382 -398 -394
392 400 397 398
362 372 297 389
377 389 -399 -297
-378 -303 -394 -388
-369 -328 -357 -353
385 391 -350 -325
397 398 -381 ...

output:

772
693
689
637
751
723
481
703
797
689
701
615
707
761
650
551
724
710
410
715
690
759
615
406
754
724
649
601
699
726
717
725
710
416
727
661
677
630
727
760
758
728
664
539
755
679
784
613
671
639
683
744
522
495
761
703
680
752
689
501
699
653
682
345
725
727
686
684
615
627
409
706
704
421
693
...

result:

ok 200000 numbers

Test #2:

score: 0
Accepted
time: 138ms
memory: 3972kb

input:

100 1 200000
2 7 50 113
119 157 -333 -316
156 156 148 158
-99 -43 -60 -51
-290 -272 -263 -262
-192 -192 203 204
-396 -390 -156 -148
-90 -89 -247 -242
-90 -47 -258 -246
-315 -308 360 371
385 390 259 260
222 290 -334 -326
12 19 69 85
-212 -210 -369 -314
-330 -322 -118 -95
-92 -83 48 76
-313 -309 51 58...

output:

385
292
217
783
593
482
146
774
262
228
521
532
509
491
709
517
442
190
486
338
588
510
451
163
379
463
460
192
499
458
368
378
375
381
153
317
282
290
415
179
541
717
399
313
318
572
183
308
560
545
709
714
237
602
229
180
166
413
620
255
473
218
486
244
546
539
237
288
282
519
264
608
301
250
486
...

result:

ok 200000 numbers

Test #3:

score: 0
Accepted
time: 129ms
memory: 3980kb

input:

100 1 200000
260 323 -196 -174
5 8 57 79
-302 -275 -31 -12
62 72 97 99
330 333 -374 -302
-80 -75 -99 -87
-51 -36 -369 -338
135 136 -10 15
-391 -356 -95 -86
-274 -263 -338 -334
-271 -253 -185 -165
11 17 371 394
-24 135 -375 -372
310 322 -255 -239
-283 -277 -205 -176
-354 -261 -375 -364
-364 -351 -247...

output:

224
597
249
331
56
190
182
399
550
291
390
164
201
411
492
390
519
153
711
461
206
555
555
387
224
362
455
160
633
521
95
516
462
466
380
236
381
239
421
491
439
580
239
750
311
696
543
558
328
389
449
139
276
476
298
380
202
577
402
228
295
507
687
467
342
379
157
341
501
229
394
507
380
357
253
40...

result:

ok 200000 numbers

Test #4:

score: 0
Accepted
time: 53ms
memory: 3684kb

input:

30 1 200000
0 37 33 33
0 0 33 37
0 45 -45 -45
0 0 -45 -45
0 88 49 49
0 0 49 88
0 110 -92 -92
0 0 -110 -92
0 139 129 129
0 0 129 139
0 174 162 162
0 0 162 174
0 205 -188 -188
0 0 -205 -188
0 236 -230 -230
0 0 -236 -230
0 239 -237 -237
0 0 -239 -237
0 259 -249 -249
0 0 -259 -249
0 286 262 262
0 0 262 ...

output:

524
345
141
565
642
330
425
662
370
337
419
230
765
347
240
235
299
317
373
252
432
574
581
348
378
395
262
424
230
393
497
592
442
347
603
491
225
194
483
364
386
736
343
378
677
676
652
479
594
579
566
298
164
672
554
427
158
293
405
447
455
560
240
462
564
276
270
455
359
446
544
228
400
428
456
...

result:

ok 200000 numbers

Test #5:

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

input:

30 1 200000
-9 17 5 5
-22 25 9 13
-26 31 17 26
-30 38 27 29
-44 53 33 45
-76 79 51 57
-86 91 -67 -66
-91 99 71 71
-95 105 78 79
-131 136 -89 -88
-141 147 -99 -96
-150 151 -113 -112
-162 170 115 127
-190 191 128 134
-219 222 -154 -147
-235 245 157 157
-235 244 -162 -157
-240 242 -205 -170
-262 271 21...

output:

296
549
423
276
550
641
344
51
94
382
478
472
346
325
370
298
333
289
173
579
1001
690
714
229
538
898
368
927
489
946
712
804
200
322
445
740
703
763
716
315
363
320
233
422
443
440
1016
713
463
888
795
673
369
679
413
512
161
539
1061
476
605
942
396
764
441
314
346
553
123
323
407
422
422
883
157...

result:

ok 200000 numbers

Test #6:

score: 0
Accepted
time: 86ms
memory: 3636kb

input:

100 1 200000
0 18 2 12
4 18 -2 12
-16 18 -2 -1
-16 -15 -2 17
-16 -1 18 18
24 33 -20 18
-25 33 -20 -6
-25 -20 -20 37
-25 -17 38 46
41 50 -29 46
-45 50 -29 -25
-45 -28 -29 50
-45 -26 51 61
56 56 -45 61
-54 56 -45 -42
-54 -48 -45 64
-54 -46 65 69
74 77 -50 69
-66 77 -50 -47
-66 -57 -50 93
-66 -55 94 12...

output:

716
1439
205
898
543
419
1043
374
568
445
720
928
1302
604
1502
529
495
344
488
19
957
127
1260
964
805
594
295
1143
781
814
913
1100
329
337
388
1286
629
561
922
61
497
522
501
645
757
1498
624
589
1340
713
446
1179
444
964
1541
806
965
1140
1397
563
1235
267
312
1314
1540
799
487
479
227
1646
354
...

result:

ok 200000 numbers

Test #7:

score: 0
Accepted
time: 39ms
memory: 3636kb

input:

9 1 200000
-1 1 -1 -1
-1 -1 -1 400
1 1 -1 400
-400 -1 400 400
1 400 400 400
-400 -400 -400 400
400 400 -400 400
-400 -1 -400 -400
1 400 -400 -400
-274 -11
-227 -378
-141 388
17 44
-365 87
-112 138
-357 -279
159 -223
299 -246
148 237
-50 -362
-101 -164
-232 -353
-133 110
39 -11
104 168
-75 296
323 -3...

output:

2669
2255
2935
2467
2858
2656
2484
2342
2459
2791
2094
2343
2285
2649
2434
2678
2777
2394
3066
2760
2576
2408
2231
2275
2938
2670
2881
2771
2527
2339
2672
2701
2173
2119
2357
2127
2957
2781
2598
2144
2139
2811
2307
2631
2735
2886
2409
2580
2633
2831
2693
3056
2781
2596
2862
2554
2378
2212
2549
2502
...

result:

ok 200000 numbers

Subtask #2:

score: 17
Accepted

Test #8:

score: 17
Accepted
time: 76ms
memory: 3752kb

input:

100 1 200000
-520000000 799999999 670000000 899999999
-870000000 -570000001 290000000 519999999
200000000 839999999 -770000000 769999999
480000000 949999999 -690000000 -1
-910000000 -390000001 380000000 939999999
370000000 879999999 850000000 889999999
-630000000 699999999 270000000 359999999
120000...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
14351189
-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
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 200000 numbers

Test #9:

score: 0
Accepted
time: 133ms
memory: 3752kb

input:

100 1 200000
-620000000 -450000001 -820000000 -690000001
620000000 809999999 750000000 769999999
560000000 579999999 180000000 229999999
300000000 329999999 -710000000 -540000001
210000000 239999999 110000000 159999999
560000000 719999999 -980000000 -920000001
490000000 499999999 -490000000 -4700000...

output:

1024986489
1503057919
1058204258
1276639352
1275950255
943526995
1374239771
1446461022
1315268981
1004036466
1403362690
184720367
511961447
887040857
1374400413
1439452243
221191600
1192059564
1790777615
921328973
849134264
1146531983
380394974
1456145444
528034469
1237884116
827414176
1064393575
12...

result:

ok 200000 numbers

Test #10:

score: 0
Accepted
time: 122ms
memory: 3696kb

input:

100 1 200000
800000000 859999999 820000000 849999999
860000000 869999999 330000000 359999999
-980000000 -950000001 50000000 89999999
870000000 879999999 190000000 209999999
760000000 769999999 150000000 179999999
10000000 29999999 -560000000 -550000001
780000000 799999999 -230000000 -210000001
77000...

output:

1919124771
1537676430
1685547831
1212780509
1604645162
878364646
657397658
1575619728
1071889205
517213258
-1
1850640221
1086456640
370638973
1055609386
351881344
611848435
438195740
432216907
760330908
1215187464
562872908
348229674
1274444955
203787924
1077821147
1357893006
1039518200
1032776829
1...

result:

ok 200000 numbers

Test #11:

score: 0
Accepted
time: 94ms
memory: 3684kb

input:

100 1 200000
0 59999999 10000000 19999999
30000000 59999999 -10000000 19999999
-40000000 59999999 -10000000 -1
-40000000 -10000001 -10000000 39999999
-40000000 -1 40000000 69999999
90000000 99999999 -50000000 69999999
-60000000 99999999 -50000000 -40000001
-60000000 -50000001 -50000000 79999999
-600...

output:

526009511
890974970
2655280535
3188334032
742417893
625144699
2480911576
1463758316
1544156762
1843680639
2038705746
2207722055
2618632578
765068192
3049944780
2650638899
2431065710
1248553578
511902039
925452749
2168932387
1158475096
1079982890
2711787013
1167056838
2429616756
671149463
1363056273
...

result:

ok 200000 numbers

Test #12:

score: 0
Accepted
time: 42ms
memory: 3644kb

input:

9 1 200000
-10000000 19999999 10000000 19999999
-10000000 -1 -1000000000 9999999
10000000 19999999 -1000000000 9999999
-1000000000 -1 -1000000000 -990000001
10000000 999999999 -1000000000 -990000001
-1000000000 -990000001 -1000000000 999999999
10000000 999999999 -1000000000 999999999
-1000000000 -1 ...

output:

6089160047
6596930369
5874475039
5768686959
6625657069
-1
7200425651
6489843249
-1
7191492311
-1
5631519465
7216520212
-1
-1
-1
-1
-1
-1
-1
6211464999
7411607068
6138944328
-1
-1
-1
-1
-1
7107230819
-1
-1
6041663701
6495526121
6301497868
-1
6707101013
7835585069
-1
338222348
7069525442
6394620771
68...

result:

ok 200000 numbers

Subtask #3:

score: 8
Accepted

Dependency #2:

100%
Accepted

Test #13:

score: 8
Accepted
time: 121ms
memory: 4640kb

input:

100 1 200000
882956534 955556110 914132723 916187709
825172571 963331990 984219579 993402442
-996087844 -865143113 -990583348 -939478442
991872385 997948948 -878327913 -840005787
-996873049 -970161260 853616978 864889994
-979742683 -918721411 -994708734 -969992605
-952533600 -886156263 -971579338 -8...

output:

1888063360
1729518854
1761016274
1953953053
1856288686
1807832041
1891714413
1861978931
1679821511
1837284438
1693709361
1815175263
1799150445
1988917293
1678078611
1921001214
1772260191
1991105984
1638879808
1809928559
1582340840
1876315955
1868266263
1768009788
1897991258
1536101818
1707361892
189...

result:

ok 200000 numbers

Test #14:

score: 0
Accepted
time: 184ms
memory: 4668kb

input:

100 1 200000
-29106381 -26748079 -941296353 -935681856
72072369 72652507 913511873 917196051
-998223865 -995895647 44787291 45831289
-24121588 -20668883 -911526340 -889221738
948486928 951403856 -12361100 -11816127
9017137 9788758 952501240 985324256
58374741 58650589 971861428 971937415
993292573 9...

output:

69918791
1777812770
1434825392
1005819121
981187132
970587786
1940684623
83026822
22698752
1920022943
1766221963
996397064
986068765
1952575886
1950009238
1925128916
993528132
899921261
21076521
1906646098
100814120
1773868355
1873886006
164771561
868487355
67107536
1001831400
971698760
1837684481
9...

result:

ok 200000 numbers

Test #15:

score: 0
Accepted
time: 185ms
memory: 4656kb

input:

100 1 200000
-174767312 -173110825 -382832708 -381510837
-421039711 -421033563 -910026736 -909889959
-904416023 -903730846 -29967326 -29416156
-989572882 -988816579 -942354836 -942145799
-585678728 -583783646 -420851319 -420272012
34180000 34236748 -371707892 -371364329
-410526065 -410470356 -570684...

output:

464491900
355545872
981334803
1081690612
1238398051
462978785
1803369198
1346003732
1655963004
1052193715
1131043150
883862501
538158423
1067001187
717995733
314323302
1383988025
751286200
1261845679
1828648192
1890919505
1063265064
1105475698
1724168730
814803018
1713639043
1259108555
1649464733
12...

result:

ok 200000 numbers

Test #16:

score: 0
Accepted
time: 93ms
memory: 3752kb

input:

100 1 200000
-43891418 0 -1549555 -1549555
0 0 -43891418 -1549555
-50679952 0 -47990452 -47990452
0 0 -50679952 -47990452
-58433825 0 -58109644 -58109644
0 0 -58433825 -58109644
-77940885 0 -62436513 -62436513
0 0 -77940885 -62436513
-93520905 0 -85618435 -85618435
0 0 -93520905 -85618435
-102099814...

output:

710027849
773730543
1156892806
1819011337
1578214549
1256710322
1190191009
1029045427
1107896809
936229779
802050830
1364812164
1167993530
598545874
561075791
832867784
1093202713
383551392
1582259711
1444648400
919085022
1850774220
1393866789
1558901313
458621645
761506045
512220938
1755390117
2383...

result:

ok 200000 numbers

Test #17:

score: 0
Accepted
time: 145ms
memory: 4716kb

input:

100 1 200000
-4065987 4065992 2230358 4177227
-12360883 12360886 -24892206 -11574784
-12492355 12492360 26030436 28155979
-16643987 16643996 28228337 36622411
-17814857 17814864 37413860 39213330
-42698471 42698472 52401199 56814996
-72649921 72649923 -58372505 -58224763
-74459610 74459612 -76087250...

output:

1166406764
860162394
324852664
1366604631
1797658073
831450758
1314101768
628400562
872172653
1125843582
941633873
1975882048
1611931653
2454766173
700722263
446397196
680772556
823136250
869684988
1537166555
1549793047
1016714062
1583320467
489014680
2235624645
2186176815
956253577
966765947
999526...

result:

ok 200000 numbers

Test #18:

score: 0
Accepted
time: 127ms
memory: 3904kb

input:

100 1 200000
-720074316 -715018811 144508507 209525013
25077918 73348717 970833425 972221754
563107167 573554783 578578957 578861752
902173429 914110053 941554247 943977126
-201408054 -198133856 65440192 96604192
-935050744 -924094863 972221755 973337309
-41820658 -39474550 963495803 970833424
76333...

output:

1169937941
446207371
449997608
658671853
765960761
363526036
1700504009
851498506
1384708921
1094911809
977669188
1204759615
1056468740
1033467649
1007949225
1078112790
901179801
1390606151
975428083
575802917
1427349544
1361706097
1393021583
846607278
1649969248
753529710
424442532
803274749
178639...

result:

ok 200000 numbers

Test #19:

score: 0
Accepted
time: 96ms
memory: 3696kb

input:

100 1 200000
0 996325036 996695965 996892814
995036557 996325036 -996222993 996892814
-996343946 996325036 -996222993 -1
-996343946 -995307256 -996222993 997103250
-996343946 -1 997103251 997247425
997233315 997319416 -997467300 997247425
-996869051 997319416 -997467300 -996426262
-996869051 -996464...

output:

1998274420
1999659943
1999436516
1999463542
1999995475
1999537834
3998420550
1998516821
1999508587
1999179390
1998618824
4000603957
1998112413
1997671605
1997371320
1998075497
3998896347
3991321993
1998387821
2000157974
1999633722
1998403105
2000873747
4002696528
1999644297
1999477152
3998860765
399...

result:

ok 200000 numbers

Test #20:

score: 0
Accepted
time: 49ms
memory: 3564kb

input:

9 1 200000
-1 1 -1 -1
-1 -1 -1 1000000000
1 1 -1 1000000000
-1000000000 -1 1000000000 1000000000
1 1000000000 1000000000 1000000000
-1000000000 -1000000000 -1000000000 1000000000
1000000000 1000000000 -1000000000 1000000000
-1000000000 -1 -1000000000 -1000000000
1 1000000000 -1000000000 -1000000000
...

output:

6957406500
5272588354
5789487537
6878444825
7485272863
7522876513
6192428236
6436620505
6982776595
6904567629
6690557536
6428257225
7023460827
6407258419
5560821128
7329970367
5992319943
5823382454
5958603813
5643059753
5116003652
6093544811
6107987456
7542544153
5811714701
7541964749
6133041755
704...

result:

ok 200000 numbers

Subtask #4:

score: 0
Wrong Answer

Test #21:

score: 0
Wrong Answer
time: 0ms
memory: 3564kb

input:

100 2 200
0 0 1 1
0 0 -1 -1
1 1 0 0
-1 -1 0 2
0 0 -1 -1
-1 -1 0 0
-1 -1 0 0
-1 -1 0 0
0 0 1 1
1 1 0 0
1 1 0 0
1 2 -1 0
1 1 0 0
-1 -1 0 0
-1 -1 0 0
1 1 0 0
0 1 1 1
-2 -1 0 0
-1 -1 0 0
-1 -1 0 0
0 0 -1 -1
0 0 -1 -1
0 0 1 1
-1 -1 0 0
-1 0 -1 -1
-1 -1 0 0
0 0 -1 -1
1 1 0 0
1 1 0 0
0 0 -1 -1
-1 0 1 1
-1 ...

output:


result:

wrong answer Answer contains longer sequence [length = 200], but output contains 0 elements

Subtask #5:

score: 0
Wrong Answer

Test #27:

score: 0
Wrong Answer
time: 0ms
memory: 3572kb

input:

100 2 400
930000000 979999999 950000000 979999999
800000000 829999999 830000000 939999999
980000000 999999999 970000000 989999999
-1000000000 -990000001 -1000000000 -960000001
950000000 979999999 -1000000000 -770000001
-970000000 -910000001 -950000000 -900000001
-970000000 -890000001 860000000 91999...

output:


result:

wrong answer Answer contains longer sequence [length = 400], but output contains 0 elements

Subtask #6:

score: 0
Skipped

Dependency #4:

0%

Subtask #7:

score: 0
Skipped

Dependency #6:

0%

Subtask #8:

score: 0
Skipped

Dependency #7:

0%

Subtask #9:

score: 0
Skipped

Dependency #8:

0%