QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#142249#4563. Radio TowersQwerty1232#0 43ms29548kbC++203.2kb2023-08-18 20:05:542024-07-04 02:39:54

Judging History

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

  • [2024-07-04 02:39:54]
  • 评测
  • 测评结果:0
  • 用时:43ms
  • 内存:29548kb
  • [2023-08-18 20:05:54]
  • 提交

answer

#include "towers.h"

#include <algorithm>
#include <cassert>
#include <functional>
#include <numeric>
#include <vector>

template <typename cmp_t>
struct ST {
    std::vector<std::vector<std::pair<int, int>>> data;

    ST() = default;
    ST(std::vector<int> vec) {
        int lg = std::__lg(vec.size()) + 1;
        data.resize(lg);
        data[0].resize(vec.size());
        for (int i = 0; i < vec.size(); i++) {
            data[0][i] = {vec[i], i};
        }
        for (int k = 1; k < lg; k++) {
            data[k].resize(vec.size() - (1 << k) + 1);
            for (int i = 0; i < data[k].size(); i++) {
                data[k][i] = std::min(data[k - 1][i], data[k - 1][i + (1 << k - 1)], cmp_t());
            }
        }
    }

    auto get_min(int l, int r) {
        int k = std::__lg(r - l);
        return std::min(data[k][l], data[k][r - (1 << k)], cmp_t());
    }
};

int n, q;
ST<std::less<>> st_min;
ST<std::greater<>> st_max;
std::vector<int> input;

std::vector<int> lvs;
std::vector<int> h_lca;
std::vector<int> shit;

void init(int n, std::vector<int> H) {
    q = 0;
    ::n = n;
    input = H;
    st_min = ST<std::less<>>(input);
    st_max = ST<std::greater<>>(input);

    h_lca.assign(n, -1);

    auto fuck = [&](auto fuck, int l, int r) -> std::pair<int, int> {
        if (l >= r) {
            return {int(1e9), -1};
        }
        if (l + 1 == r) {
            int rs = lvs.size();
            lvs.push_back(l);
            return {rs, rs};
        }
        int id = st_max.get_min(l, r).second;
        auto [p1, p2] = fuck(fuck, l, id);
        auto [p3, p4] = fuck(fuck, id + 1, r);
        if (p2 >= 0 && p3 < n) {
            h_lca[p2] = input[id];
        }
        return {std::min(p1, p3), std::max(p2, p4)};
    };
    fuck(fuck, 0, n);
    for (int i = 0; i < n - 1; i++) {
        if (h_lca[i] != -1) {
            shit.push_back(h_lca[i] - std::max(input[lvs[i]], input[lvs[i + 1]]));
        }
    }
    std::sort(shit.begin(), shit.end());
}

int max_towers(int ql, int qr, int d) {
    ::q++;
    qr++;

    {
        int it = shit.end() - std::lower_bound(shit.begin(), shit.end(), d);
        return it + 1;
    }

#ifndef LOCAL
    if (q <= 1) {
        auto fuck = [&](auto fuck, int l, int r, int max) -> int {
            if (l >= r) {
                return 0;
            }
            int res = st_min.get_min(l, r).first <= max ? 1 : 0;
            if (l + 1 < r) {
                int id = st_max.get_min(l, r).second;
                int res2 = 0;
                res2 += fuck(fuck, l, id, input[id] - d);
                res2 += fuck(fuck, id + 1, r, input[id] - d);
                res = std::max(res, res2);
            }
            return res;
        };
        int res = fuck(fuck, ql, qr, 1.1e9);
        return res;
    }
#endif

    int it1 = std::lower_bound(lvs.begin(), lvs.end(), ql) - lvs.begin();
    int it2 = std::lower_bound(lvs.begin(), lvs.end(), qr) - lvs.begin();

    int res = 1;
    for (int i = it1; i + 1 < it2; i++) {
        res += std::max(input[lvs[i]], input[lvs[i + 1]]) + d <= h_lca[i];
    }
    return res;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 35ms
memory: 22520kb

input:

59640
49885 57346 58504 87383 113182 129676 204090 205404 259925 276583 300332 324014 333675 359377 364049 408489 414852 428310 438038 440113 458193 554789 643468 666525 683112 690791 707313 720088 741028 748785 789826 796576 800966 832867 851750 861044 862283 900756 926925 939560 955678 965636 9740...

output:

2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
...

result:

wrong answer 3rd lines differ - expected: '1', found: '2'

Subtask #2:

score: 0
Wrong Answer

Test #8:

score: 0
Wrong Answer
time: 1ms
memory: 3860kb

input:

425
753881706 405729786 890889563 29736246 598281970 208352067 357783003 663497023 178397034 4832890 562140755 510307001 354540290 538848551 436879256 86659033 42928516 24145404 749159097 118423198 506851985 204895765 719719998 726244368 991372008 681703480 799303017 657138050 88278945 417801236 260...

output:

131

result:

wrong answer 3rd lines differ - expected: '13', found: '131'

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Wrong Answer

Test #65:

score: 0
Wrong Answer
time: 35ms
memory: 29548kb

input:

99308
491693640 24020487 317364185 726230755 737284540 951143270 709116045 641023337 360629062 964879440 47884022 532494780 803629825 635450854 688041998 573937055 113198481 191311841 929603572 636688 598629732 895342035 396521271 619919754 716589045 657789547 373121546 866402108 609316614 60046511 ...

output:

33010
33010
33010
33010
33010
33010
33010
33010
33010
33010
33010
33010
33010
33010
33010
33010
33010
33010
33010
33010
33010
33010
33010
33010
33010
33010
33010
33010
33010
33010
33010
33010
33010
33010
33010
33010
33010
33010
33010
33010
33010
33010
33010
33010
33010
33010
33010
33010
33010
33010
...

result:

wrong answer 3rd lines differ - expected: '11903', found: '33010'

Subtask #5:

score: 0
Wrong Answer

Test #86:

score: 0
Wrong Answer
time: 22ms
memory: 8984kb

input:

23881
605288257 422163932 155875880 339929874 76049859 196344969 958160745 767945284 469191956 997116006 387749577 15911341 920437918 367576975 800789357 351557615 283723284 369507452 841548133 643412903 309731505 256549694 370065644 699518122 559017597 347646657 469353381 575240521 501893001 454519...

output:

7097
6942
1
4214
4484
7258
421
6470
570
5464
3981
7432
3564
1259
4664
6183
7644
7144
7787
1247
5993
6935
7224
3806
15
586
5081
540
5864
4014
4118
4162
1673
49
5323
1515
7691
6838
520
5403
7102
3811
185
6302
1456
62
6369
6893
7146
5670
4416
6335
819
613
3174
5221
3319
749
6481
397
7743
54
897
5000
52...

result:

wrong answer 3rd lines differ - expected: '7197', found: '7097'

Subtask #6:

score: 0
Wrong Answer

Test #97:

score: 0
Wrong Answer
time: 43ms
memory: 26508kb

input:

88768
238644804 620122421 789364401 899010695 885388612 437964772 845379533 657562749 773925456 625793781 916240972 291506550 379611161 905077982 629848170 530056471 520438258 806293637 326792996 785404568 74285074 565304193 846963319 63529729 804909008 212070492 69936548 656129389 408708069 3070450...

output:

25448
25448
25448
25448
25448
25448
25448
25448
25448
25448
25448
25448
25448
25448
25448
25448
25448
25448
25448
25448
25448
25448
25448
25448
25448
25448
25448
25448
25448
25448
25448
25448
25448
25448
25448
25448
25448
25448
25448
25448
25448
25448
25448
25448
25448
25448
25448
25448
25448
25448
...

result:

wrong answer 3rd lines differ - expected: '7293', found: '25448'

Subtask #7:

score: 0
Skipped

Dependency #1:

0%