QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#449816#8597. Запити красот пiдмасивiвarbuzick#10 2349ms19544kbC++202.9kb2024-06-21 17:43:352024-06-21 17:43:35

Judging History

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

  • [2024-06-21 17:43:35]
  • 评测
  • 测评结果:10
  • 用时:2349ms
  • 内存:19544kb
  • [2024-06-21 17:43:35]
  • 提交

answer

#include <bits/extc++.h>

using namespace std;

constexpr long long inf = (long long)1e18 + 7;

mt19937 rnd(57);

struct Node {
    long long x;
    int y;
    long long val, mn, mx;
    Node *l, *r;

    Node(long long _x, long long _val) {
        x = _x;
        val = _val;
        y = rnd();
        mn = mx = val;
        l = r = nullptr;
    }
};

long long mn(Node *root) {
    if (root == nullptr) {
        return inf;
    }
    return root->mn;
}

long long mx(Node *root) {
    if (root == nullptr) {
        return -inf;
    }
    return root->mx;
}

void relax(Node *root) {
    root->mn = min(min(mn(root->l), mn(root->r)), root->val);
    root->mx = max(max(mx(root->l), mx(root->r)), root->val);
}

Node *merge(Node *root1, Node *root2) {
    if (root1 == nullptr) {
        return root2;
    }
    if (root2 == nullptr) {
        return root1;
    }
    if (root1->y > root2->y) {
        root1->r = merge(root1->r, root2);
        relax(root1);
        return root1;
    } else {
        root2->l = merge(root1, root2->l);
        relax(root2);
        return root2;
    }
}

pair<Node *, Node *> split_key(Node *root, long long val) {
    if (root == nullptr) {
        return make_pair(nullptr, nullptr);
    }
    if (root->x >= val) {
        auto [res1, res2] = split_key(root->l, val);
        root->l = res2;
        relax(root);
        return make_pair(res1, root);
    } else {
        auto [res1, res2] = split_key(root->r, val);
        root->r = res1;
        relax(root);
        return make_pair(root, res2);
    }
}

void solve() {
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vector<long long> pr_sum(n + 1);
    for (int i = 0; i < n; ++i) {
        pr_sum[i + 1] = pr_sum[i] + a[i];
    }
    vector<long long> ans(n + 1);
    Node *root = new Node(inf + 10, pr_sum[0]);
    for (int i = 0; i < n; ++i) {
        long long l = 0, r = inf;
        while (l < r - 1) {
            long long m = (l + r) / 2;
            auto [res1, res2] = split_key(root, m);
            if (abs(pr_sum[i + 1] - mn(res2)) >= m || abs(pr_sum[i + 1] - mx(res2)) >= m) {
                l = m;
            } else {
                r = m;
            }
            root = merge(res1, res2);
        }
        ans[i + 1] = l;
        auto [res1, res2] = split_key(root, ans[i + 1]);
        Node *add = new Node(ans[i + 1], pr_sum[i + 1]);
        root = merge(res1, merge(add, res2));
    }
    while (q--) {
        int tp;
        cin >> tp;
        if (tp == 1) {
            int l, r;
            cin >> l >> r;
            l--;
            cout << ans[r] << '\n';
        } else {
            assert(false);
        }
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

详细

Subtask #1:

score: 0
Time Limit Exceeded

Test #1:

score: 0
Time Limit Exceeded

input:

1000000 1000000
548734664 631285694 511074814 185066089 177199147 524740185 143108778 954318193 103939390 194933972 126964310 977448144 188825490 775722231 460775045 254691982 436971964 566341931 148211711 74910105 923734998 440021758 474275150 717904448 680353276 612974499 712145218 300908726 34722...

output:


result:


Subtask #2:

score: 0
Wrong Answer

Test #7:

score: 0
Wrong Answer
time: 5ms
memory: 3652kb

input:

1000 1000
-873807720 -737050877 797489760 406646247 -750849890 -581119106 43724194 -931326234 -9389547 -684003608 -926307185 -502569356 -461635706 -238087464 -83909772 -884633970 46721429 -576741985 -323890970 -855342249 -736506813 336516318 -4075924 -782227362 56799828 290931118 -471600723 81594380...

output:

9772834244
15462720211
7251185652
13393640180
18501658870
12689687707
15191280458
12319842467
12471320560
13214755699
13163077635
11983481729
12837501934
16221986663
9535060175
13280162557
14897546702
13280162557
11187753048
14166055791
12128128914
11060667593
12178994462
10688736658
13469464498
943...

result:

wrong answer 2nd numbers differ - expected: '7971661681', found: '15462720211'

Subtask #3:

score: 0
Wrong Answer

Test #14:

score: 0
Wrong Answer
time: 2042ms
memory: 19508kb

input:

200000 200000
580139218 -783262026 565291185 -701435432 -591602198 -342573855 -900284959 -10919966 -682899137 -282058183 963121871 491072571 691886927 761414760 -828585515 888361166 -790814084 145385324 214735368 388759807 -80339362 -975535748 522135695 301673442 36714481 785639770 319723485 1098009...

output:

320467023213
325906620916
262067162421
270377543351
283220169148
241979977726
271577688278
175871210801
201706307025
204109001683
202446360421
317232760227
333297491403
236879304185
270820853058
325597045888
286998924300
201183973192
246681999523
183705163810
268245778764
321561303384
197528615352
2...

result:

wrong answer 1st numbers differ - expected: '351460487491', found: '320467023213'

Subtask #4:

score: 10
Accepted

Test #21:

score: 10
Accepted
time: 2349ms
memory: 19416kb

input:

200000 200000
128744308 920701830 -482412021 59142239 721167306 -622861403 165749748 -449445968 -760679479 -207234657 171482190 -239316743 75518499 -717652242 502074875 -731242646 -183939818 -625333917 -53052313 185734819 -780000096 -563390882 -690210905 596581513 764466021 776717157 -38544163 -7898...

output:

128744308
1049446138
567034117
626176356
1347343662
724482259
890232007
906557623
1347343662
1347343662
1347343662
1347343662
1347343662
1347343662
1347343662
1466264164
1650203982
2275537899
2328590212
2142855393
2922855489
3486246371
4176457276
3579875763
2815409742
2137764691
2099220528
286704480...

result:

ok 200000 numbers

Test #22:

score: 0
Accepted
time: 1209ms
memory: 19440kb

input:

200000 200000
-763412911 313139114 535079082 989042081 993109117 995888077 998971206 999773517 999866478 999987134 777032268 990233656 992330606 996752593 998494028 998593842 998945960 999764312 999884287 999976973 653522695 919553000 971305283 988605240 995829044 997504762 999283178 999840628 99997...

output:

763412911
450273797
763412911
1073847366
2066956483
3062844560
4061815766
5061589283
6061455761
7061442895
7838475163
8828708819
9821039425
10817792018
11816286046
12814879888
13813825848
14813590160
15813474447
16813451420
17466974115
18386527115
19357832398
20346437638
21342266682
22339771444
2333...

result:

ok 200000 numbers

Test #23:

score: 0
Accepted
time: 1201ms
memory: 19544kb

input:

200000 200000
-825716414 416551232 517318490 714074106 868865237 955360474 973766234 984001767 996937534 999327490 999449772 999632500 999833646 999907522 999933058 999950810 999961227 999993042 999993315 999999589 999999786 999999944 999999987 999999999 1000000000 1000000000 1000000000 1000000000 1...

output:

825716414
416551232
825716414
825716414
1691092651
2646453125
3620219359
4604221126
5601158660
6600486150
7599935922
8599568422
9599402068
10599309590
11599242648
12599193458
13599154685
14599147727
15599141042
16599140631
17599140417
18599140361
19599140348
20599140347
21599140347
22599140347
23599...

result:

ok 200000 numbers

Test #24:

score: 0
Accepted
time: 1213ms
memory: 19420kb

input:

200000 200000
-151818563 160849335 914523434 941544657 957339565 971073750 998040223 998195659 999642984 999721721 999812380 999941098 999968574 999985544 999992595 999998006 999999673 999999850 999999978 999999997 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 10000000...

output:

151818563
151818563
923554206
1865098863
2822438428
3793512178
4791552401
5789748060
6789391044
7789112765
8788925145
9788866243
10788834817
11788820361
12788812956
13788810962
14788810635
15788810485
16788810463
17788810460
18788810460
19788810460
20788810460
21788810460
22788810460
23788810460
247...

result:

ok 200000 numbers

Test #25:

score: 0
Accepted
time: 1206ms
memory: 19428kb

input:

200000 200000
-209681962 451691484 863486040 885986082 888701465 962559431 981013429 982403304 991652037 999501945 999723427 999924077 999928121 999964867 999985728 999998099 999999676 999999802 999999830 999999830 999999841 999999983 999999995 1000000000 1000000000 1000000000 1000000000 1000000000 ...

output:

209681962
242009522
1105495562
1991481644
2880183109
3842742540
4823755969
5806159273
6797811310
7797313255
8797036682
9796960759
10796888880
11796853747
12796839475
13796837574
14796837250
15796837052
16796836882
17796836712
18796836553
19796836536
20796836531
21796836531
22796836531
23796836531
24...

result:

ok 200000 numbers

Test #26:

score: 0
Accepted
time: 1185ms
memory: 19400kb

input:

200000 200000
627252523 979366570 995764806 999831790 999935437 999969851 999979210 999989379 999991613 999995444 999999861 999999970 999999982 999999994 999999997 999999997 999999997 999999999 999999999 999999999 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 100000000...

output:

627252523
1606619093
2602383899
3602215689
4602151126
5602120977
6602100187
7602089566
8602081179
9602076623
10602076484
11602076454
12602076436
13602076430
14602076427
15602076424
16602076421
17602076420
18602076419
19602076418
20602076418
21602076418
22602076418
23602076418
24602076418
25602076418...

result:

ok 200000 numbers

Test #27:

score: 0
Accepted
time: 1225ms
memory: 19424kb

input:

200000 200000
826496201 908165650 983143103 989914407 999690455 999884701 999972967 999976620 999990881 999996713 999997865 999999657 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1...

output:

826496201
1734661851
2717804954
3707719361
4707409816
5707294517
6707267484
7707244104
8707234985
9707231698
10707229563
11707229220
12707229220
13707229220
14707229220
15707229220
16707229220
17707229220
18707229220
19707229220
20707229220
21707229220
22707229220
23707229220
24707229220
25707229220...

result:

ok 200000 numbers

Subtask #5:

score: 0
Wrong Answer

Test #28:

score: 0
Wrong Answer
time: 1150ms
memory: 19416kb

input:

200000 200000
3 -5 -3 3 3 -5 7 -2 2 -4 -4 9 0 -4 -2 2 -5 7 -2 3 -8 1 6 -7 9 -3 -2 4 -2 -2 3 -2 1 0 -3 6 0 -6 -2 6 -5 6 -4 3 2 -4 5 -2 -8 1 1 2 1 -3 3 5 -9 1 3 -2 0 1 -2 1 2 5 -1 -4 -1 -3 7 -7 7 1 -6 7 -1 -5 1 4 -7 6 -3 -4 -1 4 1 5 -7 -3 9 1 -6 2 -3 1 6 -1 -1 1 -1 -5 -3 9 -5 4 -1 3 -2 -4 -4 8 1 0 -9 ...

output:

5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
...

result:

wrong answer 1st numbers differ - expected: '9', found: '5'

Subtask #6:

score: 0
Skipped

Dependency #1:

0%

Subtask #7:

score: 0
Skipped

Dependency #6:

0%

Subtask #8:

score: 0
Skipped

Dependency #6:

0%

Subtask #9:

score: 0
Skipped

Dependency #1:

0%