QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#516673#4401. PrizeJWRuixi41 806ms230740kbC++202.9kb2024-08-12 20:19:102024-08-12 20:19:10

Judging History

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

  • [2024-08-12 20:19:10]
  • 评测
  • 测评结果:41
  • 用时:806ms
  • 内存:230740kb
  • [2024-08-12 20:19:10]
  • 提交

answer

#ifdef LOCAL
#include "stdafx.h"
#else
#include <bits/stdc++.h>
#define IL inline
#define LL long long
#define eb emplace_back
#define L(i, j, k) for (int i = (j); i <= (k); ++i)
#define R(i, j, k) for (int i = (j); i >= (k); --i)
#define FIO(FILE) freopen(FILE".in", "r", stdin), freopen(FILE".out", "w", stdout)
using namespace std;

using vi = vector<int>;
#endif

constexpr int N = 1e6 + 9;
constexpr int M = 1e5 + 9;
int n, K, Q, T;
int S[M], cnt;

struct tree {
  int rt, hd[N], tot, p[N];

  struct {
    int v, nx;
  } e[N];

  void add_edge (int u, int v) {
    e[++tot] = {v, hd[u]};
    hd[u] = tot;
  }

  int dfn[N], seq[N], dfc;

  void dfs (int u) {
    seq[dfn[u] = ++dfc] = u;
    for (int i = hd[u]; i; i = e[i].nx) {
      dfs(e[i].v);
    }
  }

  int st[20][N];

  int cp (int x, int y) {
    return dfn[x] < dfn[y] ? x : y;
  }
  
  void in () {
    L (i, 1, n) {
      scanf("%d", p + i);
      if (p[i] == -1) {
        rt = i;
      } else {
        add_edge(p[i], i);
      }
    }
    dfs(rt);
    L (i, 2, n) {
      st[0][i] = p[seq[i]];
    }
    L (i, 1, 19) {
      L (j, 1, n - (1 << i) + 1) {
        st[i][j] = cp(st[i - 1][j], st[i - 1][j + (1 << (i - 1))]);
      }
    }
  }

  int lca (int x, int y) {
    if (x == y) {
      return x;
    }
    if ((x = dfn[x]) > (y = dfn[y])) {
      swap(x, y);
    }
    int i = __lg(y - x++);
    return cp(st[i][x], st[i][y - (1 << i) + 1]);
  }

  int H[N], tt;

  struct {
    int v, nx, w;
  } E[M * 2];

  bool vis[N];
  int d[N];

  void add (int u, int v, int w) {
    E[++tt] = {v, H[u], w};
    H[u] = tt;
    E[++tt] = {u, H[v], -w};
    H[v] = tt;
  }

  void sol (int u) {
    vis[u] = true;
    for (int i = H[u], v; i; i = E[i].nx) {
      v = E[i].v;
      if (!vis[v]) {
        d[v] = d[u] + E[i].w;
        sol(v);
      }
    }
  }

  int dis (int x, int y) {
    int l = lca(x, y);
    return d[x] + d[y] - 2 * d[l];
  }
} t[2];

int qx[M], qy[M];

int main () {
  scanf("%d%d%d%d", &n, &K, &Q, &T);
  t[0].in();
  t[1].in();
  L (i, 1, K) {
    S[i] = t[0].seq[i];
  }
  sort(S + 1, S + K + 1, [] (int x, int y) {
    return t[1].dfn[x] < t[1].dfn[y];
  });
  L (i, 1, K) {
    printf("%d ", S[i]);
  }
  printf("\n");
  fflush(stdout);
  L (i, 2, K) {
    printf("? %d %d\n", S[i - 1], S[i]);
  }
  printf("!\n");
  fflush(stdout);
  L (i, 2, K) {
    int x = S[i - 1], y = S[i];
    int l1 = t[0].lca(x, y);
    int l2 = t[1].lca(x, y);
    int d1, d2, d3, d4;
    scanf("%d%d%d%d", &d1, &d2, &d3, &d4);
    t[0].add(l1, x, d1);
    t[0].add(l1, y, d2);
    t[1].add(l2, x, d3);
    t[1].add(l2, y, d4);
  }
  t[0].sol(S[1]);
  t[1].sol(S[1]);
  L (i, 1, T) {
    scanf("%d%d", qx + i, qy + i);
  }
  L (i, 1, T) {
    printf("%d %d\n", t[0].dis(qx[i], qy[i]), t[1].dis(qx[i], qy[i]));
  }
  fflush(stdout);
}
// I love WHQ!

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 352ms
memory: 161548kb

input:

500000 64682 64681 100000
46115
470589
209303
2979
473162
343535
79503
299539
404621
102085
237721
279170
392890
165201
441593
456314
218991
358478
86614
410800
159785
169761
95368
285837
297549
370283
378974
26449
444381
39320
149913
404523
144109
174828
263837
49847
468694
478535
152644
216598
301...

output:

422989 414496 290928 388223 160563 301045 470257 259625 222733 231286 345214 169817 435263 277447 386014 210139 455433 225855 264772 199736 355788 288506 233893 146148 454958 267562 498596 183745 352665 151125 266374 43142 9414 204593 212097 311775 25324 300764 6643 94847 396968 428563 311355 255767...

result:

wrong answer wrong answer on the first integer of query #1: read 0 but expected 23499297

Subtask #2:

score: 0
Wrong Answer

Test #13:

score: 0
Wrong Answer
time: 418ms
memory: 211332kb

input:

500000 88721 177440 100000
30974
23891
211201
125199
180489
387190
218020
498838
230147
307989
484136
257785
353027
304420
311738
169842
334090
486070
126212
328609
174959
368840
238722
418092
488389
226349
427271
457322
332454
12958
197530
264474
355717
482774
221286
282148
216441
266659
213750
628...

output:

299348 225578 286701 388703 273711 466172 478011 490391 462013 126494 92677 182472 13812 107732 303666 361862 256289 91025 389690 156797 268792 434419 208299 409874 319842 64913 385537 136511 498213 255392 208598 45196 97386 482069 290480 370649 225780 380585 84550 485237 301855 494683 414740 107270...

result:

wrong answer wrong answer on the first integer of query #1: read 352261 but expected 425610

Subtask #3:

score: 19
Accepted

Test #25:

score: 19
Accepted
time: 311ms
memory: 208100kb

input:

500000 200 199 40000
76296
130139
291501
292412
139543
433345
372726
451574
18315
465578
324564
477223
237354
81532
65170
465332
342130
9670
193303
193680
129668
149532
268907
89969
398275
356210
324593
433492
482232
466692
135343
433758
102545
287283
432859
351864
305769
489532
101532
450535
295762...

output:

12225 329473 124294 112780 478338 445039 249189 32330 65783 179054 497476 452979 319006 30813 48206 427935 466790 486377 109196 200837 164218 45188 487722 282259 229713 367076 188057 187010 232559 151913 348461 116954 20242 322713 185020 157495 443679 326708 325415 391214 266949 457474 3735 299220 2...

result:

ok good job!

Test #26:

score: 19
Accepted
time: 292ms
memory: 196268kb

input:

500000 200 199 40000
83785
150667
304961
267635
97760
385201
77226
6522
352645
72592
427133
30755
100574
359648
403948
394809
425453
115868
11287
351385
494434
245106
58157
395180
326236
277135
359592
13569
76251
45366
172378
122783
216597
466130
284420
342613
471698
380682
92490
79264
241049
54038
...

output:

455890 309275 63656 335800 292806 9763 489623 63346 86191 446791 183068 362736 197911 107095 211424 101597 145440 202553 8696 425553 151090 60540 369501 412878 462364 222 148686 133609 158102 107714 270626 112101 244973 133381 421561 462192 28928 193698 101629 183699 205161 304190 364442 409432 4207...

result:

ok good job!

Test #27:

score: 19
Accepted
time: 234ms
memory: 194476kb

input:

500000 200 199 40000
94863
498513
460682
411416
360517
309831
253717
325019
496632
255803
130770
289206
181204
74729
481723
293737
94126
307214
342974
448321
17084
433126
387809
279606
251781
65795
125269
129465
433572
219622
11806
179248
367117
84640
114067
122590
4140
116015
77759
392439
408930
10...

output:

202545 440862 361010 401185 475867 496061 39372 222066 236817 48111 60999 471755 360514 236313 204451 106250 381948 236421 376463 311524 441571 461140 98374 326916 103118 4158 483991 237952 222429 81602 347639 227796 78705 480293 427895 94835 128503 382030 222511 447219 456777 442490 405317 331113 3...

result:

ok good job!

Test #28:

score: 19
Accepted
time: 257ms
memory: 200184kb

input:

500000 200 199 40000
460896
356428
214577
150748
16877
1635
258267
370689
262538
369939
466845
415822
304104
329494
6035
489031
48344
181107
61121
4048
156120
273134
234110
418870
101454
330401
45460
74853
175589
44170
192108
214802
482345
120910
76381
307448
204387
170471
187255
20694
494550
351800...

output:

74629 216409 452886 65274 396083 306614 271286 250271 377987 76133 184065 443000 108728 51517 28628 412868 179055 464576 343588 397215 111447 8749 370727 92101 86364 448557 216093 1279 387295 348867 302046 390957 375386 266148 88874 379220 396301 409011 144844 495576 243516 59739 293503 135896 13486...

result:

ok good job!

Test #29:

score: 19
Accepted
time: 212ms
memory: 200712kb

input:

500000 200 199 40000
472275
149661
377034
488618
186507
171592
345983
124571
76807
5855
300138
80553
340257
185587
378146
311401
334561
194922
182638
104826
420776
448537
393232
195734
347470
219413
82586
185915
58528
404731
329285
300479
342445
115864
230618
360114
281628
86760
203158
212935
376440...

output:

226412 269284 83547 393586 330369 494997 26991 474239 153656 355957 268755 98973 109076 282461 352777 408065 333791 251643 363031 478601 282820 375604 255417 243410 136724 450004 313552 453256 234253 185784 396339 64884 382408 469458 73824 104809 244911 91481 397385 427909 319057 194883 322229 38040...

result:

ok good job!

Test #30:

score: 19
Accepted
time: 282ms
memory: 199776kb

input:

500000 200 199 40000
457235
436089
312892
490957
247950
207946
50653
437012
325088
141386
319878
207087
398253
383132
11996
402164
409233
443227
294400
242006
327126
10129
244769
232885
165818
291514
332036
352883
406737
63191
380159
208131
327008
61194
18237
223687
413010
160943
426911
162568
18875...

output:

430109 499635 484741 359744 385839 333901 288089 98276 352167 219328 324681 148925 406326 478546 81987 131830 291795 343344 288034 394508 189581 224237 120076 302345 400332 471908 493759 436271 338102 224353 417516 95746 311161 245608 323019 219800 94186 448190 485597 428847 462352 94095 465464 6507...

result:

ok good job!

Test #31:

score: 19
Accepted
time: 253ms
memory: 195300kb

input:

500000 200 199 40000
498222
451076
484997
74171
344510
119552
181399
378715
468521
103237
143923
10760
103036
353626
331913
232159
181090
14984
85005
467731
200014
74750
304897
488094
80862
428792
303440
325833
70112
301252
111208
109820
23216
97480
361786
424164
357979
22040
249278
329701
472798
13...

output:

254190 224095 403575 254787 441835 173323 494866 116770 495162 482174 458062 195211 267003 327697 339874 461704 128423 66381 496452 380845 401804 296051 338444 277202 111718 192182 283559 63067 213198 226857 73752 219540 410874 462468 247045 117455 125635 71655 245860 404133 98717 125853 120091 3016...

result:

ok good job!

Test #32:

score: 19
Accepted
time: 262ms
memory: 197176kb

input:

500000 200 199 40000
235229
335906
185851
155252
476682
68595
44502
499901
403010
120212
365527
365904
165512
445297
44401
416812
282314
301556
484290
469265
250037
184042
387456
226812
371932
410610
263086
279108
442354
371814
37100
77190
202799
118817
250469
478086
307786
11617
132836
304380
25170...

output:

84512 334590 67846 84398 361772 344927 199707 300189 39341 361970 209197 189233 82832 142238 438504 158285 285254 178422 443208 459069 240655 75359 419951 381356 435460 497662 312544 429920 356661 281074 456218 275992 134186 293889 484260 454301 166568 342651 341600 427091 160635 109132 233166 47294...

result:

ok good job!

Test #33:

score: 19
Accepted
time: 236ms
memory: 192232kb

input:

500000 200 199 40000
27113
326978
70968
474916
390195
217639
467929
292659
58323
454399
169213
185253
114409
287912
251420
281315
94695
326310
237316
424237
79688
285918
43312
65978
450176
255930
425562
242907
198847
77977
135410
122795
349710
416624
428899
314932
135513
464911
286182
28508
268649
1...

output:

383154 495088 484903 365729 36915 196840 11209 263169 255393 340669 323322 366781 455322 369803 385298 103302 102532 371354 466571 463473 422048 488775 16113 298363 271979 283397 108389 423954 138523 153650 286698 439342 306150 314146 42526 26101 6563 410910 353654 146575 308765 435646 325636 420904...

result:

ok good job!

Test #34:

score: 19
Accepted
time: 264ms
memory: 195212kb

input:

500000 200 199 40000
158367
3349
98725
462635
71709
384166
328253
132679
334131
433401
352051
9045
188775
366068
218093
90403
193264
359869
432442
263881
154277
470908
470355
200679
36628
399310
359036
163322
404722
42891
12614
147023
421373
479199
71619
182994
443724
120532
217367
134309
221302
310...

output:

434928 268613 437195 495851 354255 69204 419069 305587 334133 45453 189634 45000 391163 5965 38937 88360 342769 338499 691 225347 134611 473618 487150 454527 123711 382830 473568 137370 399272 323282 478989 59405 373840 72166 387590 376373 383128 91477 493120 26198 451825 278270 264509 6684 280070 4...

result:

ok good job!

Test #35:

score: 19
Accepted
time: 227ms
memory: 193100kb

input:

500000 200 199 40000
487441
36354
395955
6882
385179
368092
7896
377902
329818
287628
224290
27427
439352
326593
43030
180557
361665
163
8128
233496
22632
367138
126510
64436
351877
190302
145137
17783
209795
411209
255585
72497
161599
407307
216969
128706
67358
261184
268088
304573
63115
386332
827...

output:

392141 41926 348088 396582 336921 398453 163626 464364 56651 405963 384129 383230 87006 287565 482787 268951 353934 379818 330384 319023 354953 143111 110992 401553 403670 397591 321779 129356 449992 488379 61303 61482 329289 214815 454175 383390 445943 34854 231573 400467 266272 139316 143764 22891...

result:

ok good job!

Test #36:

score: 19
Accepted
time: 240ms
memory: 189892kb

input:

500000 200 199 40000
234051
59729
19849
414190
183195
238559
189881
256369
97803
379735
363604
391055
490274
186114
46653
230044
14075
437112
279313
141334
478372
146753
310018
305921
464449
475813
132149
290804
21707
51493
249658
15019
151386
494305
468781
444714
318658
179510
283604
351846
110675
...

output:

425295 271226 303957 278988 79842 395483 254615 263682 141435 386955 429785 433365 259515 422515 235300 481389 7000 364402 29646 493480 188259 20343 338442 408018 241464 201108 289191 431874 306891 387759 302886 280860 176860 60456 377968 194068 389832 9512 92188 358464 366782 154777 311194 341613 3...

result:

ok good job!

Subtask #4:

score: 22
Accepted

Test #37:

score: 22
Accepted
time: 719ms
memory: 226056kb

input:

1000000 1000 999 100000
678746
439069
32542
85937
936926
284219
461661
203235
533462
940676
230275
621140
780674
254931
562355
229273
201341
493976
358955
963527
880412
91220
474599
160086
698841
591551
718276
844558
39859
765917
34722
401724
219774
443004
682244
545401
968419
968020
354030
411187
1...

output:

927453 737189 653885 840772 346403 780854 103601 49131 439139 486132 820231 177271 826206 982104 499097 409243 194435 293457 172618 662161 236859 473531 81188 533335 712368 462084 777243 239386 911529 829354 62098 492333 390487 523069 358162 163042 451543 653539 717744 885154 584533 11086 661366 952...

result:

ok good job!

Test #38:

score: 22
Accepted
time: 718ms
memory: 227500kb

input:

1000000 1000 999 100000
530144
36744
762893
712555
181981
816257
634992
419372
362279
817260
80801
697008
163211
900947
207310
862766
871091
388529
304808
574011
609949
509094
682125
781230
431445
517909
578411
288003
874415
410542
327673
607230
278208
956997
60166
842448
708661
562761
996349
382922...

output:

70930 162711 104847 600658 547594 219142 447597 811056 140247 502224 659605 421892 389493 152949 636421 692108 137214 372169 804489 399568 586198 152111 43257 899797 878142 278025 996438 364577 750352 580921 589621 139136 802259 100210 987920 563289 985356 224651 422771 630597 972354 915562 97459 56...

result:

ok good job!

Test #39:

score: 22
Accepted
time: 570ms
memory: 216556kb

input:

1000000 1000 999 100000
184414
849676
938006
927343
390133
327580
229110
507237
712311
8816
414520
114671
637641
82050
586607
523821
775429
139792
129360
175687
202474
801377
53523
281419
268534
488983
371227
294280
754555
448802
474939
391153
68307
762784
972243
245396
471656
982894
891252
945526
5...

output:

881979 65371 912477 527036 771384 637332 77375 96895 202131 869565 189017 344963 196422 79444 100330 903304 343434 851499 371245 836709 649674 985443 866113 369794 901391 590940 852434 64909 863307 156420 172661 78866 325578 556760 158104 549272 713416 571200 129022 328902 131081 557467 370894 8037 ...

result:

ok good job!

Test #40:

score: 22
Accepted
time: 577ms
memory: 215640kb

input:

1000000 1000 999 100000
279950
249721
597292
449885
16559
173928
771422
461514
392390
935006
401814
270115
877076
38286
665465
238399
632929
179581
685305
910549
211998
608701
352060
872741
888320
701449
144650
551823
899287
53420
994085
608934
941044
730655
818001
379877
176374
592364
165476
704855...

output:

223909 718896 217558 500095 199877 328634 96085 905331 970007 158199 27921 603783 357140 504155 706692 280199 789540 617406 204097 463501 679648 197898 724177 927084 944959 886477 251562 798038 801095 937749 182285 770424 269868 664501 852487 16270 511998 258753 846305 652364 599760 557613 730263 56...

result:

ok good job!

Test #41:

score: 22
Accepted
time: 594ms
memory: 216376kb

input:

1000000 1000 999 100000
20291
14699
561360
480484
286821
851537
642046
340254
362763
85475
567413
791788
145352
893579
253840
568256
281056
600506
834619
722257
570033
739505
158527
142792
475867
834583
85573
692242
107763
238427
749609
945275
238413
468714
75532
903433
452471
189579
134021
196949
2...

output:

802849 576946 497170 716012 758812 496113 646943 780166 104468 129141 558079 844433 59593 273939 836142 686555 135726 540964 236364 980636 575270 548431 929241 236650 61762 842283 579015 337174 58957 839920 707901 698417 568342 48901 222229 826970 757594 644164 98622 70592 157070 136264 20534 795284...

result:

ok good job!

Test #42:

score: 22
Accepted
time: 694ms
memory: 219480kb

input:

1000000 1000 999 100000
79586
680985
105418
485822
250996
367398
927624
781485
911744
133593
352104
588258
914821
421528
538901
315958
275633
856427
5509
935195
913751
92920
619111
848814
663965
45219
344279
165968
865619
154854
900710
774023
872807
340764
497215
631438
911663
879056
918477
890010
3...

output:

463307 934289 351017 190930 590421 329349 207397 353160 698589 604066 736674 925930 499187 512546 224629 728976 686682 717259 943915 38674 163871 738389 521236 337757 318576 640457 759355 886092 225601 229664 90976 781806 51946 152893 685328 870872 864783 566242 988557 4905 726860 361741 488808 6791...

result:

ok good job!

Test #43:

score: 22
Accepted
time: 698ms
memory: 219332kb

input:

1000000 1000 999 100000
864268
381722
137834
585983
418961
493735
111546
74594
3531
508504
383125
609419
708077
928352
762197
141167
174341
418962
107812
631708
84967
770802
568509
276991
376328
909246
85244
453348
203444
298108
478742
824330
149959
297025
840543
296938
691263
894733
491791
319919
8...

output:

828195 835791 665377 388368 436365 943990 443275 726421 73272 550893 679669 245286 985622 828674 471421 244760 594152 498272 279598 918410 315068 181589 731587 883600 328601 100623 121515 896280 554028 486686 894194 229925 953262 775412 278622 629074 972329 893022 409360 592343 810275 792776 591239 ...

result:

ok good job!

Test #44:

score: 22
Accepted
time: 685ms
memory: 218560kb

input:

1000000 1000 999 100000
845169
885017
493118
865999
3330
999692
653381
608408
419452
799529
98306
295418
755923
442503
85146
52116
980435
452773
633069
998249
788034
527181
418057
380217
158464
23015
364569
275325
675030
381121
889352
891866
203541
14657
69958
428476
4927
853670
908949
664221
936648...

output:

264261 554773 213033 167095 460079 476465 678290 771904 247487 452229 2604 861632 905956 525799 270116 636788 168283 966476 28928 241051 414557 808579 968047 624451 332609 432698 836981 823613 725764 578806 985650 314654 882329 396154 716564 973526 68087 947437 768181 494539 464301 218405 531171 301...

result:

ok good job!

Test #45:

score: 22
Accepted
time: 647ms
memory: 218660kb

input:

1000000 1000 999 100000
582602
618937
427880
217239
896256
608317
42018
91716
145269
277504
94008
601157
503365
892936
294525
477654
286441
721652
14541
805171
315688
615193
950960
232416
430226
299443
690527
317106
303199
277200
283069
268869
650167
725195
788623
817992
647261
671722
426903
453937
...

output:

871595 153845 146436 998885 710416 695381 752688 383536 28440 887790 486262 236298 138990 598641 743599 161111 206937 958106 575202 513534 876309 507993 929031 76772 54967 198579 805405 809834 765812 493357 629546 3350 486288 475826 83185 497259 590227 124847 734532 881334 419055 759792 590422 54176...

result:

ok good job!

Test #46:

score: 22
Accepted
time: 629ms
memory: 217636kb

input:

1000000 1000 999 100000
761086
125560
807519
496861
197173
671162
286468
361527
420830
337089
99902
928320
527383
162932
540385
255275
952224
668471
897966
186547
575192
315130
399856
441499
876295
462690
556218
167574
711101
146911
914260
296451
432034
722939
27102
687771
200204
636114
525983
59197...

output:

464950 902827 958282 846598 508480 448022 831436 696630 278538 400461 98227 959239 892399 488867 645860 522789 410147 868157 979065 595866 467110 182287 688051 974358 652264 279300 534265 577714 331923 693086 703371 474168 913274 314267 482826 996478 659670 545055 479754 967361 721159 107379 108340 ...

result:

ok good job!

Test #47:

score: 22
Accepted
time: 612ms
memory: 218188kb

input:

1000000 1000 999 100000
700422
705984
742655
297368
991331
273447
971924
235042
288410
226105
751213
71757
552545
234328
777224
460184
747354
483278
77275
960232
145343
677496
979573
598317
294693
762557
214101
155814
368037
345816
214266
272277
6667
461234
109578
330628
355557
16281
696921
633114
6...

output:

280854 748941 965663 52093 765738 688770 804241 50893 713297 572171 332298 479000 868683 390347 829676 121783 664736 240859 481008 798858 732908 93893 908421 830478 949532 512679 577977 720518 556787 345400 908919 440071 637688 657447 747811 777615 958310 164787 575870 569617 527750 380880 503067 28...

result:

ok good job!

Test #48:

score: 22
Accepted
time: 586ms
memory: 220356kb

input:

1000000 1000 999 100000
294979
912636
954626
984835
432393
676651
323592
496950
442003
287176
988897
310588
517194
868410
42913
165122
231552
13998
103334
502710
396538
590023
630061
530055
980426
628250
446184
451072
276133
424200
328584
26687
392134
766381
197139
174221
564083
149136
481705
457343...

output:

474295 903419 600502 158418 618883 77946 541327 691617 279685 545829 371649 492990 689702 393806 529836 959331 901255 75652 614474 325479 936332 983931 197515 894203 473057 683679 921426 902388 573665 541873 58301 240808 477910 449220 214967 874238 132798 743132 51696 313697 902443 271444 538487 620...

result:

ok good job!

Subtask #5:

score: 0
Wrong Answer

Dependency #4:

100%
Accepted

Test #49:

score: 0
Wrong Answer
time: 806ms
memory: 230740kb

input:

1000000 91074 91073 100000
844855
360256
604500
520288
3402
603913
199722
732526
574997
429775
182518
190073
386932
693624
254661
333433
557929
350362
247817
201441
960948
519977
461212
493412
852908
455639
732827
432452
320916
223796
413293
969300
617038
438432
2369
51283
908991
374139
410798
19612...

output:

104349 170744 322298 943785 796710 500874 79937 976772 191057 27689 906009 603418 442795 561154 796064 292228 504787 249824 525843 435036 271618 183442 461251 6332 765553 582250 226179 860734 445334 729051 457570 772087 147634 119269 85940 899087 838934 714547 249430 419834 488759 535606 70064 74100...

result:

wrong answer wrong answer on the first integer of query #1: read 0 but expected 20911630