Submission #689739

# Submission time Handle Problem Language Result Execution time Memory
689739 2023-01-29T08:42:13 Z lohacho Radio Towers (IOI22_towers) C++17
56 / 100
1200 ms 16864 KB
#include "towers.h"

#include <bits/stdc++.h>
using namespace std;

int n;
vector<int> a;
vector<int> leaf, lt;
vector<vector<int>> spa;
vector<int> lp, rp;
vector<int> mnl, mnr;

struct fenw{
    int n;
    vector<int> tr;

    fenw(int m){
        n = m + 4;
        tr.resize(n, -1);
    }

    void push(int pos, int val){
        for(int i = pos; i < n; i += (i & -i)){
            tr[i] = max(tr[i], val);
        }
    }

    int get(int pos){
        int rv = -1;

        for(int i = pos; i > 0; i -= (i & -i)){
            rv = max(rv, tr[i]);
        }

        return rv;
    }
};

int fir = 0;

void init(int N, std::vector<int> H) {
    n = N;
    a = H;

    spa.resize(n, vector<int>(20, (int)1e9));
    lp.resize(n);
    rp.resize(n);
    mnr.resize(n, (int)1e9);
    mnl.resize(n, (int)1e9);
}

int max_towers(int L, int R, int D) {
    if(!fir){
        fir = 1;
        vector<int> srt;
        for(int i = 0; i < n; ++i){
            srt.push_back(a[i]);
            srt.push_back(a[i] + D);
        }

        sort(srt.begin(), srt.end());
        srt.erase(unique(srt.begin(), srt.end()), srt.end());

        auto getnum = [&](int x)->int{
            return lower_bound(srt.begin(), srt.end(), x) - srt.begin();
        };

        auto getl = [&](vector<int> x)->vector<int>{
            fenw tr((int)srt.size() + 4);
            vector<int> rv(n);

            for(int i = 0; i < n; ++i){
                rv[i] = tr.get((int)srt.size() - getnum(a[i] + D)) + 1;
                rv[i] = i - rv[i];
                tr.push((int)srt.size() - getnum(a[i]), i);
            }

            return rv;
        };

        lp = getl(a);
        reverse(a.begin(), a.end());
        rp = getl(a);
        reverse(a.begin(), a.end());
        reverse(rp.begin(), rp.end());

        // for(int i = 0; i < n; ++i){
        //     cout << i - lp[i] << ' ' << i + rp[i] << endl;
        // }
        // cout << endl;

        for(int i = n - 1; i >= 0; --i){
            assert(i - lp[i] >= 0);
            spa[i - lp[i]][0] = min(spa[i - lp[i]][0], i + rp[i]);
            for(int j = 1; j < 20; ++j){
                if(spa[i][j - 1] < n - 1){
                    spa[i][j] = spa[spa[i][j - 1] + 1][j - 1];
                }
            }
            if(i + 1 < n){
                for(int j = 0; j < 20; ++j){
                    spa[i][j] = min(spa[i][j], spa[i + 1][j]);
                }
            }

            mnl[i - lp[i]] = min(mnl[i - lp[i]], i);
            mnr[i] = i + rp[i];
        }

        for(int i = n - 2; i >= 0; --i){
            mnl[i] = min(mnl[i], mnl[i + 1]);
            mnr[i] = min(mnr[i], mnr[i + 1]);
        }
    }

    int ans = 1;
    int pos = mnr[L] + 1;
    for(int i = 19; i >= 0; --i){
        if(pos < n && spa[pos][i] < R){
            ans += (1 << i);
            pos = spa[pos][i] + 1;
        }
    }
    if(pos < n && mnl[pos] <= R){
        ++ans;
    }

    return ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 385 ms 10072 KB 31st lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 2 ms 592 KB Output is correct
3 Correct 2 ms 592 KB Output is correct
4 Correct 2 ms 592 KB Output is correct
5 Correct 2 ms 632 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 2 ms 592 KB Output is correct
8 Correct 2 ms 624 KB Output is correct
9 Correct 1 ms 592 KB Output is correct
10 Correct 1 ms 592 KB Output is correct
11 Correct 2 ms 592 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 2 ms 592 KB Output is correct
14 Correct 1 ms 592 KB Output is correct
15 Correct 2 ms 592 KB Output is correct
16 Correct 2 ms 592 KB Output is correct
17 Correct 2 ms 592 KB Output is correct
18 Correct 2 ms 592 KB Output is correct
19 Correct 2 ms 592 KB Output is correct
20 Correct 2 ms 592 KB Output is correct
21 Correct 2 ms 592 KB Output is correct
22 Correct 2 ms 592 KB Output is correct
23 Correct 1 ms 592 KB Output is correct
24 Correct 1 ms 592 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 2 ms 592 KB Output is correct
27 Correct 3 ms 592 KB Output is correct
28 Correct 2 ms 592 KB Output is correct
29 Correct 2 ms 592 KB Output is correct
30 Correct 2 ms 592 KB Output is correct
31 Correct 2 ms 592 KB Output is correct
32 Correct 2 ms 592 KB Output is correct
33 Correct 2 ms 592 KB Output is correct
34 Correct 1 ms 592 KB Output is correct
35 Correct 2 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 2 ms 592 KB Output is correct
3 Correct 2 ms 592 KB Output is correct
4 Correct 2 ms 592 KB Output is correct
5 Correct 2 ms 632 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 2 ms 592 KB Output is correct
8 Correct 2 ms 624 KB Output is correct
9 Correct 1 ms 592 KB Output is correct
10 Correct 1 ms 592 KB Output is correct
11 Correct 2 ms 592 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 2 ms 592 KB Output is correct
14 Correct 1 ms 592 KB Output is correct
15 Correct 2 ms 592 KB Output is correct
16 Correct 2 ms 592 KB Output is correct
17 Correct 2 ms 592 KB Output is correct
18 Correct 2 ms 592 KB Output is correct
19 Correct 2 ms 592 KB Output is correct
20 Correct 2 ms 592 KB Output is correct
21 Correct 2 ms 592 KB Output is correct
22 Correct 2 ms 592 KB Output is correct
23 Correct 1 ms 592 KB Output is correct
24 Correct 1 ms 592 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 2 ms 592 KB Output is correct
27 Correct 3 ms 592 KB Output is correct
28 Correct 2 ms 592 KB Output is correct
29 Correct 2 ms 592 KB Output is correct
30 Correct 2 ms 592 KB Output is correct
31 Correct 2 ms 592 KB Output is correct
32 Correct 2 ms 592 KB Output is correct
33 Correct 2 ms 592 KB Output is correct
34 Correct 1 ms 592 KB Output is correct
35 Correct 2 ms 592 KB Output is correct
36 Correct 75 ms 10892 KB Output is correct
37 Correct 108 ms 16740 KB Output is correct
38 Correct 114 ms 16656 KB Output is correct
39 Correct 104 ms 16748 KB Output is correct
40 Correct 107 ms 16724 KB Output is correct
41 Correct 109 ms 16804 KB Output is correct
42 Correct 112 ms 16660 KB Output is correct
43 Correct 60 ms 16680 KB Output is correct
44 Correct 62 ms 16748 KB Output is correct
45 Correct 69 ms 16748 KB Output is correct
46 Correct 66 ms 16752 KB Output is correct
47 Correct 101 ms 16724 KB Output is correct
48 Correct 104 ms 16748 KB Output is correct
49 Correct 103 ms 16712 KB Output is correct
50 Correct 60 ms 16744 KB Output is correct
51 Correct 57 ms 16708 KB Output is correct
52 Correct 102 ms 16728 KB Output is correct
53 Correct 100 ms 16700 KB Output is correct
54 Correct 107 ms 16740 KB Output is correct
55 Correct 58 ms 16700 KB Output is correct
56 Correct 60 ms 16672 KB Output is correct
57 Correct 99 ms 16140 KB Output is correct
58 Correct 109 ms 16712 KB Output is correct
59 Correct 110 ms 16724 KB Output is correct
60 Correct 114 ms 16864 KB Output is correct
61 Correct 105 ms 16672 KB Output is correct
62 Correct 106 ms 16728 KB Output is correct
63 Correct 105 ms 16676 KB Output is correct
64 Correct 67 ms 16676 KB Output is correct
65 Correct 58 ms 16728 KB Output is correct
66 Correct 61 ms 16708 KB Output is correct
67 Correct 62 ms 16712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 644 ms 16608 KB Output is correct
2 Correct 1102 ms 16712 KB Output is correct
3 Correct 1180 ms 16744 KB Output is correct
4 Correct 1050 ms 16804 KB Output is correct
5 Correct 1022 ms 16780 KB Output is correct
6 Correct 969 ms 16748 KB Output is correct
7 Correct 1027 ms 16712 KB Output is correct
8 Correct 992 ms 16748 KB Output is correct
9 Correct 905 ms 16736 KB Output is correct
10 Correct 1040 ms 16656 KB Output is correct
11 Correct 996 ms 16660 KB Output is correct
12 Correct 915 ms 16704 KB Output is correct
13 Correct 868 ms 16656 KB Output is correct
14 Correct 0 ms 208 KB Output is correct
15 Correct 2 ms 592 KB Output is correct
16 Correct 2 ms 548 KB Output is correct
17 Correct 118 ms 16820 KB Output is correct
18 Correct 102 ms 16700 KB Output is correct
19 Correct 101 ms 16748 KB Output is correct
20 Correct 58 ms 16748 KB Output is correct
21 Correct 63 ms 16748 KB Output is correct
22 Correct 102 ms 16652 KB Output is correct
23 Correct 100 ms 16716 KB Output is correct
24 Correct 110 ms 16668 KB Output is correct
25 Correct 67 ms 16652 KB Output is correct
26 Correct 66 ms 16700 KB Output is correct
27 Correct 2 ms 592 KB Output is correct
28 Correct 2 ms 592 KB Output is correct
29 Correct 2 ms 592 KB Output is correct
30 Correct 2 ms 592 KB Output is correct
31 Correct 2 ms 624 KB Output is correct
32 Correct 2 ms 592 KB Output is correct
33 Correct 2 ms 592 KB Output is correct
34 Correct 2 ms 592 KB Output is correct
35 Correct 2 ms 592 KB Output is correct
36 Correct 2 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 311 ms 4280 KB 2nd lines differ - on the 1st token, expected: '7063', found: '7197'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 2 ms 592 KB Output is correct
3 Correct 2 ms 592 KB Output is correct
4 Correct 2 ms 592 KB Output is correct
5 Correct 2 ms 632 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 2 ms 592 KB Output is correct
8 Correct 2 ms 624 KB Output is correct
9 Correct 1 ms 592 KB Output is correct
10 Correct 1 ms 592 KB Output is correct
11 Correct 2 ms 592 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 2 ms 592 KB Output is correct
14 Correct 1 ms 592 KB Output is correct
15 Correct 2 ms 592 KB Output is correct
16 Correct 2 ms 592 KB Output is correct
17 Correct 2 ms 592 KB Output is correct
18 Correct 2 ms 592 KB Output is correct
19 Correct 2 ms 592 KB Output is correct
20 Correct 2 ms 592 KB Output is correct
21 Correct 2 ms 592 KB Output is correct
22 Correct 2 ms 592 KB Output is correct
23 Correct 1 ms 592 KB Output is correct
24 Correct 1 ms 592 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 2 ms 592 KB Output is correct
27 Correct 3 ms 592 KB Output is correct
28 Correct 2 ms 592 KB Output is correct
29 Correct 2 ms 592 KB Output is correct
30 Correct 2 ms 592 KB Output is correct
31 Correct 2 ms 592 KB Output is correct
32 Correct 2 ms 592 KB Output is correct
33 Correct 2 ms 592 KB Output is correct
34 Correct 1 ms 592 KB Output is correct
35 Correct 2 ms 592 KB Output is correct
36 Correct 75 ms 10892 KB Output is correct
37 Correct 108 ms 16740 KB Output is correct
38 Correct 114 ms 16656 KB Output is correct
39 Correct 104 ms 16748 KB Output is correct
40 Correct 107 ms 16724 KB Output is correct
41 Correct 109 ms 16804 KB Output is correct
42 Correct 112 ms 16660 KB Output is correct
43 Correct 60 ms 16680 KB Output is correct
44 Correct 62 ms 16748 KB Output is correct
45 Correct 69 ms 16748 KB Output is correct
46 Correct 66 ms 16752 KB Output is correct
47 Correct 101 ms 16724 KB Output is correct
48 Correct 104 ms 16748 KB Output is correct
49 Correct 103 ms 16712 KB Output is correct
50 Correct 60 ms 16744 KB Output is correct
51 Correct 57 ms 16708 KB Output is correct
52 Correct 102 ms 16728 KB Output is correct
53 Correct 100 ms 16700 KB Output is correct
54 Correct 107 ms 16740 KB Output is correct
55 Correct 58 ms 16700 KB Output is correct
56 Correct 60 ms 16672 KB Output is correct
57 Correct 99 ms 16140 KB Output is correct
58 Correct 109 ms 16712 KB Output is correct
59 Correct 110 ms 16724 KB Output is correct
60 Correct 114 ms 16864 KB Output is correct
61 Correct 105 ms 16672 KB Output is correct
62 Correct 106 ms 16728 KB Output is correct
63 Correct 105 ms 16676 KB Output is correct
64 Correct 67 ms 16676 KB Output is correct
65 Correct 58 ms 16728 KB Output is correct
66 Correct 61 ms 16708 KB Output is correct
67 Correct 62 ms 16712 KB Output is correct
68 Correct 644 ms 16608 KB Output is correct
69 Correct 1102 ms 16712 KB Output is correct
70 Correct 1180 ms 16744 KB Output is correct
71 Correct 1050 ms 16804 KB Output is correct
72 Correct 1022 ms 16780 KB Output is correct
73 Correct 969 ms 16748 KB Output is correct
74 Correct 1027 ms 16712 KB Output is correct
75 Correct 992 ms 16748 KB Output is correct
76 Correct 905 ms 16736 KB Output is correct
77 Correct 1040 ms 16656 KB Output is correct
78 Correct 996 ms 16660 KB Output is correct
79 Correct 915 ms 16704 KB Output is correct
80 Correct 868 ms 16656 KB Output is correct
81 Correct 0 ms 208 KB Output is correct
82 Correct 2 ms 592 KB Output is correct
83 Correct 2 ms 548 KB Output is correct
84 Correct 118 ms 16820 KB Output is correct
85 Correct 102 ms 16700 KB Output is correct
86 Correct 101 ms 16748 KB Output is correct
87 Correct 58 ms 16748 KB Output is correct
88 Correct 63 ms 16748 KB Output is correct
89 Correct 102 ms 16652 KB Output is correct
90 Correct 100 ms 16716 KB Output is correct
91 Correct 110 ms 16668 KB Output is correct
92 Correct 67 ms 16652 KB Output is correct
93 Correct 66 ms 16700 KB Output is correct
94 Correct 2 ms 592 KB Output is correct
95 Correct 2 ms 592 KB Output is correct
96 Correct 2 ms 592 KB Output is correct
97 Correct 2 ms 592 KB Output is correct
98 Correct 2 ms 624 KB Output is correct
99 Correct 2 ms 592 KB Output is correct
100 Correct 2 ms 592 KB Output is correct
101 Correct 2 ms 592 KB Output is correct
102 Correct 2 ms 592 KB Output is correct
103 Correct 2 ms 592 KB Output is correct
104 Correct 812 ms 14896 KB Output is correct
105 Correct 1114 ms 16716 KB Output is correct
106 Correct 1116 ms 16700 KB Output is correct
107 Correct 1042 ms 16664 KB Output is correct
108 Correct 1053 ms 16744 KB Output is correct
109 Correct 1175 ms 16700 KB Output is correct
110 Correct 1200 ms 16656 KB Output is correct
111 Correct 962 ms 16640 KB Output is correct
112 Correct 815 ms 16664 KB Output is correct
113 Correct 738 ms 16656 KB Output is correct
114 Correct 869 ms 16652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 385 ms 10072 KB 31st lines differ - on the 1st token, expected: '1', found: '2'
2 Halted 0 ms 0 KB -