QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#754420#5435. Clamped Sequenceenar#TL 769ms4132kbC++201.4kb2024-11-16 14:59:482024-11-16 14:59:49

Judging History

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

  • [2024-11-16 14:59:49]
  • 评测
  • 测评结果:TL
  • 用时:769ms
  • 内存:4132kb
  • [2024-11-16 14:59:48]
  • 提交

answer

#include <bits/stdc++.h>

void solve() {
    int n, d;
    std::cin >> n >> d;
    std::vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        std::cin >> a[i];
    }
    std::set<int> st(a.begin(), a.end());
    auto func = [&](int l, int r) ->int64_t {
        std::vector<int> v = a;
        for(int i = 0; i < n; ++i) {
            v[i] = std::max(v[i], l);
            v[i] = std::min(v[i], r);
        }
        int64_t res = 0;
        for(int i = 0; i + 1 < n; ++i) {
            res += std::abs(v[i] - v[i + 1]);
        }
        return res;
    };
    int64_t ans = 0;
    int64_t lst = -1E9;
    for(const auto &x : st) {
        int64_t l = lst, r = x, res = 0;
        while(l <= r) {
            int64_t lmid = l + (r - l + 1) / 3;
            int64_t rmid = r - (r - l + 1) / 3;
            int64_t lres = func(lmid, lmid + d);
            int64_t rres = func(rmid, rmid + d);
            if(lres > rres) {
                r = rmid - 1;
                res = std::max(res, lres);
            } else {
                l = lmid + 1;
                res = std::max(res, rres);
            }
        }
        ans = std::max(ans, res);
        lst = x;
    }
    std::cout << ans << '\n';
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int T = 1;
    while(T--) {
        solve();
    }
    return 0;
}

详细

Test #1:

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

input:

8 3
3 1 4 1 5 9 2 6

output:

15

result:

ok 1 number(s): "15"

Test #2:

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

input:

2 1
-1000000000 1000000000

output:

1

result:

ok 1 number(s): "1"

Test #3:

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

input:

2 1000000000
-1000000000 1000000000

output:

1000000000

result:

ok 1 number(s): "1000000000"

Test #4:

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

input:

5000 10000
-10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10000 10000 -10...

output:

49990000

result:

ok 1 number(s): "49990000"

Test #5:

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

input:

5000 10000
10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 1...

output:

0

result:

ok 1 number(s): "0"

Test #6:

score: 0
Accepted
time: 177ms
memory: 4100kb

input:

5000 2897
8987 9710 547 6523 -4484 8892 7360 7473 -5435 8122 -1396 -9963 -1884 -5758 -2930 2867 -260 -3947 -7915 -2428 4137 -1202 -1874 7205 -2852 -6126 -9346 -8662 2294 -4453 -2430 2424 9434 -112 2906 -169 -9489 -1977 68 -9072 2785 -2258 9710 271 8817 6251 3120 4765 -8449 -6625 2617 -3931 -4024 144...

output:

7111087

result:

ok 1 number(s): "7111087"

Test #7:

score: 0
Accepted
time: 175ms
memory: 3816kb

input:

5000 6321
-5894 5183 -3582 7556 -2937 2854 -5688 1422 -7283 5712 -3719 3700 -8585 2577 -703 1839 -8871 9819 -1080 6964 -7192 1664 -9414 1863 -3638 7843 -6700 9064 -4209 7225 -2617 180 -9771 401 -3029 7485 -3877 3095 -4176 5830 -1954 8879 -9515 4671 -9834 395 -3489 6706 -5316 9004 -3536 546 -5360 686...

output:

26696461

result:

ok 1 number(s): "26696461"

Test #8:

score: 0
Accepted
time: 181ms
memory: 3820kb

input:

5000 1224
-9995 -9993 -9992 -9990 -9987 -9979 -9977 -9969 -9965 -9963 -9959 -9956 -9944 -9944 -9931 -9930 -9929 -9927 -9926 -9924 -9923 -9921 -9917 -9917 -9907 -9901 -9899 -9890 -9885 -9876 -9871 -9867 -9859 -9859 -9859 -9854 -9854 -9841 -9841 -9836 -9836 -9834 -9831 -9829 -9823 -9823 -9822 -9818 -9...

output:

1224

result:

ok 1 number(s): "1224"

Test #9:

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

input:

5000 1000000
-1000000 1000000 -1000000 1000000 -1000000 1000000 -1000000 1000000 -1000000 1000000 -1000000 1000000 -1000000 1000000 -1000000 1000000 -1000000 1000000 -1000000 1000000 -1000000 1000000 -1000000 1000000 -1000000 1000000 -1000000 1000000 -1000000 1000000 -1000000 1000000 -1000000 100000...

output:

4999000000

result:

ok 1 number(s): "4999000000"

Test #10:

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

input:

5000 1000000
1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000...

output:

0

result:

ok 1 number(s): "0"

Test #11:

score: 0
Accepted
time: 767ms
memory: 3836kb

input:

5000 187598
115918 -727930 454749 -650387 -131030 -583797 907610 -314887 -494840 -116261 406466 734257 -410787 342451 -14930 831297 314447 -433165 -777692 -609353 -434131 518832 320933 -199305 154559 932798 930259 214168 -930213 -34688 247952 503849 21404 311008 -785124 -503509 -476434 -654305 -2049...

output:

477553294

result:

ok 1 number(s): "477553294"

Test #12:

score: 0
Accepted
time: 769ms
memory: 4132kb

input:

5000 771022
-433847 99241 -927062 676808 -285169 89911 -510718 955902 -571570 492726 -139309 477186 -547729 353570 -725526 425661 -48956 239263 -322769 706571 -439634 141317 -391906 398130 -314133 863417 -600052 439135 -352487 753429 -139934 14119 -561827 258290 -54747 419167 -669228 189453 -373567 ...

output:

3125424072

result:

ok 1 number(s): "3125424072"

Test #13:

score: 0
Accepted
time: 756ms
memory: 3824kb

input:

5000 964263
-999875 -999003 -998711 -998242 -997924 -997483 -997289 -997020 -997006 -996326 -995855 -995273 -994500 -994316 -994065 -994038 -993391 -992800 -992573 -991083 -990368 -990156 -990045 -990029 -989806 -988798 -987858 -986711 -986697 -986484 -985989 -985838 -985087 -984605 -983535 -983207 ...

output:

964263

result:

ok 1 number(s): "964263"

Test #14:

score: 0
Accepted
time: 762ms
memory: 3824kb

input:

5000 470574
-780515 -565052 540227 331334 -814359 813817 146460 -468526 -757891 710807 -753613 885094 -727795 373597 712366 -262537 148313 -172412 979620 -921670 -746243 -317334 -673027 190226 844027 -537371 -81273 -545282 -18126 -273706 -492037 439079 69269 -523256 -263698 -564222 -357935 -520341 -...

output:

1146273041

result:

ok 1 number(s): "1146273041"

Test #15:

score: 0
Accepted
time: 766ms
memory: 3896kb

input:

5000 553999
-383027 159712 -632376 301503 -328868 532550 -798606 839794 -952568 547489 -131306 300856 -567633 559760 -931367 903728 -455406 78693 -933438 114173 -107792 402731 -901237 217199 -256503 295296 -661728 482029 -277184 759196 -711481 598907 -575679 97357 -500627 75038 -734531 924348 -35588...

output:

2371523741

result:

ok 1 number(s): "2371523741"

Test #16:

score: 0
Accepted
time: 768ms
memory: 3776kb

input:

5000 859344
-999811 -999297 -998112 -997262 -997043 -996924 -996891 -996031 -994416 -994412 -993847 -993651 -992769 -992318 -992260 -991391 -990815 -990515 -990165 -990137 -989941 -988550 -988458 -988186 -987523 -987484 -987204 -986704 -986611 -986563 -986215 -985492 -985440 -985164 -984845 -984387 ...

output:

859344

result:

ok 1 number(s): "859344"

Test #17:

score: 0
Accepted
time: 761ms
memory: 4092kb

input:

5000 753551
224979 632678 597334 347907 -462837 -823422 448533 342983 979058 -490498 -850469 -865995 -108024 -728183 -588710 -293147 10551 116713 -297921 -268837 -23504 846501 333014 -385392 -466507 -7540 -29583 695269 795887 452425 796347 -590839 -819644 544407 -805496 -624935 725714 -386377 238167...

output:

1803811669

result:

ok 1 number(s): "1803811669"

Test #18:

score: 0
Accepted
time: 756ms
memory: 3828kb

input:

5000 826108
-506082 830836 -68098 345647 -202707 920622 -435431 472585 -132184 27988 -523678 177442 -7098 222566 -399388 649621 -459957 320586 -971439 698215 -650533 307030 -658607 442217 -194639 174723 -537732 420706 -437605 6790 -835034 530710 -246859 977996 -195240 232084 -443806 733902 -952063 5...

output:

3315584633

result:

ok 1 number(s): "3315584633"

Test #19:

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

input:

5000 1000000000
-1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000...

output:

4999000000000

result:

ok 1 number(s): "4999000000000"

Test #20:

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

input:

5000 1000000000
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 100000000...

output:

0

result:

ok 1 number(s): "0"

Test #21:

score: -100
Time Limit Exceeded

input:

5000 910901608
974118216 -282189310 -464236812 467039630 667895423 339508537 58260393 -703766496 504826455 441618514 -585508328 -193759450 688197130 -930698882 707075173 -451731589 606780952 806202619 -564168107 -344313708 886153476 -454490978 83456751 819316128 -226033791 783846069 962016852 238052...

output:


result: