QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#282440#7072. PhotographVladMTL 392ms4904kbC++172.0kb2023-12-12 00:47:172023-12-12 00:47:17

Judging History

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

  • [2023-12-12 00:47:17]
  • 评测
  • 测评结果:TL
  • 用时:392ms
  • 内存:4904kb
  • [2023-12-12 00:47:17]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define DIM 100007

long long h[DIM], ans, sum, it1, it2, d;

int n, q, it, p[2*DIM];

set<int> s;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> q;
    for(int i = 1; i <= n; i++) cin >> h[i];
    for(int i = 1; i <= n; i++) cin >> p[i];
    for(int i = n + 1; i <= 2 * n; i++) p[i] = p[i - n];
    it = 1;
    for(int tst = 1; tst <= q + 1; tst++){
        if(tst != 1){
            cin >> d;
            d += ans;
            it = (it - 1 + d + n) % n + 1;
        }
        sum = 0;
        ans = 0;
        s.clear();
        for(int i = it; i <= it + n - 1; i++){
            if(s.empty()){
                s.insert(p[i]);
                continue;
            }
            if(s.size() == 1){
                it1 = *s.begin();
                sum += (h[p[i]] - h[it1]) * (h[p[i]] - h[it1]);
                ans += sum;
                s.insert(p[i]);
                continue;
            }
            it1 = *s.begin();
            if(p[i] < it1){
                //cout << it1 << ' ' << H[i] << endl;
                sum += (h[p[i]] - h[it1]) * (h[p[i]] - h[it1]);
                ans += sum;
                s.insert(p[i]);
                continue;
            }
            it1 = *(--s.end());
            if(p[i] > it1){
                //cout << it1 << ' ' << H[i] << endl;
                sum += (h[p[i]] - h[it1]) * (h[p[i]] - h[it1]);
                ans += sum;
                s.insert(p[i]);
                continue;
            }
            auto LB = s.lower_bound(p[i]);
            it1 = *(LB);
            it2 = *(--LB);
            it1 = h[it1];
            it2 = h[it2];
            //cout << it1 << ' ' << H[i] << ' ' << it2 << endl;
            sum -= (it1 - it2) * (it1 - it2);
            sum += (h[p[i]] - it1) * (h[p[i]] - it1);
            sum += (h[p[i]] - it2) * (h[p[i]] - it2);
            ans += sum;
            s.insert(p[i]);
        }
        cout << ans << "\n";
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5 4
1 2 3 4 5
1 2 3 4 5
6
6
8
10

output:

10
10
13
21
36

result:

ok 5 lines

Test #2:

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

input:

1 100
9139
1
815121916
455099013
31761433
46418945
11466871
709189476
658667824
977821005
511405192
843598992
501074199
638564514
680433292
994431111
584582554
452689372
642414314
863578235
135133204
438404803
67246919
492858783
447116205
723252212
948645336
191050463
326944894
685212650
828613990
1...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

result:

ok 101 lines

Test #3:

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

input:

2 100
9859 8096
2 1
692572036
546897526
810778144
630776743
411450468
47253421
344401774
898201838
853758724
613913038
441359030
921437570
855535818
106915566
108572797
533697405
315571976
503278469
849317884
327448764
867873746
718830950
808828124
547579134
751502930
595486247
629024078
79153124
34...

output:

3108169
3108169
3108169
3108169
3108169
3108169
3108169
3108169
3108169
3108169
3108169
3108169
3108169
3108169
3108169
3108169
3108169
3108169
3108169
3108169
3108169
3108169
3108169
3108169
3108169
3108169
3108169
3108169
3108169
3108169
3108169
3108169
3108169
3108169
3108169
3108169
3108169
3108...

result:

ok 101 lines

Test #4:

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

input:

3 100
5987 4237 8891
3 1 2
760669141
361439344
393719043
515372386
379329282
704177992
446687639
688441074
939269095
570763162
492018656
161714447
596461367
384092911
304150759
54574629
350079205
804917425
296791887
311704304
120533843
281070757
787668201
311851357
243944555
860970785
463288414
9962...

output:

33155432
33155432
33155432
46381932
33155432
46381932
33155432
27784716
27784716
46381932
33155432
27784716
33155432
27784716
46381932
33155432
46381932
33155432
33155432
46381932
27784716
33155432
33155432
46381932
33155432
27784716
33155432
33155432
46381932
46381932
46381932
46381932
46381932
277...

result:

ok 101 lines

Test #5:

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

input:

4 100
9411 3081 2149 9907
2 4 1 3
890272966
654059361
166090080
333233666
911989359
541813943
232020213
717913040
277628991
24281180
424608385
453986387
234435555
940076771
584737344
285922050
322027160
55417534
219258279
944530197
902531317
204963356
159347669
59389769
496952588
412286058
62840111
...

output:

234381540
194798256
163047900
163047900
214293312
234381540
163047900
234381540
234381540
163047900
163047900
234381540
163047900
194798256
214293312
214293312
163047900
163047900
214293312
234381540
214293312
194798256
194798256
163047900
234381540
234381540
194798256
214293312
194798256
234381540
...

result:

ok 101 lines

Test #6:

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

input:

5 100
5539 9221 6895 2089 8673
1 2 3 5 4
77109657
780837560
486885376
754808995
539371459
829908259
461093031
358202421
812475269
330167945
420738799
449755992
974016054
893157388
911184149
27096064
544888624
181378986
949932667
679253230
633194309
392611044
893327579
740816578
390443961
911660892
1...

output:

140067300
223307496
291786308
223307496
291786308
140067300
203804176
171252896
291786308
140067300
140067300
203804176
223307496
223307496
171252896
171252896
171252896
171252896
291786308
291786308
171252896
171252896
171252896
171252896
140067300
171252896
203804176
140067300
140067300
140067300
...

result:

ok 101 lines

Test #7:

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

input:

6 100
6259 770 7448 3054 7926 1667
2 1 5 3 6 4
322065559
589340392
229869162
513690899
994467050
633820414
856590056
742301205
94367267
935173705
269614273
371228927
648897289
275136359
947994032
14652900
375199561
962516208
27020002
91805311
784722753
914752052
789918299
362845589
71976266
81221521...

output:

457491743
457491743
373376971
301534488
373376971
457491743
373376971
457491743
405608641
405608641
301534488
374356525
374356525
285814308
457491743
285814308
285814308
405608641
373376971
405608641
301534488
285814308
373376971
373376971
373376971
457491743
301534488
374356525
457491743
373376971
...

result:

ok 101 lines

Test #8:

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

input:

7 100
2387 5422 4898 2532 2988 4636 9872
7 6 4 1 5 2 3
989301423
726738333
762016619
720019121
224386186
389607162
105343720
162417396
185295808
598490187
99799082
648854654
536061877
114509431
283693326
282358088
275870967
913068064
614906460
852055446
91973668
194752801
390559107
461675312
2011715...

output:

214808460
176848801
221076979
177842834
214808460
141417382
177842834
177842834
183113350
177842834
183113350
177842834
176848801
95737577
214808460
221076979
95737577
214808460
183113350
183113350
141417382
221076979
95737577
214808460
221076979
221076979
95737577
176848801
221076979
177842834
1768...

result:

ok 101 lines

Test #9:

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

input:

8 100
8515 1563 5451 4713 9537 709 3343 1819
6 3 5 4 7 2 8 1
836830783
902424840
284979127
688898930
59994023
808377077
930879146
894119069
821284022
790534164
228245558
799101331
178643742
437272706
727533806
775447721
24262953
878651956
922486099
872583248
662851066
537459716
952308815
516311556
5...

output:

751938476
437536532
772628520
652581904
751938476
437536532
557787696
652581904
437536532
686111272
562017712
772628520
695734860
557787696
652581904
557787696
686111272
652581904
695734860
562017712
562017712
437536532
437536532
652581904
695734860
652581904
686111272
686111272
695734860
652581904
...

result:

ok 101 lines

Test #10:

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

input:

9 100
1939 407 197 4191 8791 9486 8030 5807 11
3 6 9 1 8 7 5 2 4
315381698
90569951
966739056
839050299
904095993
625868334
181495123
11473484
460154086
971398763
979097531
680974958
656252706
241084925
897974527
468605657
884412240
443130759
588996224
238053542
114337251
472276082
321394542
8344271...

output:

1023923923
605498313
674262593
373588111
476117235
674262593
605498323
1023923923
403693374
373588111
373588111
799677263
476117235
674262593
605498313
373588111
605498323
674262593
605498323
799677263
674262593
605498323
373588111
561924404
1023923923
674262593
799677263
403693374
403693374
6742625...

result:

ok 101 lines

Test #11:

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

input:

10 100
518 6518 4071 9971 121 4862 3967 3607 9138 754
1 4 6 3 9 5 7 2 10 8
719710883
666234150
467699746
727866843
45112665
282378479
269145212
766047675
927093918
324077627
288227195
970588158
53638885
428349538
228916329
382463463
828400290
815679985
192268817
213004434
912994422
290756648
9495302...

output:

1565945277
1565945277
1197593514
1197593514
1535585224
1274777281
1274777281
879023037
1384491329
1148485517
1360738892
879023037
1526843055
1526843055
1535585224
1197593514
1535585224
1384491329
980900206
1148485517
879023037
1148485517
1565945277
1535585224
1360738892
1360738892
1535585224
8790230...

result:

ok 101 lines

Test #12:

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

input:

20 100
5440 8704 1481 2140 5810 8854 3034 5150 684 1360 516 4301 8790 3678 6138 9893 9899 260 2881 6499
16 2 18 6 10 17 13 14 9 15 7 11 19 8 5 12 1 4 3 20
873743899
267369173
386910848
723632495
701073067
948499896
955797196
123811466
110006083
224370701
608902286
678328025
748844283
340300747
56966...

output:

4460296043
4639005790
3445021867
4460296043
5993760213
5993760213
2461320767
3329872438
4177195619
5385479095
3302882127
3445021867
5506852915
4692208381
3747380630
5385479095
3701512884
3373660669
5506852915
3329872438
3101912149
4625124890
4177195619
5506852915
3701512884
3302882127
3302882127
446...

result:

ok 101 lines

Test #13:

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

input:

50 100
81 7965 736 4325 2476 832 4026 3972 1400 7099 5141 7386 9799 9285 4039 818 3552 2203 5273 8168 2783 365 9351 945 7154 8047 7586 9184 573 8953 8849 6466 5479 9848 2827 1475 4283 7115 2590 8903 7800 4550 4140 2514 849 6786 7881 3456 3022 5051
47 21 8 45 30 46 49 20 35 13 22 10 12 33 29 32 14 44...

output:

17901780726
21335068397
23069343089
16950972033
23440737536
20117989735
18356412077
23525547283
22194828031
19811623125
20333420304
22427374378
20286983804
27017764531
19811623125
20286983804
20143513995
17287897270
27017764531
21801672311
19863325956
23377168350
17657924342
21801672311
22957130016
...

result:

ok 101 lines

Test #14:

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

input:

100 100
4115 1014 5932 1665 528 1396 4633 8293 2948 1428 6757 8520 5932 3620 5590 6142 5157 6353 1218 7858 1394 5121 7927 5729 7737 9722 3094 2845 4567 2360 6083 2123 9320 9323 8935 7893 6303 5142 7006 1146 1668 7346 2234 3625 5617 4616 7550 4105 949 7691 1923 9876 1569 6300 1558 3768 4381 3732 5288...

output:

80031664363
77657872547
70145626337
85045803740
78022469686
77866663743
77390386319
89696446847
83105646995
80198430484
83081961557
85078735719
75376793307
83373111607
77147665384
69884444547
81358282505
90856824687
85078735719
74490379696
87311539708
90856824687
73592457322
87849986173
87849986173
...

result:

ok 101 lines

Test #15:

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

input:

200 100
2960 1568 8113 919 9305 6083 1325 2449 7131 1868 6501 8610 5469 3943 3507 9272 9611 7075 8163 5798 9171 5334 9607 9586 3354 3943 7955 7157 4437 5778 6354 4414 5456 5624 6639 2623 6378 5084 221 4542 2887 1638 6688 326 9405 1428 9090 4723 3607 804 5167 4458 6197 1900 1497 5358 2490 6483 3092 1...

output:

293418365919
326723178330
309087105859
276977973321
303709745476
291821856450
324471734393
279812248071
315492045682
330117133118
321927601969
324112145380
302369447503
310394007301
316857653167
320732415815
291719697819
317750034396
276977973321
323623995598
300475239717
268796333038
315205481843
3...

result:

ok 101 lines

Test #16:

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

input:

500 100
6789 7021 738 1784 7123 6225 3289 7619 9677 5891 8836 8881 577 9104 1450 6632 6478 6538 9397 6644 1017 966 4244 6565 9787 3902 9434 3198 8640 353 6077 4391 5753 4654 6248 9516 6603 6796 953 3933 334 1685 5459 3404 6848 1863 6414 6978 495 5954 9218 4825 8466 5180 5904 1619 5057 5536 5017 9378...

output:

2133904075206
2289302087360
2144811996572
2139453787635
2209077279831
2297947877040
2202889039833
2128633993178
2192072806628
2148612856470
2220983504043
2203590782491
2268320522349
2141756036558
2138926499371
2188279929163
2139326014398
2133498398272
2135491428344
2176300859898
2138223102773
217543...

result:

ok 101 lines

Test #17:

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

input:

1000 100
9894 4197 1325 3232 4902 1183 7041 1481 8495 7266 152 8704 5790 4458 6546 6258 3030 9366 7747 546 6332 3816 7523 7683 9771 2152 9647 9967 6785 3793 1062 8915 6864 5667 6972 9536 5678 9183 9290 7164 2533 5374 5932 943 1508 1627 8226 2823 7644 4596 8767 3620 2563 5613 1053 7340 1813 7164 9591...

output:

7981784391963
7978818307790
8246297650037
7914133704386
8015489418731
8174046462467
8058205851919
7913747443205
7915300201665
7879936810393
7980006758992
7977516169049
8165705833057
8101106995102
8029584184378
8023809723263
8323488045529
7809423971911
8076862825252
8383133020587
7944689656970
791762...

result:

ok 101 lines

Test #18:

score: 0
Accepted
time: 27ms
memory: 3796kb

input:

2000 100
6271 7415 3493 8921 8895 2953 8585 322 4909 4077 3116 9803 6892 964 7756 5407 7374 659 8933 9341 1597 9828 9547 4906 3573 6133 7556 1421 8104 7287 2075 8322 6233 8464 3519 7064 817 4730 2657 1075 4126 9570 2426 3434 5583 1785 1554 1978 9785 5126 4906 1585 6613 4275 9475 3572 5167 2764 2581 ...

output:

31477810356424
32204977824423
32160551783144
32171598385227
33063969475605
32130003986779
32021555729968
31913842464300
32919654277685
33004889816595
32063984671380
31328706829667
31936783900870
33400455792547
33348437075247
31721741474797
32663271777801
32275162439114
32180578455205
33348792635919
...

result:

ok 101 lines

Test #19:

score: 0
Accepted
time: 79ms
memory: 3912kb

input:

5000 100
2829 6670 5679 1395 5065 1242 1599 3742 4840 8702 6201 812 5603 3457 1385 2163 3509 1562 603 2624 7390 7464 9938 4289 3091 3754 2900 4169 1387 2359 3628 6143 4339 7544 4775 863 1915 4473 3847 2807 4311 8652 4611 5099 5504 9157 9925 4851 7696 2399 2234 7096 2553 8645 8934 7946 6047 5642 1678...

output:

210857193521308
209453022743142
209602395377577
209046001031692
210145727974890
208446657249604
209255137801970
209040449345374
208714639563282
209932405001013
210475676250666
209484668645997
210052060276996
208245389688369
211269420840673
210584536116411
210927411911226
208483357244260
209376886525...

result:

ok 101 lines

Test #20:

score: 0
Accepted
time: 179ms
memory: 4220kb

input:

10000 100
8581 6058 3019 2151 4140 4553 5920 9883 9170 318 1527 6945 5345 5007 6709 7960 7659 7507 7188 3939 4849 3336 7426 9064 4765 9262 9265 8162 8985 2298 9285 7280 9622 3652 3897 8691 4135 6185 682 2484 7107 8233 8426 9867 7526 314 574 2777 4928 5363 7617 9583 9748 8482 9103 1701 5339 951 4875 ...

output:

854703488502466
855472024095359
847023698769249
855078929652868
854478501793200
856946588070231
856527612186354
847108510362009
853962331289242
850152777764715
839019515696414
836889492766597
839914615559625
855052370109305
832648512832854
854069738670068
839165662078776
848534489745680
857729565170...

result:

ok 101 lines

Test #21:

score: 0
Accepted
time: 392ms
memory: 4904kb

input:

20000 100
9135 8239 2273 2416 316 5837 75 4065 9609 62 4721 3378 5668 2924 4431 2414 8381 4452 937 1717 2359 7720 1283 9272 8986 4123 3577 8032 2404 2568 1576 3416 5923 8252 5923 8766 4476 9400 9487 3702 5592 5392 2423 3655 146 4558 8488 1244 746 8607 7606 4212 2644 5717 2182 5218 1194 8755 4386 610...

output:

3390495723109384
3370689095676011
3366304507534486
3414617200467113
3359036644950176
3380108370724598
3385374098771083
3362896235631443
3353254976673473
3375625039707345
3392924772270764
3403532658983606
3386948536872428
3385847282978717
3413575685196834
3351740962356596
3382921965218929
33891279236...

result:

ok 101 lines

Test #22:

score: -100
Time Limit Exceeded

input:

50000 100
7692 864 3137 234 3161 7801 5246 6612 3632 9693 7696 1590 2317 3571 1391 9281 7843 5687 9078 858 7991 2357 5558 1113 8946 5602 2322 4939 1570 9188 1553 6417 4953 965 2816 8991 8893 2836 6173 3854 1447 1459 8205 6906 580 1882 7638 5028 87 2659 5270 6481 4437 3228 4250 5081 2951 3384 4008 21...

output:


result: